how to send sell stop and buy stop order ?

 

I am trying send write buy stop and sell stop order using below code in Strategy Tester, but it is giving me below error

failed instant sell stop limit 0.01 GBPUSD at 1.42418 sl: 1.42397 tp: 1.42440 [Invalid request]

                  MqlTradeRequest mqlrequest;
                  MqlTradeResult mqlresult;

                  mqlrequest.action=TRADE_ACTION_DEAL;
                  mqlrequest.price = NormalizeDouble(result.bid,5);        
                  mqlrequest.sl = NormalizeDouble(result.bid-0.00021,5);
                  mqlrequest.tp=NormalizeDouble(result.bid+0.00022,5);
                  mqlrequest.symbol=_Symbol;
                  mqlrequest.volume=Lot;
                  mqlrequest.magic=MagicNum;
                  mqlrequest.type=ORDER_TYPE_BUY_STOP;
                  mqlrequest.type_filling=ORDER_FILLING_FOK;                 
                  mqlrequest.deviation=Deviation;                             
                 

                  OrderSend(mqlrequest ,mqlresult); 

also please explain how to use price, sl and tp in sending buy stop and sell stop orders.

Thanks in advance!!

 
MqlTradeRequest mqlrequest={0};

Please read the documentation, buy stop/sell stop is a pending not a deal order.

TRADE_ACTION_PENDING

Place a trade order for the execution under specified conditions (pending order)

 

If you are using true ECN broker.

Order should be loaded in two step.

step 1.  Place the order with Sl=0.0 and TP=0.0.

step 2. Modify the order to set desired SL and TP.

 
Langtha Prosanta Daudung:

If you are using true ECN broker.

Order should be loaded in two step.

step 1.  Place the order with Sl=0.0 and TP=0.0.

step 2. Modify the order to set desired SL and TP.

Of course not.
 
Alain Verleyen:

Please read the documentation, buy stop/sell stop is a pending not a deal order.

TRADE_ACTION_PENDING

Place a trade order for the execution under specified conditions (pending order)

Alain Verleyen:

Please read the documentation, buy stop/sell stop is a pending not a deal order.

TRADE_ACTION_PENDING

Place a trade order for the execution under specified conditions (pending order)

Thanks for the reply Alain Verleyen !!

What are the parameters that we need to fill in MqlTradeRequest mqlrequest; in all below parameters to place Sell stop loss order after a buying.

I tried with below code but it is giving me invalid price.

      mqlrequest={0};

      mqlrequest.action = TRADE_ACTION_PENDING;                             
      mqlrequest.price = NormalizeDouble(latest_price.bid,_Digits);    
      mqlrequest.sl = NormalizeDouble(latest_price.bid + STP,_Digits);
      mqlrequest.tp = NormalizeDouble(latest_price.bid - TKP,_Digits);
      mqlrequest.symbol = _Symbol;                                        
      mqlrequest.volume = Lot;                                           
      mqlrequest.magic = MagicNum;                                 
      mqlrequest.type= ORDER_TYPE_SELL_STOP;        
      mqlrequest.type_filling = ORDER_FILLING_FOK;   

      mqlrequest.deviation=100;    



 
parashuram:

Thanks for the reply Alain Verleyen !!

What are the parameters that we need to fill in MqlTradeRequest mqlrequest; in all below parameters to place Sell stop loss order after a buying.

I tried with below code but it is giving me invalid price.

      mqlrequest={0};

      mqlrequest.action = TRADE_ACTION_PENDING;                             
      mqlrequest.price = NormalizeDouble(latest_price.bid,_Digits);    
      mqlrequest.sl = NormalizeDouble(latest_price.bid + STP,_Digits);
      mqlrequest.tp = NormalizeDouble(latest_price.bid - TKP,_Digits);
      mqlrequest.symbol = _Symbol;                                        
      mqlrequest.volume = Lot;                                           
      mqlrequest.magic = MagicNum;                                 
      mqlrequest.type= ORDER_TYPE_SELL_STOP;        
      mqlrequest.type_filling = ORDER_FILLING_FOK;   

      mqlrequest.deviation=100;    




Instructions given by Alain is clear.

Try to read carefully this document and example script:

https://www.mql5.com/en/docs/trading/ordersend



Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
Trade Functions / OrderSend - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: