Please show your code if you need coding help.
I don't want to use pending orders to partial close in netting mode...
I would like to use immediate orders (to market)
if(m_trade.SellLimit(rp1_ct,m_symbol.Bid()+rp1_pt*_s_point,_Symbol,0,0,ORDER_TIME_GTC,TimeTradeServer()+PeriodSeconds(PERIOD_M1),"RP1_Sell"))
but PositionClosePartial fails, it only works in hedging ? correct?
if (m_trade.PositionClosePartial(_p_symbol,rp1_ct,m_symbol.Spread()*3)) //closepartial is hedging mode? it fails
rp1_ct=1 ; (1 lot / 1 contract)
rp1_pt=200; (200 pts)
//+------------------------------------------------------------------+ //| function rp1 | //+------------------------------------------------------------------+ void fRP1() { if(!m_symbol.RefreshRates())return; int _tp=PositionsTotal(); for(int i=_tp-1; i>=0; i--) { string _p_symbol=PositionGetSymbol(i); //if(WorkSymb==CurrentSymbol && _p_symbol!=_Symbol) continue; if(_p_symbol!=_Symbol) continue; if(FezRP1) break; if(m_magic>=0 && m_magic!=PositionGetInteger(POSITION_MAGIC)) continue; double _p_op = PositionGetDouble(POSITION_PRICE_OPEN); double _s_point = SymbolInfoDouble(_p_symbol, SYMBOL_POINT); //--- if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { double Bid=SymbolInfoDouble(_p_symbol,SYMBOL_BID); if(_p_op+rp1_pt*_s_point>=Bid) { Print(_p_op+rp1_pt*_s_point,"===>",Bid); Print("RP1=BUY===========================================================");if(m_trade.SellLimit(rp1_ct,m_symbol.Bid()+rp1_pt*_s_point,_Symbol,0,0,ORDER_TIME_GTC,TimeTradeServer()+PeriodSeconds(PERIOD_M1),"RP1_Sell"))//if (m_trade.PositionOpen(_Symbol,ORDER_TYPE_SELL,rp1_ct,SymbolInfoDouble(_Symbol, SYMBOL_BID),0,0,m_magic)); //if (m_trade.PositionClosePartial(_p_symbol,rp1_ct,m_symbol.Spread()*3)) //closepartial só tá funcionando em hedge e não uso isso { FezRP1=true; } } } else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { double Ask=SymbolInfoDouble(_p_symbol,SYMBOL_ASK); if(_p_op-rp1_pt*_s_point<=Ask) { Print(_p_op-rp1_pt*_s_point,"===>",Ask); Print("RP1=BUY==========================================================="); //if (m_trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,rp1_ct,SymbolInfoDouble(_Symbol, SYMBOL_ASK),0,0,m_magic)); if(m_trade.BuyLimit(rp1_ct,m_symbol.Ask()-rp1_pt*_s_point,_Symbol,0,0,ORDER_TIME_GTC,TimeTradeServer()+PeriodSeconds(PERIOD_M1),"RP1_Buy")) //if (m_trade.PositionClosePartial(_p_symbol,rp1_ct,m_symbol.Spread()*3)) //closepartial is hedging mode? it fails { FezRP1=true; } } } } }
If you buy 1 lot, and you want to partially close it with 0.5 lots, just sell 0.5 lots. The remaining will be a 0.5 buy.
If you buy 1 lot, and you want to partially close it with 0.5 lots, just sell 0.5 lots. The remaining will be a 0.5 buy.
This.
...however, it does work if you replace the Trade class with a slightly modified version.
If you buy 1 lot, and you want to partially close it with 0.5 lots, just sell 0.5 lots. The remaining will be a 0.5 buy.
It is just an example. In netting mode partial close is by means of opposite order with a lot size lower then the current volume. If bigger you change from direction. If volume is the same, the position is closed.
ok tks...
I was complicating what is simple... I just dropped a opposite order and I get my partial working fine... tks for all replies
This.
...however, it does work if you replace the Trade class with a slightly modified version.
and nicholishen, tk you for the modded trade.mqh it gave some good ideas.. lol

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm trying to use partialclose but it's not working, I think that this mt5 is only for hedgeing
Could someone show me a similar function/code for partialclose that works with netting mode?
I buy 2 and to partialclose 1 contract.
I sell 2 and to partialclose 1 contract.
thanks