[B][U]hi Traders,
[/U]im learning expert programming these days and made small experts depends on the common indicators in MT4.[/B]
I made an EA to open 1 buy order when Parabolic SAR is under the current price and the opposite for sell.
and closes buy orders when SAR goes over the price and the opposite for sell.
it worked fine in the first order in the back-test and closed the order fine too, then the EA began to open (many many many …) buy orders in the very same bar (not 1 as I coded it)
(as shown in the attached photo)
N.B: I zoomed the bars as possible. Hope that helps
can anyone help me solve this code problem?
im attached a photo and the code for more details
thnx in advance for helping
//-----------------------------------------------------------------
void OnTick()
{
//---
double SAR=iSAR(Symbol(),0,0.02,0.2,1); // ----------- opening orders
if (SAR<Ask && OrdersTotal()==0)
OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"",0,0);
else if (SAR>Bid && OrdersTotal()==0)
OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"",0,0);
for(int i=0;i<OrdersTotal();i++) //------------------ closing orders
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{Comment("Order Selected");
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && SAR>Bid)
OrderClose(OrderTicket(),0.1,Bid,3);
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && SAR<Ask)
OrderClose(OrderTicket(),0.1,Ask,3);
}
}
}
//-----------------------------------------------------------------