int CountSellPositions() { int totalPositions = PositionsTotal(); int sellPositionCount = 0; for (int i = 0; i < totalPositions; i++) { if (PositionGetTicket(i)==0) { Print("ERRROR CODE: ", GetLastError()); continue; } if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) sellPositionCount++; } return sellPositionCount; }
Also using long for counting loops is not logical.
Also using long for counting loops is not logical.
Thanks Yashar, that solved the issue.
I was using long since that was the type required for the second argument of PositionGetInteger().
It's interesting though that you are using PositionGetTicket(), when the docs say:
PositionGetInteger
The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect.
The docs for PositionGetTicket() also seem to say the same thing regarding PositionGetInteger():
PositionGetTicket
The function returns the ticket of a position with the specified index in the list of open positions and automatically selects the position to work with using functions PositionGetDouble, PositionGetInteger, PositionGetString.
Hence my use of PositionSelect(), which other tutorials have also used, but in your example you use PositionGetTicket().
It's strange to me that there appears to be two ways according to the docs to do the same thing, but one fails silently.
Anyway, thanks for your help
Much appreciated.
Regards
@HenZen, Improperly formatted code edited by moderator. In the future, please use the CODE button (Alt-S) when inserting code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Greetings,
I'm a bit puzzled by the following. The documentation recommends calling PositionSelect() before calling PositionGetInteger(), which I'm doing as follows:
Only problem is, the MT5 back-test freezes if I do the PositionSelect() call. If I comment out that check, everything works fine.Any idea what may be happening here?
Thanks