Ordermodify error 130 - page 2

 

Hi

I thought you were calculating trailing stop on every tick each time the code goes through everything and so it should always have a value. Your variable types need sorting out you need to make sure they are correct although MQ4 doesn't seem too good at identifying wrong assignments types. If they ever tighten up on it you will be in big trouble.


timeold should be type datatime.

Traiinglstop is int but should be double etc etc.

This variable is global and should hold its value between calls.


Just noticed you only calculate trailing stop on a condition so how does the modify order know whether it has a sell or buy trailing stop?

 
jjc:

Hard to be certain, because you say you haven't posted the whole of the code [...]

Now that I've seen the whole of the code, I've changed my mind. It turns out that you are declaring Trailingstop outside of start(). However, that means that Trailingstop is defined in two places: as a double within start() and also as an int with global scope. The first declaration takes precedence, meaning that Trailingstop is an int. And that's where the problem almost certainly comes from. Your code does the following:


double Trailingstop = price - stoploss;                              // CALCULATION OF TRAILING STOP


Price - stoploss is going to be something like 1.3200 - 1.3100 = 0.0100. This is going to be getting stored in an int, and therefore it's going to be rounded down to zero. Hence the subsequent calculation of the trailing stop as Ask + 0 * Point etc.


The easiest fix should either be to change the declaration at global scope from int to double, or to remove it at global scope and change the declaration within start() from double to static double. And, in case it's not clear, if you're defining variables at global scope you don't then need to redefine them within individual functions - in fact you shouldn't do this. The MQL compiler really ought to warn you about it, particularly if you then redefine the variable's type.

 
Thank you all for your help. ... I have finally solved it. I ve put Trailingstop as static double and deleted it from the beginning as an integer (I hadnt even noticed it was there before :) )....
 
Juraj:
Thank you all for your help. ... I have finally solved it. I ve put Trailingstop as static double and deleted it from the beginning as an integer (I hadnt even noticed it was there before :) )....

can you help me, as i am getting same error "Ordermodify error 130", my code of trailling is as below.


extern int TrailingStop = 30;
extern int TrailingStep = 12;
extern int BreakEven    = 3;
extern int movestopto   = 10;
if (TrailingStop>0)MoveTrailingStop();
  if (BreakEven>0)MoveBreakEven(); 
//+------------------------------------------------------------------+
//| trailing functions                                               |
//+------------------------------------------------------------------+
void MoveTrailingStop() {
   
   for(int cnt=0;cnt<OrdersTotal();cnt++)  {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&& OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)    {
         if(OrderType()==OP_BUY)  {
            if(TrailingStop>0&&NormalizeDouble(Ask-TrailingStep*point,Digits)>NormalizeDouble(OrderOpenPrice()+TrailingStop*point,Digits))  {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailingStop*point,Digits))||(OrderStopLoss()==0))   {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailingStop*point,Digits),OrderTakeProfit(),0,Blue);
                  if (GetLastError()==0) Print(Symbol()+ ": Trailing Buy OrderModify ok " );   

               }
            }
         }
         else {
            if(TrailingStop>0&&NormalizeDouble(Bid+TrailingStep*point,Digits)<NormalizeDouble(OrderOpenPrice()-TrailingStop*point,Digits))  {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+TrailingStop*point,Digits)))||(OrderStopLoss()==0))  {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*point,Digits),OrderTakeProfit(),0,Red);
                  if (GetLastError()==0) Print(Symbol()+ ": Trailing Sell OrderModify ok " );   

               }
            }
         }
      }
   }
}
 

check the spread, instead of using current use a specific one since some brokers raise the spread at around 00:00

I know, the issue was so annoying

Reason: