Invalid request - page 2

 

Thanks a lot you are great!

the stoploss value is valid

I add the ZeroMemory function and I managed to modify the stoploss it works great.

I now have to fix the initial stoploss value which is 0 the position is open and I try to modify the SL with a request action but it doesn't work the code 

 if(Buy_Condition_1 && Buy_Condition_2)
     {
      if(Buy_Condition_3 && Buy_Condition_4)
        {
         // any opened Buy position?
         if(Buy_opened)
           {
            Alert("We already have a Buy Position!!!");
            return;    // Don't open a new Buy Position
           }
         ZeroMemory(mrequest);
         mrequest.action = TRADE_ACTION_DEAL;                                  // immediate order execution
         mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // latest ask price
         mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                            // currency pair
         mrequest.volume = Lot;                                                 // number of lots to trade
         mrequest.magic = EA_Magic;                                             // Order Magic Number
         mrequest.type = ORDER_TYPE_BUY;                                        // Buy Order
         mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
         mrequest.deviation=100;                                                // Deviation from current price
         //--- send order
         OrderSend(mrequest,mresult);
         // get the result code
         
         
   Print("SLSETUP:",NormalizeDouble(latest_price.bid + STP*_Point,_Digits));
   
   
   MqlTradeRequest lrequest;  // To be used for sending our trade requests
   MqlTradeResult lresult;    // To be used to get our trade results
   
   
   //ZeroMemory(lrequest);
   lrequest.action = TRADE_ACTION_SLTP;
   lrequest.symbol = Symbol();
   lrequest.sl = NormalizeDouble(latest_price.bid + STP*_Point,_Digits); // Stop Loss
   lrequest.tp = NormalizeDouble(latest_price.bid - TKP*_Point,_Digits); // Take Profit
   
   
   
   OrderSend(lrequest,lresult);
         
         
         
         if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
           {
            Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
           }
         else
           {
            Alert("The Buy order request could not be completed -error:",GetLastError());
            ResetLastError();           
            return;
           }
        }
     }
 
fx0011:

Thanks a lot you are great!

the stoploss value is valid

I add the ZeroMemory function and I managed to modify the stoploss it works great.

I now have to fix the initial stoploss value which is 0 the position is open and I try to modify the SL with a request action but it doesn't work the code 

  • As I already said, you have to check the returned value when you are using a function who can fail. So check the returned value of OrderSend().
  • When you are copying code, try to understand it. If a test on mresult.retcode is done, this test must be just after to call to OrderSend where mresult is used.
  • Why are you commenting ZeroMemory(lrequest) ?
  • What does that means "that doesn't work" ? What is the error code or log you get ?
 
Thank you for your answer I will check it tomorrow...
 

Also it is not guaranteed that 2 OrderSend should work in the same tick,

as the trade server could not accept (most of the times in my experience) more than one synchronous trade operations.

In your OnTick function you should check your EA state and act in consequence, something like this:

a.) is a position opened for the symbol ?

Yes ->  b.) is the position protected (has sl and tp) ?

  • No -> send order to set the sl and tp
  • Yes -> Do nothing just wait (or manage to anticipate the close of the position using signals)

 

No -> check your signals for buy or sell and eventually place buy or sell

Reason: