scale out of a position with a limit order

 

Something common, i am using latest metatrader 5, so i think its the last standard library, i want to create a limit order as soon as i create a trade to scale out half of position in 1:1. The problem i have its that everything is fine but for example if i am in a sell when it touches the buy limit order it just open a buy and the sell stays open the same, it doesnt close half of sell and let the other half run, as i want to. This is my code:

  if(m_trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,lot_size,price,stop_loss,0)) {      if(!m_position.Select(_Symbol)) return false; double one_to_one_rr_distance= m_position.StopLoss() - m_position.PriceOpen(); double take_half_price = m_position.PriceOpen() - one_to_one_rr_distance; m_trade.BuyLimit(lot_size/2,take_half_price, _Symbol, 0,0,ORDER_TIME_GTC,0,NULL); }


thank you in advance

 
Im new in this forex trade and im looking for anybody who can mentor me and guid me throngh the process of bucaom ing a mexport trader thank you all
 
raowl :

Something common, i am using latest metatrader 5, so i think its the last standard library , i want to create a limit order as soon as i create a trade to scale out half of position in 1:1. The problem i have its that everything is fine but for example if i am in a sell when it touches the buy limit order it just open a buy and the sell stays open the same, it doesnt close half of sell and let the other half run, as i want to. This is my code:


thank you in advance

It is necessary to understand the difference between a hedge and netting account. Example:

Current state Event Netting Hedge
USDCAD Sell 3.0 lot USDCAD BuyLimit 1.0 lo triggered -> USDCAD Sell 2.0 lot USDCAD Sell 3.0 lot
USDCAD Buy 1.0 lot


I also highly recommend working with OnTradeTransaction.

Reason: