# Formula Problem

71

Hi Guys,

Need help on my EA code, currently I'm trying to define the condition using counter formula, so each time the counter increase or decrease would be my extra condition to perform. But somehow this counter not work.

//+-------------------------------------------------------------------------------------------+
//| Start Trade and Check Order Conditions                                                    |
//+-------------------------------------------------------------------------------------------+
{

//------------------ Check OrderType in History
for(int i=0; i<OrdersHistoryTotal();i++)
{
OTicket = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

OProfit = OrderProfit();
OType   = OrderType();
OLot    = OrderLots();

if(n<1)
{
n=0;
}
counter=n;
n=counter+m;
}
//------------------ Hedge Lot Calculation
Hedge_Lot = NormalizeDouble((OLot*2),2)+Lot_Size;
//------------------ Order is closed
if(OrdersTotal()==0)
{
if(OProfit==0)
{
Lot = Lot_Size;
Selling();
return;
}
//------------------ Hedge condition
if(OType==OP_SELL && OProfit>0)
{
if(n==0)
{
Lot=Lot_Size;
}
else
{
m=-1;
Lot = Lot_Size;
return;
}
}
{
if(n==0)
{
Lot=Lot_Size;
Selling();
}
else
{
m=-1;
Lot = Lot_Size;
Selling();
return;
}
}
if(OType==OP_SELL && OProfit<0)
{
if(OLot>1.3)
{
if(n==0)
{
m=2;
}
else
{
m=1;
}
OLot=OLot;
return;
}
else
{
Lot = Hedge_Lot;
return;
}
}
{
if(OLot>1.3)
{
if(n==0)
{
m=2;
}
else
{
m=1;

}
OLot=OLot;
Selling();
return;
}
else
{
Lot = Hedge_Lot;
Selling();
return;
}
}
}
}
Moderator
5667

I'm sorry but what is m ?

if(n<1)  // n = 0 so it's smaller then 1
{
n=0;  // n = forever 0
}
counter=n; // now counter is also 0
n=counter+m; // n = 0 + m
}
71

Marco vd Heijden:

I'm sorry but what is m ?

if(n<1)  // n = 0 so it's smaller then 1
{
n=0;  // n = forever 0
}
counter=n; // now counter is also 0
n=counter+m; // n = 0 + m
}
It on the hedge condition as per my code, different condition, different value of m.

but then, its not work at all..
16102

1. No idea what that code is trying to do. Zero a variable before the loop and increment the variable in the loop. Move the rest outside the loop.
2.    for(int i=0; i<OrdersHistoryTotal();i++){
OTicket = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
Perhaps you should read the manual. OrderSelect does not return a ticket number.
3. There are other things in history besides closed buys and sells.
4. 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
71

whroeder1:
1. No idea what that code is trying to do. Zero a variable before the loop and increment the variable in the loop. Move the rest outside the loop.
2.    for(int i=0; i<OrdersHistoryTotal();i++){
OTicket = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
Perhaps you should read the manual. OrderSelect does not return a ticket number.
3. There are other things in history besides closed buys and sells.
4. 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

1. I want to used counter "n" to represent extra condition for my hedge, different value of n would be different condition as per code. The equation should be like n=n+m and n=n-m, m would be different value on the condition which take next order to next condition. However, it seem not count at all, i try to put everywhere but still not count at all. Can you help me on this?

2. Thanks for remind me on the OrderSelect(), almost forgot to put the condition that you mention. Thanks.