Closing order Logic???

 

Hello


I have been using psar to trigger buys and sells, but Im having problems with the EA closing the order a second later, Im just wondering if anyone has any idea whats wrong with my coding below


double PSAR_5M=iSAR(Symbol(),PERIOD_M5,0.03,0.02,1);

double MA_5M=iMA(Symbol(),PERIOD_M5,1,0,MODE_SMA,PRICE_CLOSE,1);


if (PSAR_5M > MA_5M)

{

OrderSend(Symbol(),OP_BUY,lots,Bid,30,30,30,"multi",923929332,Red);

}


This opens orders just fine, then i use the following for closing the order


double PSAR=iSAR(Symbol(),PERIOD_M5,0.03,0.02,1);

double MA=iMA(Symbol(),PERIOD_M5,1,0,MODE_SMA,PRICE_CLOSE,1);


if (PSAR < MA)

{

OrderClose(OrderTicket(), lots, pBid, 2 );

}


The problem is that it opens a position, then closes, then opens again and closes again constantly . I made the shift 1 to prevent repainting but that doesnt help at all.



thanks

 
Try this:

if (PSAR_5M > MA_5M)

{

OrderSend(Symbol(),OP_BUY,lots,Bid,30,30,30,"multi",923929332,Red);

Print(" PSAR _5M- ",DoubleToStr(PSAR_5M,6)," MA_5M - ",DoubleToStr(MA_5M,6));

}

and

if (PSAR < MA)

{

OrderClose(OrderTicket(), lots, pBid, 2 );

Print(" PSAR - ",DoubleToStr(PSAR,6)," MA- ",DoubleToStr(MA,6));

}

and then compare.