I have an extern double StopLossPips and I would like to make it conditional with an IF statement. Basically I don't want the stop loss to kick in unless some condition exists in the market. In this case price above/below a 5MA. (_Is5MAStopUp) I have tried to implement it within the code where the StopLossPips is referenced and I have put it before the subopenorder and 1-2 other places but not luck. I cant understand why the IF statement will not take. Any help appreciated.
Inserted Code
if ( (OpenOnSignalChange && lastDirection != OP_BUY && curDirection == OP_BUY) || (!OpenOnSignalChange && curDirection == OP_BUY && TradeCount[OP_BUY] == 0 && lastDirection == -1) ) { closeTrades(OP_SELL); if(_Is5MAStopUp) { if (StopLossPips > 0)StopLoss = Ask - StopLossPips * MyPoint; else StopLoss = getZigZagStopLoss(OP_BUY); Lots = getLotSize3( (Ask-StopLoss)/MyPoint ); subOpenOrder(OP_BUY,StopLossPips,TakeProfitPips,Lots); lastDirState = 1; }} else if ( (OpenOnSignalChange && lastDirection != OP_SELL && curDirection == OP_SELL) || (!OpenOnSignalChange && curDirection == OP_SELL && TradeCount[OP_SELL] == 0 && lastDirection == -1) ) { closeTrades(OP_BUY); if(_Is5MAStopDown){ if (StopLossPips > 0)StopLoss = Bid + StopLossPips * MyPoint; else StopLoss = getZigZagStopLoss(OP_SELL); Lots = getLotSize3( (StopLoss-Bid)/MyPoint ); //to otwiera pierwsze zlecenia subOpenOrder(OP_SELL, StopLossPips,TakeProfitPips,Lots); //Comment("SUB "+TimeToStr(TimeCurrent())); //Print("SUB "+TimeToStr(TimeCurrent())); lastDirState = 1; } } else { if(lastDirState==1) lastDirState = -1; }