Download MetaTrader 5

Trailing Stop Error: Invalid Stops

To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
polymath
182
polymath 2012.08.27 16:29 

Hi guys, I've been having this error the entire day while trying to figure out a way to place trailing stops to my positions.  I'm getting an "invalid stops" error.  I've read through some of the previous posts about the invalid stops but nothing seems to work. Appreciate if anyone can kindly look at my code below and try to decipher where the problem is coming from:

if(Buy_opened==true)
    {
      if(SymbolInfoDouble(_Symbol,SYMBOL_ASK)-TtrailingStop*_Point >= myposition.StopLoss())
      { double newSLpoint=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK)+TrailingStop*_Point,_Digits);
        double newTPpoint=NormalizeDouble(myposition.TakeProfit(),_Digits);
        if(mytrade.PositionModify(_Symbol,newSLpoint,newTPpoint))  
        {
          //--- Request successfully completed    
         Alert("An opened position has been successfully modified!!");
         return;
        }
      else
        {
         Alert("The position modify request could not be completed - error: ",mytrade.ResultRetcodeDescription());
         return;
        }
      }
    }
    if(Sell_opened==true)
    {
      if(SymbolInfoDouble(_Symbol,SYMBOL_BID)+TrailingStop*_Point <= myposition.StopLoss())
      { double newSLpoint=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK)-TrailingStop*_Point,_Digits);
        double newTPpoint=NormalizeDouble(myposition.TakeProfit(),_Digits);
        
        if(mytrade.PositionModify(_Symbol,newSLpoint,newTPpoint))  
        {
          //--- Request successfully completed    
         Alert("An opened position has been successfully modified!!");
         return;
        }
      else
        {
         Alert("The position modify request could not be completed - error: ",mytrade.ResultRetcodeDescription());
         return;
        }
      }
    }
polymath
182
polymath 2012.08.27 16:34  

Here's a screenshot of the journal:

Invalid Stops Error

the stoploss and takeprofit modification seems to be correct... 

 

polymath
182
polymath 2012.08.28 06:31  
Hi guys, any suggestions?  
Suresh Kaulagi
147
Suresh Kaulagi 2012.08.28 08:55  
polymath:
Hi guys, any suggestions?  
Just change + to - in Buy and - to + in Sell order and verify.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Orders in DOM - Documentation on MQL5
polymath
182
polymath 2012.08.28 14:04  
Hi askrsk, thanks for pointing out that very clumsy mistake of mine, hehe...Thanks a lot!
To add comments, please log in or register