Can anyone see what I am doign wrong with this OrderModify?

 

Hi

I have an EA but my broker has decided that now the EA's cannot create an order with stops simultaniously, you must enter then market, then modify the order with the correct stops.

Here is some of my code, you can see I have added the OrderModify code but when testing this the EA just seems to enter the market and no stops are placed:

   if(Trade>0){
            err=0;
            GetLastError();
            RefreshRates();   
            if(StopLoss!=0){sl = nd(Ask+StopLoss*Point*mno);}else{sl=0;}
            if(TakeProfit!=0){tp =nd(Bid-TakeProfit*Point*mno);}else{tp=0;}            
                 err = OrderSend(Symbol(),
                                  OP_SELL,
                               TradingLot,
                                  nd(Bid),
                                  slp*mno,
                                       /*sl*/0,
                                       /*tp*/0,
                                     comm,
                              MagicNumber,
                                        0,
                         GetOrdCl(OP_SELL)
                                 );
                         
             OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL));
            if(err>0){
               Alert("Opened order ",GetNameOP(OP_SELL));
            }else{
               Fun_Error(GetLastError());
            }          
         }
      }
   }
         }
      }
   }

Thanks

Antony

 

Just one little thing

 if(Trade>0){
            err=0;
            GetLastError();
            RefreshRates();   
            if(StopLoss!=0){sl = nd(Ask+StopLoss*Point*mno);}else{sl=0;}
            if(TakeProfit!=0){tp =nd(Bid-TakeProfit*Point*mno);}else{tp=0;}            
                 err = OrderSend(Symbol(),
                                  OP_SELL,
                               TradingLot,
                                  nd(Bid),
                                  slp*mno,
                                       /*sl*/0,
                                       /*tp*/0,
                                     comm,
                              MagicNumber,
                                        0,
                         GetOrdCl(OP_SELL)
                                 );
             if(err!=-1)if(OrderSelect(err,SELECT_BY_TICKET))           
             OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL));
            if(err>0){
               Alert("Opened order ",GetNameOP(OP_SELL));
            }else{
               Fun_Error(GetLastError());
            }          
         }
      }
   }
         }
      }
   }
 
tonyjms2005:

Hi

I have an EA but my broker has decided that now the EA's cannot create an order with stops simultaniously, you must enter then market, then modify the order with the correct stops.

Here is some of my code, you can see I have added the OrderModify code but when testing this the EA just seems to enter the market and no stops are placed:


Roger is correct, one other thing to consider, what will you do if the OrderSend works OK but the OrderModify fails ?
 
            if(err!=-1)if(OrderSelect(err,SELECT_BY_TICKET))           
             OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL));
            if(err>0){
               Alert("Opened order ",GetNameOP(OP_SELL));
            }else{
               Fun_Error(GetLastError());
            }          
Close but if order didn't open, shouldn't be calling orderModify. Always test return codes.
            if(err < 0)
               Fun_Error(GetLastError());
            else if(!OrderSelect(err,SELECT_BY_TICKET))           {
               Fun_Error(GetLastError());
            else if(!OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL)))
               Fun_Error(GetLastError());
            else
               Alert("Opened order ",GetNameOP(OP_SELL));
 

Hi

Thanks, i cant believe I missed that.

Thanks again

Antony

 
WHRoeder:
Close but if order didn't open, shouldn't be calling orderModify. Always test return codes.

If OrderSend failed err = -1 "Returns number of the ticket assigned to the order by the trade server or -1 if it fails" . . . so OrderModify won't be called . . or am I missing something ?

if(err!=-1)if(OrderSelect(err,SELECT_BY_TICKET))           
             OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL));

or . . . .

if(err != -1)
   {
   if(OrderSelect(err,SELECT_BY_TICKET))  
     {
      OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL));
     }
   }         
             
Reason: