code not working properly

#1
please help me. In the following code, i want sell to take place only
when stop loss is cut or the target is met. But the position is exited
on the very next candle bar. What am i doing wrong?

_SECTION_BEGIN("SHITIZ");
COND2 = High > Max(Max(Ref(High,-1),Ref(High,-2)),Max(Ref(High,-3),Ref(High,-4)));
Buy = COND2;


BuyPrice = Close;

ApplyStop(stopTypeProfit,stopModePercent,4.9,0,False,0);
ApplyStop(stopTypeLoss,stopModePercent,1.2,0,False,0);
Sell = stopTypeProfit || stopTypeLoss;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
PlotShapes(IIf(Buy,shapeSquare,shapeNone),colorWhite);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorYellow,0,Graph0,-50);

_SECTION_END();
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?