Send an order in reverse direction using position id obtained after the first order execution. Here is some code.
Thank you.
I tried the Stanislav's recommendation and it works so far.
It was necessary simply to find the position ticket and to set it in the opposite order's request.
Find ticket:
int posTotal=PositionsTotal(); for(int posIndex=0;posIndex<posTotal;posIndex++) { ulong ticket=PositionGetTicket(posIndex); if(PositionSelectByTicket(ticket) && PositionGetString(POSITION_SYMBOL)==_Symbol && PositionGetInteger(POSITION_MAGIC)==Magic_Number) { posType = PositionGetInteger(POSITION_TYPE); posLots = PositionGetDouble(POSITION_VOLUME); posTicket = ticket; break; } }
Set ticket in request:
request.position = ticket;
Miroslav Popov:
Thank you.
I tried the Stanislav's recommendation and it works so far.
It was necessary simply to find the position ticket and to set it in the opposite order's request.
Find ticket:
Set ticket in request:
Hello Miroslav,
I'm having a hard time trying to close an open position. Can you please post your entire code that closes the opened position? I guess it would help lots of us
Thanks a lot.

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
Let's open a position in a Hedge account with a given Magic_Number on the current _Symbol.
Open Long 0.1 lots.
How to find this position and close it?
I assume I have to first open an opposite one:
Ok. Now I have one long and one short positions with the same magic number.
How to execute CloseBy ?