Order modification does not work

 

Hello All!

Could you please help me out with my code? Below I'm presenting my code:

extern double Lots               = 0.01;
extern double MovingPeriod       = 27;
extern double MovingShift        = 0;
extern double trailing           = 5;

int start()
{
   int cnt, ticket, total;
   double ma;

ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_MEDIAN,0);

total=OrdersTotal();

   if(total<1)
     {
      if(Open[0]>Open[1] && Open[1]<ma && Close[1]>ma)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Low[0]-200*Point,High[0]+300*Point,"My order",0,Green);
         return(0);
        }
     }
 
   for(cnt=0;cnt<total;cnt++)
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     
      if(OrderType()==OP_BUY)
         {
            if (trailing > 0)
               {
                  if (Bid - OrderOpenPrice() > Point * trailing)
                     {
                        if (OrderTakeProfit() < Bid - Point * trailing)
                           {
                              OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*trailing,0,Pink);
                              return(0);
                           }
                     }
               }
          }
   }
}

I think that modification of orders does not work at all? Could you please take a look and advise me on this?

Cheers!

 

How can this be true:

if (OrderTakeProfit() < Bid - Point * trailing)

and after that, what is the value of Point? Maybe you get Error 130 when it tries to modify your order.

 

Yes, I get Error 130. I'm a beginner.

I'd like to learn the code if I want to move up Take Profit if price increases. Could you please help me out?

 

 How can the TakeProfit price be below Bid for a BUY order?

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*trailing,0,Pink);


Maybe you mean:

                        if (OrderTakeProfit() - Bid < Point * trailing)
                           {
                              OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+Point*trailing,0,Pink);
                              return(0);
                           }


Is your SL 200 Pips and your TP 300 Pips or 20 and 30 Pips? I only ask because I am not sure about the values in Pips you want for trailing (and for slippage in your OrderSend() function)?

 
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*trailing,0,Pink);
  1. What are Function return values ? How do I use them ? - MQL4 forum
  2. Tell me how the TP can be set below the bid on a buy order. You can not place stops closer to market than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point.
  3. Not adjusting for 4/5 digit brokers. (tp, sl, AND slippage.) Not adjusting for ECN brokers.
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){                                             OptInitialization();
         if (Digits % 2 == 1){  // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
    //---- These are adjusted for 5 digit brokers.
        //{ On ECN brokers you must open first and THEN set stops
        //int ticket = OrderSend(..., 0,0,...)
        //if (ticket < 0)
        //   Alert("OrderSend failed: ", GetLastError());
        //else if (!OrderSelect(ticket, SELECT_BY_TICKET))
        //   Alert("OrderSelect failed: ", GetLastError());
        //else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0))
        //   Alert("OrderModify failed: ", GetLastError());
        //}