How does one close a position under the new hedging system via an MqlTradeRequest?
When
modifying or closing a position in the hedging system, make sure to
specify its ticket (MqlTradeRequest::ticket). You can specify a ticket
in the netting system as well, however positions are identified by a
symbol name.
MetaTrader 5 features hedging position accounting system
- 2016.03.21
- MetaQuotes Software Corp.
- www.mql5.com
In order to expand possibilities of retail Forex traders, we have added the second accounting system — hedging. Now, it is possible to have multiple positions per symbol, including oppositely directed ones. This paves the way to implementing trading strategies based on the so-called "locking" — if the price moves against a trader, they can open a position in the opposite direction.
Alain Verleyen:
When
modifying or closing a position in the hedging system, make sure to
specify its ticket (MqlTradeRequest::ticket). You can specify a ticket
in the netting system as well, however positions are identified by a
symbol name.
Hi
I had seen the article which is why I tried the code below. However I get the error invalid request. Already contacted service desk and they are yet to revert.
for(int i=0;i<PositionsTotal();i++) { if(PositionSelect(PositionGetSymbol(i))) { if(PositionGetSymbol(i)==SymbolName) { if(SymbolInfoTick(SymbolName,__tick)) { float _bid=(float)__tick.bid,_ask=(float)__tick.ask; long _position_ticket = PositionGetInteger(POSITION_TICKET); __request.symbol = PositionGetSymbol(i); __request.action = TRADE_ACTION_CLOSE_BY; __request.position = _position_ticket; __request.type_filling = ORDER_FILLING_FOK; __request.type_time = ORDER_TIME_GTC; __request.magic = MagicNumber; if(OrderCheck(__request,__check)){ if(!OrderSend(__request,__result)){ _close_error=GetLastError(); printf(__FUNCTION__+" RESULT ON "+SymbolName+" "+EnumToString((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))+" could not be closed "+ ", WITH ask: "+DoubleToString(_ask)+", bid: "+DoubleToString(_bid)+ " err # "+IntegerToString(_close_error)+" returned code: "+IntegerToString(__result.retcode)+", broker comments: "+__result.comment); return(_close_error);} else{ _close_error=GetLastError(); if(_close_error!=0&&(__result.retcode!=TRADE_RETCODE_PLACED||__result.retcode!=TRADE_RETCODE_DONE)){ printf(__FUNCTION__+" "+SymbolName+" "+EnumToString((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))+" may not be closed "+ ", WITH ask: "+DoubleToString(_ask)+", bid: "+DoubleToString(_bid)+ " err # "+IntegerToString(_close_error)+" returned code: "+IntegerToString(__result.retcode)+", broker comments: "+__result.comment);}}} else{ _close_error=GetLastError(); printf(__FUNCTION__+" CHECK ON "+SymbolName+" "+EnumToString((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE))+" could not be closed "+ ", WITH ask: "+DoubleToString(_ask)+", bid: "+DoubleToString(_bid)+ " err # "+IntegerToString(_close_error)+" returned code: "+IntegerToString(__check.retcode)+", broker comments: "+__check.comment); return(_close_error); } } } } }
You edited your original answer to my question so my comment and code no longer follow what you had written...
STEPHEN NJUKI:
You edited your original answer to my question so my comment and code no longer follow what you had written...
Who are you talking to ?
You edited your original answer to my question so my comment and code no longer follow what you had written...
Alain Verleyen:
Who are you talking to ?
Sorry, there was only one respondent here. Who are you talking to ?
Any way no worries service desk said they will revert.
STEPHEN NJUKI:
Sorry, there was only one respondent here.
I don't know what you are talking about, I didn't change anything.
Sorry, there was only one respondent here.
Any way no worries service desk said they will revert.
Then I guess I had not properly read your earlier reply. Sorry
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register