about order modify error 130

 

i have some times this message (order modify error 130) and even  i use big stoploss

input string EaName = "ATLAS" ;
double priceNew1  ;
extern double lot = 0.01 ;
extern double TP = 0 ;
extern double SL = 0 ;
extern int MagicNumber1 = 1917 ;
double MyPoint,sl,tp ;
int Ticket,Decimal;
color N = clrNONE;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   if(Digits ==4 || Digits <=2)
      MyPoint=Point ;
   if(Digits ==3 || Digits ==5)
      MyPoint=Point*10 ;
   Comment(EaName,"\n\nalkosovi13@yahoo.fr") ;
   if(MarketInfo(Symbol(),MODE_MINLOT)<0.1)
      Decimal =2;
   else
      Decimal=1;

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {


  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()

  {

   double bolingbandlower1= iBands(NULL,0,20,2,0,PRICE_TYPICAL,MODE_LOWER,0);
   double bolingbandlower10=NormalizeDouble(bolingbandlower1,Digits);


//OrderModify

   int total=OrdersTotal();

   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {
         //MODIFY_BUYSTOP

         if((bolingbandlower10+10*MyPoint>OrderOpenPrice()+1*Point ||  bolingbandlower10+10*MyPoint<OrderOpenPrice()-1*Point) &&OrderType()==OP_BUYSTOP&& OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber1 &&OrderTicket()==Ticket)

           {

            priceNew1 = bolingbandlower10+10*MyPoint;

            if(TP==0)
               tp=0;
            else
               tp = priceNew1  + TP*MyPoint;
            if(SL==0)
               sl=0;
            else
               sl = priceNew1 - SL*MyPoint;

            bool  modify3 =  OrderModify(Ticket, priceNew1,NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),0,clrBlue);

           }

        }

     }


//BUY_STOP
   if(TB()<1  && Total(OP_BUYSTOP)<1  &&Low[0]<(Close[1]-5*MyPoint)&& Ask<  bolingbandlower10 && Bid >bolingbandlower10-2*MyPoint)

     {

      priceNew1 =  bolingbandlower10+10*MyPoint;

      if(TP==0)
         tp=0;
      else
         tp = priceNew1  +TP*MyPoint;
      if(SL==0)
         sl=0;
      else
         sl = priceNew1 - SL*MyPoint;


      Ticket= OrderSend(Symbol(),OP_BUYSTOP,lot,priceNew1,1, NormalizeDouble(sl,Digits),NormalizeDouble(tp,Digits),EaName,MagicNumber1,0,N);

     }

  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int TB()
  {
   int b = 0, i ;
   for(i=0; i < OrdersTotal() ; i++)
     {

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(Symbol() == OrderSymbol() && OrderMagicNumber() == MagicNumber1 && OrderType() == OP_BUY)
           {
            b++;
           }
     }
   return (b);

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 

// PENDING_ORDER

int Total(int type=-1)
  {
   int total =0,i;
   for(i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         if(Symbol()==OrderSymbol()&& OrderMagicNumber()==MagicNumber1   && (OrderType()==type||type==-1))
           {
            total++;
           }
     }
   return (total);
  }


//+------------------------------------------------------------------+

.. can some give a help plz

 
ALI AMRIOUI: i have some times this message (order modify error 130) and even  i use big stoploss
  1. extern double TP = 0 ;
    extern double SL = 0 ;
    ⋮
                   tp = priceNew1  + TP*MyPoint;
                   sl = priceNew1 - SL*MyPoint;
    
    Big SL? Your code show no SL.
  2. You aren't handling sells.
  3.    int total=OrdersTotal();
    
       for(int i=0; i<total; i++)
         {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

    Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
              PositionClose is not working - MQL5 programming forum (2020)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
              Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

  4. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
William Roeder #:
  1. Big SL? Your code show no SL.
  2. You aren't handling sells.
  3. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
              PositionClose is not working - MQL5 programming forum (2020)
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
              Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)

    You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

  4. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

No i use big StopLose when i test EA and i have error 130 ,, u can check it with u self