Always 0 because you are comparing different things :
if( oType==tradeType)
this can't be true. A position type is not the same as an order type.
Always 0 because you are comparing different things :
this can't be true. A position type is not the same as an order type.
Thanks for your response
How do you know it always returns zero ?
If there is a position, as soon as the terminal is notified about it PositionTotal() must return a value >0
Turns out the culprit was the variable type.
Change
int total = PositionsTotal();
to
uint total = PositionsTotal();
The corrected version of the code is this
int _Currently_Open_Trades_Of_Type(ENUM_ORDER_TYPE tradeType) { int totalPositions=0; uint total = PositionsTotal(); int oType; if(total<=0) { return(0); } else { for(uint i=0;i<total;i++) { if (!PositionSelect(_Symbol)) continue; oType = (int)PositionGetInteger(POSITION_TYPE); if( oType==tradeType) { totalPositions++; } } } return(totalPositions); }
BTW, oType is just a variable name.
How do you know it always returns zero ?
If there is a position, as soon as the terminal is notified about it PositionTotal() must return a value >0
I placed a "watch" on the variable during debug.
the fix was to change:
int total = PositionsTotal(); touint total = PositionsTotal();
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have the code below but PostionsTotal() is always returning zero even when there is open trades.
I am trying to return the total number of currently open trades.
I am using MT5 downloaded from Metaquotes.
Any help highly appreciated. Thanks.