Please read the documentation: PositionGetString
The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. The position property should be of the string type. There are 2 variants of the function.
The correct iteration in the loop by positions ((this is an example of counting positions)
int total=0; for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current positions { ulong ticket=PositionGetTicket(index); if(ticket>0); { if(PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC)==InpMagic) { total++ } } }
- www.mql5.com
Please read the documentation: PositionGetString
The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. The position property should be of the string type. There are 2 variants of the function.
The correct iteration in the loop by positions ((this is an example of counting positions)
Ah I see, so I need to make sure it has been "pre-selected using PositionGetSymbol or PositionSelect". It seems that PositionGetTicket() does the job also, so in my example this would be the correction:
void print_symbols() { for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current positions { ulong ticket=PositionGetTicket(i); if(ticket > 0) { string symbol = PositionGetString(POSITION_SYMBOL); Print(symbol); } } }
Thankyou!
- www.mql5.com
Ah I see, so I need to make sure it has been "pre-selected using PositionGetSymbol or PositionSelect ". It seems that PositionGetTicket() does the job also, so in my example this would be the correction:
Thankyou!
Yes, now your example will work. And yes: ' PositionGetTicket ' also selects a position
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys, why doesnt this Print out the Symbols of open positions please?