ORDER_TYPE_SELL_STOP modification of trigger price

Nuno Madeira Amaro Pire Costa  

Hi all.

I am trying to build a function where I set a STOP order's request details, then I check if another exists on same pair, if it doesn't I create it, if it does I want to edit the parameters.

I can create it, but it does not change the parameters when found.

Can it be done?

I tried using both OrderSend with both Trade Action pending, trade action deal, and also tried with m_trade.OrderModify and still doesn't working.

Can someone point me in the right direction?


EIDT: Found the error. The if(OrderSend) needs to be inside { } for the "else if" to be applied to the if(ContaPos)

      if(contaPos(par_temp,ORDER_TYPE_SELL_STOP)==0) {if(OrderSend(request,result)) true;}
      else if(contaPos(par_temp,ORDER_TYPE_SELL_STOP)==1 && request.price> m_order.PriceOpen()) {
            request.action=TRADE_ACTION_MODIFY;
            m_trade.OrderModify(ticket,request.price,request.sl,request.tp,ORDER_TIME_SPECIFIED,request.expiration);         
      }
Basic Principles - Trading Operations - MetaTrader 5 Help
Basic Principles - Trading Operations - MetaTrader 5 Help
  • www.metatrader5.com
Before you proceed to study the trade functions of the platform, you must have a clear understanding of the basic terms: order, deal and position...
R4tna C  
Nuno Costa:

Hi all.

I am trying to build a function where I set a STOP order's request details, then I check if another exists on same pair, if it doesn't I create it, if it does I want to edit the parameters.

I can create it, but it does not change the parameters when found.

Can it be done?

I tried using both OrderSend with both Trade Action pending, trade action deal, and also tried with m_trade.OrderModify and still doesn't working.

Can someone point me in the right direction?


EIDT: Found the error. The if(OrderSend) needs to be inside { } for the "else if" to be applied to the if(ContaPos)

There is a pretty good example in the documentation - copy that and adjust as needed

https://www.mql5.com/en/docs/constants/tradingconstants/enum_trade_request_actions#trade_action_modify

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trade Operation Types - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: