I doubt this to be the most elegant way to do this,... but here is a solution that works:
void PairNamesOpenedPos(string& PairNams[]) { int total=0; int nPositions=PositionsTotal(); //n Total open positons ulong position_ticket; string CurrentSymbol; string msymbols=""; for(int i=0; i<nPositions; i++) { position_ticket = PositionGetTicket(i); CurrentSymbol = PositionGetString(POSITION_SYMBOL) ; if( 0>StringFind(msymbols,CurrentSymbol) ) { msymbols += CurrentSymbol+";"; ArrayResize(PairNams,total+1); PairNams[total]=CurrentSymbol; total ++; } } }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am developing a function to create a list of unique pairs with open positions. Say USDJPY has a long and short position and GBPJPY has a long positions, the result should be "USDJPY" and "GBPJPY". For this I create an empty array to store the names. First I loop through all open positions, then for the symbol, i loop trhough the list of names, and if the symbol is not new, keep going, if new, add it to the list. The code is below.. However, for some reason I am getting all pairs names of all pairs (duplicated) with opened positions... what I am doing wrong?