Mistake #1: You don't selected the position. Mistake #2: You are confusing the concept of "order" and "position".
An example of how to count positions. This example counts the number of positions for the current symbol ('Symbol()') and only those positions for which the 'Magic number' is equal to the given one.
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++ } } }
Pay attention: enumeration of positions in the loop goes 'to zero'.
We make sure to do 'PositionGetTicket'
- www.mql5.com
Mistake #1: You don't selected the position. Mistake #2: You are confusing the concept of "order" and "position".
An example of how to count positions. This example counts the number of positions for the current symbol ('Symbol()') and only those positions for which the 'Magic number' is equal to the given one.
Pay attention: enumeration of positions in the loop goes 'to zero'.
We make sure to do 'PositionGetTicket'
Thank you Vladimir for your response, that was very helpful.
- 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,
it seems i cant get buy or sell positions but when i call
it will return all positions and when calling
it doesn't return anything.
this is my code: