Download MetaTrader 5

My stoploss and take profit will not move

To add comments, please log in or register
Added support for the Spanish language. Come and check it out!
Diane Minshew
350
Diane Minshew 2014.05.17 09:31 
void LongPositionMoveSLTP()
{
double      slb = NormalizeDouble(iEnvelopeUp[1],_Digits);
double      tpb = NormalizeDouble(iEnvelopeBtm[1],_Digits);
 
   MqlTradeRequest mrequest;                            
   MqlTradeResult mresult;   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);

   if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)

      {
       mrequest.action=TRADE_ACTION_SLTP;
       mrequest.sl = slb;   
       mrequest.tp = tpb;
       OrderSend(mrequest,mresult);   
      }
      
It gives me the error: 2014.05.17 03:18:49    Core 1    2014.01.31 00:00:00   failed modify buy 0.00  sl: 0.00000, tp: 0.00000 -> sl: 1.35017, tp: 1.37186 [Invalid request]

The order is a pending order that has been triggered with stoploss and takeprofit already set

From order to position the position has no SL or TP. 

But as you can see there is no value???

Alain Verleyen
Moderator
30737
Alain Verleyen 2014.05.17 09:51  
wehsnim:
It gives me the error: 2014.05.17 03:18:49    Core 1    2014.01.31 00:00:00   failed modify buy 0.00  sl: 0.00000, tp: 0.00000 -> sl: 1.35017, tp: 1.37186 [Invalid request]

The order is a pending order that has been triggered with stoploss and takeprofit already set

From order to position the position has no SL or TP. 

But as you can see there is no value???

Where did you set the position to modify ?

SL & TP Modification

Trade order to modify the StopLoss and/or TakeProfit price levels. It requires to specify the following 4 fields:

action

symbol

sl

tp

I strongly suggest you to check the return value of OrderSend() and to process error in your code.

Diane Minshew
350
Diane Minshew 2014.05.18 04:43  
angevoyageur:

Where did you set the position to modify ?

SL & TP Modification

I strongly suggest you to check the return value of OrderSend() and to process error in your code.

I read your post. Went to the documentation.

Added : mrequest.symbol=Symbol();

The function came together beautifully.

I am now correcting the OrderSend Function..

Thank you for the help. :)

Alain Verleyen
Moderator
30737
Alain Verleyen 2014.05.18 12:26  
wehsnim:

I read your post. Went to the documentation.

Added : mrequest.symbol=Symbol();

The function came together beautifully.

I am now correcting the OrderSend Function..

Thank you for the help. :)

You are welcome.
To add comments, please log in or register