How to count pairs in basket MQL5
Thank you Fabio
have you got an example of code on which I can work?
Unfortunately not, but if you have some basic coding skills, will be very easy. It will be something like this. (Code not compiled and not tested)
string TradedSymbols[]; void CountSymbols() { ArrayFree(TradedSymbols); for( int i=PositionsTotal()-1; i>=0; i-- ) { if( !m_position.SelectByIndex(i) ) continue; if( ArrayFind(TradedSymbols,m_position.Symbol()) == -1 ) { ArrayResize(TradedSymbols,ArraySize(TradedSymbols)+1); TradedSymbols[ArraySize(TradedSymbols)]-1] = m_position.Symbol(); } } } int ArrayFind(string &array, string item) { for( int i=0; i<ArraySize(array); i++ ) if( item == array[i] ) return i; return -1; }
Then, in your OnTick call the "CountSymbols". After that call, the array size = the amount of traded symbols. Of course if you already have a cycle through all positions, will be more effective to add the part into your existing cycle instead of creating a new one.
Thanks Fabio you were very kind!
Have a great Sunday!
Hi i need to count how many pairs has opened positions on my account. It can happend that one pair has more than 1 trade open and in that case must be counted one time only.
Thank you