# Problem on equation as additional condition

71

Hi all,

I'm having problem on the equation which will be one of the condition to my code. As you can see on my code below. I was trying to used counter "n" as a condition to my code. "n" can be n=n+3, n=n+2 and n=n-1 depend on the condition as below. But this equation seem not work at all. Please help me to solve this problem. Thanks.

{
//------------------ Check OrderType in History
for(int i=0; i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
OProfit = OrderProfit();
OType   = OrderType();
OLot    = OrderLots();
}
//------------------ Hedge Lot Calculation
Hedge_Lot = NormalizeDouble((OLot*3),2);
//------------------ Order is closed
if(OrdersTotal()==0)
{
if(OProfit==0)
{
n=0;
Lot = Lot_Size;
Selling();
return(n);
}
//------------------ Hedge condition
if(OType==OP_SELL && OProfit>0)
{
if(n==0)
{
Lot=Lot_Size;
}
else
{
n=n-1; //does not work
Lot = Lot_Size;
}
return(n);
}
{
if(n==0)
{
Lot=Lot_Size;
Selling();
}
else
{
n=n-1;  //does not work
Lot = Lot_Size;
Selling();
}
return(n);
}
if(OType==OP_SELL && OProfit<0)
{
if (OLot>1.3)
{
if(n==0)
{
n=n+3; //does not work
}
else
{
n=n+2; //does not work
}
Lot=OLot;
}
else
{
Lot = Hedge_Lot;
}
return(n);
}
{
if (OLot>1.3)
{
if(n==0)
{
n=n+3; //does not work
}
else
{
n=n+2; //does not work
}
Lot=OLot;
}
else
{
Lot = Hedge_Lot;
Selling();
}
return(n);
}
}
return(n);
}
Moderator
7958

1) Where is n declared? What is the initial value of n - have you checked it with the debugger?

2) Why e.g. n=n+2; doe not work? Have you checked it with the debugger - I bet you if n == 5 after that n==7!

3) Instead of n=n+1 you can use either n++; or  n+=1;
17097

1. Why did you post here and not in the MQ4 section?
2. for(int i=0; i<OrdersHistoryTotal();i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
OProfit = OrderProfit();
OType   = OrderType();
OLot    = OrderLots();
}
What happens when OrderSelect loop doesn't find any order?
3. What happens when OrderSelect loop finds a deleted order?
4. You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
5. Profit is profit + commission + swap
6. if(OrdersTotal()==0)
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.) Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
7. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
8. Print out your variables, and find out why.
934

zaharulrizal:

Hi all,

I'm having problem on the equation which will be one of the condition to my code. As you can see on my code below. I was trying to used counter "n" as a condition to my code. "n" can be n=n+3, n=n+2 and n=n-1 depend on the condition as below. But this equation seem not work at all. Please help me to solve this problem. Thanks.