Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@ class CPositionInfoCustom : public CPositionInfo {

public:
int Total() { return ( OrdersTotal() ); }
int Count( const string symbol, int magic_number );
};

int CPositionInfo::Count(string symbol, int magic_number)
{
int positionCount = 0; // Counter for positions

// Loop through all open orders
for(int i = OrdersTotal() - 1; i >= 0; i--)
{
// Select order by position
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
// Check if order matches symbol and magic number
if(OrderSymbol() == symbol && OrderMagicNumber() == magic_number)
{
positionCount++;
}
}
}

return(positionCount);
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,25 @@ class CPositionInfoCustom : public CPositionInfo {

public:
int Total() { return ( PositionsTotal() ); }
int Count( const string symbol, int magic_number );
};

int CPositionInfoCustom::Count( const string symbol, int magic_number ) {
CPositionInfo positionInfo; // Create an instance of CPositionInfo
int positionCount = 0; // Counter for positions on the current symbol
// Loop through all open positions
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
// Select position by index
ulong ticket = PositionGetTicket(i);
if(positionInfo.SelectByTicket(ticket))
{
// Check if the position is for the current symbol
if(positionInfo.Symbol() == symbol && positionInfo.Magic() == magic_number)
{
positionCount++;
}
}
}
return (positionCount);
};