I Want to count how many open buy and sell positions do i have using mql5 - page 2 12 New comment Pratyush Sharma 2022.08.05 06:54 #11 R4tna C #: If that is not clear, comment out the line and you will see the numbers increase with every tick Search the forum for tutorials in MQL5. ... perfect sir... now i'm getting a little bit idea how its working.. .. R4tna C #: _MAHA_ #: thank you..sir I Want to count how many open buy and sell positions do i have using mql5 2022.08.02 www.mql5.com Hey i'm new here.. can you please help me to count the no... Dominik Patrick Doser 2023.06.22 12:13 #12 Pratyush Sharma: Hey i'm new here.. can you please help me to count the no. of positions do i have open, and in which how many there are buy positions and sell , i need mql5 code. like.. totol open positions = 5 buy = 3 sell = 2 thank you. //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int countLongPositions(int magic) { int counterBuy = 0; for(int i = PositionsTotal() - 1; i>=0; i--) { string symbol = PositionGetSymbol(i); int PositionMagicNumber = (int)PositionGetInteger(POSITION_MAGIC); //Comment(symbol) ; if(PositionMagicNumber == magic && _Symbol==symbol) { long pos_type =(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); if(pos_type == 0) // 0 = buy; 1 = sell { counterBuy = counterBuy +1; } } } return counterBuy; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int countShortPositions(int magic) { int counterSell = 0; for(int i = PositionsTotal() - 1; i>=0; i--) { string symbol = PositionGetSymbol(i); int PositionMagicNumber = (int)PositionGetInteger(POSITION_MAGIC); //Comment(symbol) ; if(PositionMagicNumber == magic && _Symbol==symbol) { long pos_type =(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); if(pos_type == 1) // 0 = buy; 1 = sell { counterSell = counterSell +1; } } } return counterSell; } To get the overall position count, just add them both up. 12 New comment
R4tna C #:
If that is not clear, comment out the line and you will see the numbers increase with every tick
Search the forum for tutorials in MQL5. ...
perfect sir... now i'm getting a little bit idea how its working.. ..
R4tna C #:
_MAHA_ #:
thank you..sir
Hey i'm new here.. can you please help me to count the no. of positions do i have open, and in which how many there are buy positions and sell ,
i need mql5 code.
like..
totol open positions = 5
buy = 3
sell = 2
thank you.
To get the overall position count, just add them both up.