Error 130 ordermodify but why ?

 

hy  , i dont know  why in my script  return always error 130  if i set a price 1.09556 for example  work

anyone can help me ?   thnks

//+------------------------------------------------------------------+
//|                                                   ExpertPens.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
extern int Dimen=144;
extern int Buffer=0;
extern int Point4TS=8;
extern int ProfitMin=8;
extern int BufferTrigger=0;
extern int MAgickNumber=123458;
extern double LottSize= 0.01;
extern string StartTime ="00:00:00";
extern string EndTime ="22:00:00";

int ticketBuy;
int ticketSell;
int CtrlBuyTP=0;
int CtrlSellTP=0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ChartSetSymbolPeriod(0,Symbol(),PERIOD_D1);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
  double ND(double val)
{
return(NormalizeDouble(val, Digits));
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   double bid =MarketInfo(Symbol(),MODE_BID);

   if((TimeToString(TimeLocal(),TIME_SECONDS)> StartTime)&&(TimeToString(TimeLocal(),TIME_SECONDS)<EndTime)&&(OrdersTotal()==0)) // se sono  in apertura orario e non ho altre trade aperte
     {

      //candele tutte
      if(((High[1]-Low[1])*Point) < Dimen)   //e' una candela piccola ?  si
        {
         if(((bid*Point)+Buffer)> (High[1]*Point))   // la quotazione  attuale  supera l hig precedente ? si
           {
            ticketBuy=OrderSend(Symbol(),OP_BUY,LottSize,Ask,3,0,0,"By ExpertPens BUY",MAgickNumber,0,clrGreen);  // compro
            CtrlBuyTP=0;
           }
         if(((bid*Point)+Buffer)< (Low[1]*Point))  // la quotazione attuale  e piu bassa del low precedente ?  si
           {
            ticketSell=OrderSend(Symbol(),OP_SELL,LottSize,Bid,3,0,0,"My ExpertPens SELL",MAgickNumber,0,clrRed);
            CtrlSellTP=0;
           }
        }
      // candelone lungo
      if(((High[1]-Low[1])*Point) > Dimen)
        {
         double Median=((High[1]+Low[1])/2);
         if(((bid*Point)+Buffer)> (Median*Point))   // la quotazione  attuale  supera l hig precedente ? si
           {
            ticketBuy=OrderSend(Symbol(),OP_BUY,LottSize,Ask,3,0,0,"By ExpertPens BUY",MAgickNumber,0,clrGreen);  // compro
            CtrlBuyTP=0;
           }
         if(((bid*Point)+Buffer)< (Median*Point))  // la quotazione attuale  e piu bassa del low precedente ?  si
           {
            ticketSell=OrderSend(Symbol(),OP_SELL,LottSize,Bid,3,0,0,"My ExpertPens SELL",MAgickNumber,0,clrRed);
            CtrlSellTP=0;
           }
        }

     }
   if(OrdersTotal()>0)
     {
      double Median2=((High[1]+Low[1])/2);
      // devo capire  che  ordine c'e' se  e' un buy  e mi va  contro alla candela  1  chiudo e reverso ,
      for(int i= OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS)==true)
           {
            if(OrderMagicNumber() == MAgickNumber)
              {
               if(OrderType() == OP_BUY)
                 {


                  if((Bid-OrderOpenPrice())>ProfitMin*Point*10 && CtrlBuyTP==0  && (Bid-OrderOpenPrice())>Point4TS*Point*10)
                    {
                     double NewSL=Bid-(Point4TS*Point*10);
                     bool res= OrderModify(OrderTicket(),OrderOpenPrice(),NewSL,OrderTakeProfit(),0,Yellow);
                     CtrlBuyTP=1;
                    }



                  //---- close the position
                  if(((High[1]-Low[1])*Point) > Dimen) //  candelona lunga deve stoppare  ameta candela
                    {
                     if(bid<=Median2)
                       {
                        bool ResOC=OrderClose(OrderTicket(), OrderLots(), Bid, 5, Green);
                        // ticketSell=OrderSend(Symbol(),OP_SELL,LottSize,Bid,3,0,0,"My ExpertPens SELL",MAgickNumber,0,clrRed);
                       }
                    }
                  else   // candele corte
                    {
                     // if(bid<=Low[1])
                     if(bid<=Median2)
                       {
                        bool ResOC2=OrderClose(OrderTicket(), OrderLots(), Bid, 5, Green);
                        //   ticketSell=OrderSend(Symbol(),OP_SELL,LottSize,Bid,3,0,0,"My ExpertPens SELL",MAgickNumber,0,clrRed);
                       }
                    }
                 }
               //---- if the SELL position has been opened,
               if(OrderType() == OP_SELL)
                 {
                  Print("QUANTEEE111444444    "+(Bid));
                  Print("QUANTEEE1113333    "+(OrderOpenPrice()));
                  Print("QUANTEEE    "+(OrderOpenPrice()- (ProfitMin*Point)));
                   Print("QUA    "+CtrlSellTP);
                  //if((Ask-OrderOpenPrice())<ProfitMin*Point*10 && CtrlSellTP==0)
                  if((Bid <= ND((OrderOpenPrice()-(ProfitMin*Point)))) && (CtrlSellTP==0))
                    {
                     Print("SONO QUIIIIIIII    "+ND((Bid-Point4TS*Point)));
                     double NewSL=ND(Bid-(Point4TS*Point));
                     bool resOM=OrderModify(OrderTicket(),OrderOpenPrice(),NewSL,OrderTakeProfit(),0,Yellow);
                  
                   //  CtrlSellTP=1;
                    }




                  if(((High[1]-Low[1])*Point) > Dimen)
                    {
                     if(bid>=Median2)
                       {
                        bool resOC=OrderClose(OrderTicket(), OrderLots(), Ask, 5, Red);
                        // ticketBuy=OrderSend(Symbol(),OP_BUY,LottSize,Ask,3,0,0,"By ExpertPens BUY",MAgickNumber,0,clrGreen);  // compro
                       }
                    }
                  else
                    {
                     Print(" DEMA DE MEMM  "+bid+ " HKHK "+Low[1]);
                     // if(bid>=Low[1])
                     if(bid>=Median2)
                       {
                        bool Res_OC=OrderClose(OrderTicket(), OrderLots(), Ask, 5, Red);
                        ticketBuy=OrderSend(Symbol(),OP_BUY,LottSize,Ask,3,0,0,"By ExpertPens BUY",MAgickNumber,0,clrGreen);  // compro
                       }
                    }
                 }
              }
           }
        }

     }








  }

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

//+------------------------------------------------------------------+
 
faustf:

hy  , i dont know  why in my script  return always error 130  if i set a price 1.09556 for example  work

anyone can help me ?   thnks

Please highlight the code that gives the error.

 
 //---- if the SELL position has been opened,
               if(OrderType() == OP_SELL)
                 {
                  Print("QUANTEEE111444444    "+(Bid));
                  Print("QUANTEEE1113333    "+(OrderOpenPrice()));
                  Print("QUANTEEE    "+(OrderOpenPrice()- (ProfitMin*Point)));
                   Print("QUA    "+CtrlSellTP);
                  //if((Ask-OrderOpenPrice())<ProfitMin*Point*10 && CtrlSellTP==0)
                  if((Bid <= ND((OrderOpenPrice()-(ProfitMin*Point)))) && (CtrlSellTP==0))
                    {
                     Print("SONO QUIIIIIIII    "+ND((Bid-Point4TS*Point)));
                     double NewSL=ND(Bid-(Point4TS*Point));
                     bool resOM=OrderModify(OrderTicket(),OrderOpenPrice(),NewSL,OrderTakeProfit(),0,Yellow);
                  
                   //  CtrlSellTP=1;
                    }
 
How can the SL be below the Bid on a sell order?
 

also if i use Ask do the same error


           if(OrderType() == OP_SELL)
                 {
                  Print("QUANTEEE111444444    "+(Ask));
                  Print("QUANTEEE1113333    "+(OrderOpenPrice()));
                  Print("QUANTEEE    "+(OrderOpenPrice()- (ProfitMin*Point)));
                   Print("QUA    "+CtrlSellTP);
                  //if((Ask-OrderOpenPrice())<ProfitMin*Point*10 && CtrlSellTP==0)
                  if((Ask <= ND((OrderOpenPrice()-(ProfitMin*Point)))) && (CtrlSellTP==0))
                    {
                     Print("SONO QUIIIIIIII    "+ND((Ask-Point4TS*Point)));
                     double NewSL=ND(Ask-(Point4TS*Point));
                     bool resOM=OrderModify(OrderTicket(),OrderOpenPrice(),NewSL,OrderTakeProfit(),0,Yellow);
                  
                   //  CtrlSellTP=1;
                    }
 
faustf: also if i use Ask do the same error

What part of "How can the SL be below the Bid on a sell order" was unclear to you?

 
faustf:

also if i use Ask do the same error


if(NewSL!=OrderStopLost())  bool resOM=OrderModify(OrderTicket(),OrderOpenPrice(),NewSL,OrderTakeProfit(),0,Yellow);
 
Mehmet Bastem:
Your suggestion only fixes error #1. OPs problem is currently error 130.
 
William Roeder:

What part of "How can the SL be below the Bid on a sell order" was unclear to you?

all is not clear , if i just open a trade sell , after i want set with ordermodify a stoploss  X pips after  

Ask price is       1.09458  and  new stop loss is      1.09451 

example

the problem is about because not set a stoploss when open a trade ???



 
faustf: Ask price is       1.09458  and  new stop loss is      1.09451

That is impossible. That would be a Take Profit for a sell.

 

but if the beaten price is below the take profit price I don't think it can be entered because the price has already exceeded the take profit.

but thanks again i will try to find a solution

Reason: