Download MetaTrader 5

Modify error 130 in small TimeFrame

To add comments, please log in or register
cape1354
188
cape1354  
Trading is good in Eur/Usd

But "ordermodify error 130" will appear when I trade aud/cad eur/cad... in M1,M5, M15, M30

It works well in H1, H4, etc.

What's the problem?



//+------------------------------------------------------------------+
//|  TP/ST                                                |
//+------------------------------------------------------------------+
          
for(cnt=0;cnt<OrdersTotal();cnt++) 
 {
   if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)

   {
    if(OrderMagicNumber()==MagicNo && OrderSymbol() == Symbol())
    
      {
         if(OrderType() == OP_BUY)
            {if(OrderStopLoss()==0 && OrderTakeProfit() == 0)
            
              {ticketM = OrderModify(OrderTicket(),OrderOpenPrice(),Ask- Minimum_Move*Point*10,Ask+Average_Profit*Point*10,0,Blue);
            
              return(0);
              }
            }
          if(OrderType() == OP_SELL)
            {if(OrderStopLoss()==0 && OrderTakeProfit() == 0)
             
              {ticketM = OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Minimum_Move*Point*10,Bid-Average_Profit*Point*10,0,Blue);
              
              return(0);
              }
            }
       }
   }
 return(0);
 } 


Marco vd Heijden
Moderator
5956
Marco vd Heijden  

It doesn't show anything about

Minimum_Move

And it's calculation.

whroeder1
16572
whroeder1  
  1. if(OrderType() == OP_BUY){
     ticketM = OrderModify(OrderTicket(),OrderOpenPrice(),Ask- Minimum_Move*Point*10,Ask+Average_Profit*Point*10,0,Blue);
    
    OrderModify does not return a ticket number

  2. Check your return codes and find out why.
  3. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  4. Code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a pip is and use it, not points.
  5. You can't move stops closer to the market than the minimum (MODE_STOPLEVEL * _Point.) What are your values?
  6. for(cnt=0;cnt<OrdersTotal();cnt++) if(
       OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true
    && OrderMagicNumber()==MagicNo 
    && OrderSymbol() == Symbol() )
    In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) because while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (US brokers,) (or the EA only opens one order per symbol,) you can simply count down in a position loop, and you won't miss orders. Get in the habit of always counting down.
    2. For FIFO (US brokers,) and you (potentially) process multiple orders per symbol, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
    3. and check OrderSelect.
    4. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead, on the next order/server call.

  7. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool).
Alain Verleyen
Moderator
33810
Alain Verleyen  
whroeder1:

May I ask where is the answer to the specific question of the OP ?

Your efforts to provide help are laudable but I am afraid that too much information is killing information. An user which can't manage an error 130 will be lost with all these links.

Also as a side note using html table makes your post(s) unreadable on mobile and for people with disabilities, and even for some "normal" persons.

Marco vd Heijden
Moderator
5956
Marco vd Heijden  

The easiest way would be to print the values, and to look in code base at some examples then you can compare that code to yours to find the problem.

whroeder1
16572
whroeder1  
Alain Verleyen: May I ask where is the answer to the specific question of the OP ?
Item #3 and item #5
Ask- Minimum_Move*Point*10
is less than the spread plus stop level so is an invalid SL
Alain Verleyen
Moderator
33810
Alain Verleyen  
whroeder1:
Item #3 and item #5
is less than the spread plus stop level so is an invalid SL

Please take into account my advice about using html table uselessly.

Marco vd Heijden
Moderator
5956
Marco vd Heijden  


cape1354
188
cape1354  

I resolved with your help. Thank you.

To add comments, please log in or register