openPosition = PositionSelect(_Symbol); positionType = PositionGetInteger(POSITION_TYPE); position_ticket=PositionGetTicket(0);First, you select a position with the chart's symbol. Last, you select a random order.
I have assumed that the terminal has only one open trade at any given time. This should work with this condition, shouldn't it.?
bool PositionSelect( string symbol // Symbol name );
Note
For the "netting" interpretation of positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING and ACCOUNT_MARGIN_MODE_EXCHANGE), only one position can exist for a symbol at any moment of time. This position is a result of one or more deals. Do not confuse positions with valid pending orders, which are also displayed on the Trading tab of the Toolbox window.
If individual positions are allowed (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), multiple positions can be open for one symbol. In this case, PositionSelect will select a position with the lowest ticket.
Function PositionSelect() copies data about a position into the program environment, and further calls of PositionGetDouble(), PositionGetInteger() and PositionGetString() return the earlier copied data. This means that the position itself may no longer exist (or its volume, direction, etc. has changed), but data of this position still can be obtained. To ensure receipt of fresh data about a position, it is recommended to call PositionSelect() right before referring to them.
The "PositionSelect" function is primarily designed for netting accounts, so I always recommend using a universal algorithm:
for(int i=PositionsTotal()-1; i>=0; i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic) { ... }

- www.mql5.com
Note
For the "netting" interpretation of positions (ACCOUNT_MARGIN_MODE_RETAIL_NETTING and ACCOUNT_MARGIN_MODE_EXCHANGE), only one position can exist for a symbol at any moment of time. This position is a result of one or more deals. Do not confuse positions with valid pending orders, which are also displayed on the Trading tab of the Toolbox window.
If individual positions are allowed (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING), multiple positions can be open for one symbol. In this case, PositionSelect will select a position with the lowest ticket.
Function PositionSelect() copies data about a position into the program environment, and further calls of PositionGetDouble(), PositionGetInteger() and PositionGetString() return the earlier copied data. This means that the position itself may no longer exist (or its volume, direction, etc. has changed), but data of this position still can be obtained. To ensure receipt of fresh data about a position, it is recommended to call PositionSelect() right before referring to them.
The "PositionSelect" function is primarily designed for netting accounts, so I always recommend using a universal algorithm:
Thanks... Issue resolved. There was some logical error in modifying SL.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This trade was to help me in scalping. but it isn't closing trades. Objective was to find alternative for sl or tp at a level closer than stop levels of a pair. please help.
Tried closing them by removing any condition for closing trades but it still didn't work. These set of statements to close trades worked in my previous programming but aren't working here on my manual trades. No concept of magic number taken into consideration so this should work.
Thanks everyone.