Help with Entry Criteria

 

Hi all,
I have come up with a way by using "Bars" function. When a trade is triggered, I will set a integer count with the bars function (e.g. a buy trade is triggered in bar 122, hence the count will be 122) and when my criteria has being triggered again, I will call the bar function again and compared it with the count and the trade will only trigger if the new count is higher then the previous which is 122 in this case.

However, I am still triggering 2 trades together instead of 1 per criteria. Why is this so?

Please help

Thanks and regards
Terrance


int BarCounter, BarCounter2;
total = OrdersTotal();
if(total < 1)
{
if(isCrossed == 1 && shortEma > mainshortEma && longEma > mainshortEma)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("BUY order opened : ",OrderOpenPrice());

BarCounter = Bars;
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2 && shortEma < mainshortEma && longEma < mainshortEma)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+S topLoss*Point,Bid-TakeProfit*Point,
"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("SELL order opened : ",OrderOpenPrice());

BarCounter = Bars;
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}



if(total == 1)
{
BarCounter2 = Bars;

if(isCrossed == 1 && shortEma > mainshortEma && longEma > mainshortEma && BarCounter2 > BarCounter)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,1,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("BUY order opened : ",OrderOpenPrice());

BarCounter = BarCounter2;
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(isCrossed == 2 && shortEma < mainshortEma && longEma < mainshortEma && BarCounter2 > BarCounter)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,1,Bid+S topLoss*Point,Bid-TakeProfit*Point,
"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
Print("SELL order opened : ",OrderOpenPrice());

BarCounter = BarCounter2;
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}

return(0);
}

 
tkuan77:

Hi all,

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 
Bars is unreliable, you should use Time instead . . .
 
  1. SRC
  2. Time
  3. Unless your variable is a global or static, the value is lost when you return from start()
  4. On your first if(isCrossed == 1 && shortEma... you don't check barCount, so it opens a second order the next tick.
  5. if(total<0) means the EA is incompatible with every other, including itself and manual trading
Reason: