I showed the solution - how to get the number of BUY positions and the number of SELL positions at once for all symbols in one function:
//+------------------------------------------------------------------+//| Calculate all positions Buy and Sell |//+------------------------------------------------------------------+void CalculateAllPositions(STRUCT_CALCULATE_POSITIONS &SCalculatePositions[])
{
ArrayFree(SCalculatePositions);
for(int i=PositionsTotal()-1; i>=0; i--)
if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
{
string pos_symbol=m_position.Symbol();
intsize=ArraySize(SCalculatePositions);
int find=false;
for(int j=0; j<size; j++)
{
if(SCalculatePositions[j].symbol==pos_symbol)
{
if(m_position.PositionType()==POSITION_TYPE_BUY)
SCalculatePositions[j].count_buys=SCalculatePositions[j].count_buys+1;
if(m_position.PositionType()==POSITION_TYPE_SELL)
SCalculatePositions[j].count_sells=SCalculatePositions[j].count_sells+1;
find=true;
break;
}
}
if(!find)
{
ArrayResize(SCalculatePositions,size+1);
SCalculatePositions[size].symbol=pos_symbol;
if(m_position.PositionType()==POSITION_TYPE_BUY)
SCalculatePositions[size].count_buys=SCalculatePositions[size].count_buys+1;
if(m_position.PositionType()==POSITION_TYPE_SELL)
SCalculatePositions[size].count_sells=SCalculatePositions[size].count_sells+1;
}
}
//---return;
}
In the j-loop you compare the symbols in the SCalculatePositions[] - Array with the position symbol and only if they are equal you check for Position-Type and start counting . However, what is the value of variablesizebefore you run into the j-loop? Where does SCalculatePositions[] get its values (symbols) from that size becomes > 0? Thanks in advance.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
An example for you: No more than N positions for each symbol Simple
I salute you Sir. You really are an asset to the MQL5 community. Thank you for your help and guidance.
I showed the solution - how to get the number of BUY positions and the number of SELL positions at once for all symbols in one function: