Order Modify error 4756 (10013 - invalid request)

 

Hi 


  I am writing some code to try modifying my order , I keep getting this message in the strategy tester


failed modify order #2 buy 0.00  at market sl: 0.00000 tp: 0.00000 -> 1.28769 (1.28669), sl: 1.27452 tp: 1.29569 [Invalid request]

the trade is being opened normally but modification fails

 can anyone help with this , attached below is the code i am trying

#include <Trade\Trade.mqh>
CTrade trade;
bool buy_once;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   buy_once = false;
//---
   return(INIT_SUCCEEDED);
  }

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

    
  double askNow =NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
  
  double bidNow =NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); 
  
  double equity = AccountInfoDouble(ACCOUNT_EQUITY);
  
  double balance = AccountInfoDouble(ACCOUNT_ASSETS);
  
  
  double SL = bidNow-(500*_Point);
  
  double TP = askNow+(500*_Point);
  
 
 
//  open orders
   if(equity >= balance && !buy_once) 
   { 
   
         trade.Buy(0.04,NULL,askNow,(bidNow-(500*_Point)),(askNow+(500*_Point)),NULL);
         buy_once = true;
         
        
         ulong ticket=trade.RequestOrder();
         double price=trade.RequestPrice();
         modifyOrder(price,SL,TP);
         
   }
  }
//+------------------------------------------------------------------+


 void modifyOrder(double price, double  SL, double TP )
 {
     
   
      
          
    ulong oTicket = trade.ResultOrder();      
    double stopLoss = SL-(500*_Point) ;
    double takeProfit  = TP+(500*_Point);
    double nPrice = price+(200*_Point);
    double slimit =  price+(100*_Point);
  
    
       
      if (trade.OrderModify(oTicket,nPrice,stopLoss,takeProfit,ORDER_TIME_GTC,0,slimit))
      {
      
       Print( "modified" + GetLastError());
      
      } else
      
      {
        Print("unable to modify " + GetLastError());
      }
 
  
 
 }
 

I am with the same problem, if you already sove this could you show it here? I'll do it if I find a way to fix it.


Thank you.

 
I don't use cTrade, but it seems you buy something and then want to change the price of it? Buy is not a pending order, I guess?

 

hello, do you have a solution for this issue? now i have the same problem.

thanks.

 
i guess u need to trigger that from a custom button