Invalid Stops Error

 
    if (mPosition.Profit() > 0)
            {
               double ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits);
               double bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits);            
               double oldSl = mPosition.StopLoss();
               double newSl = 0.0;
               if (mPosition.Type() == POSITION_TYPE_BUY) {
                  newSl = NormalizeDouble(bid - TrailingStopPoints*_Point,_Digits);
                  if (newSl > oldSl + 10*_Point && newSl < bid) {
		     Print (mPosition.Ticket(), " ", "BUY POS. ", bid, " ", newSl, " ", mPosition.PriceOpen(), " ", SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL), " ", NormalizeDouble((ask - bid)/_Point,0));
                     mTrade.PositionModify(mPosition.Ticket(), newSl, mPosition.TakeProfit());
                  }
               }   
               else if (mPosition.Type() == POSITION_TYPE_SELL) {
                  newSl = NormalizeDouble(ask + TrailingStopPoints*_Point,_Digits);
                  if (newSl + 10*_Point < oldSl && newSl > ask) {
		     Print (mPosition.Ticket(), " ", "SELL POS. ", ask, " ", newSl, " ", mPosition.PriceOpen(), " ", SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL), " ", NormalizeDouble((ask - bid)/_Point,0));
                     mTrade.PositionModify(mPosition.Ticket(), newSl, mPosition.TakeProfit());
                  }
               }                  
            }


I am using this code. My TrailingStopPoints = 100. Why do I get INVALID STOPS?



Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
 

I use this

new_sl=NormalizeDouble(floor(new_sl/_Point)*_Point, _Digits);
Reason: