Trying to get a list of all pairs with at least one trade active - Can't stop an Array from being filled
...
Where am I doing wrong?
Any tips to think different?
Thanks in advance,
Francesco
Do what Mohammed says.
You may also consider the need for your array to be declared globalscope. The array will retain symbols for trades even after they have been closed.
Is that whet you want?
Don't subtract 1 from ArraySize of your both loop condition.
Thanks Muhammad. I've tried your suggestion, but I get "Array out of range error" now =(
Do what Mohammed says.
You may also consider the need for your array to be declared globalscope. The array will retain symbols for trades even after they have been closed.
Is that whet you want?
Thanks Keith. Keeping symbols in array after trades being closed is not my goas. I want them to be in this array as long as they have orders active on the symbol itself =)
Other hints to help me achieve that?
=)
Thanks Keith. Keeping symbols in array after trades being closed is not my goas. I want them to be in this array as long as they have orders active on the symbol itself =)
Other hints to help me achieve that?
=)
Not tested
//+------------------------------------------------------------------+ //| OrderSymbols.mq4 | //+------------------------------------------------------------------+ #property version "1.00" #property strict #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { EventSetTimer(1); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void OnTimer() { string arraySymbols[]; //Array containing list of Symbols DECLARED LOCALLY int as=0; //Variable to hold the array size for(int i = OrdersTotal()-1; i>=0; i--) //Loop through all the Orders { if(OrderSelect(i, SELECT_BY_POS) ) { string sym=OrderSymbol(); if (checkIFsymbolExists(arraySymbols,sym,as) == False) { as++; ArrayResize(arraySymbols,as); arraySymbols[as-1] = sym; } } } string str; for(int i=0; i<as; i++) { str+=arraySymbols[i]+" "; Print(str); } } //+------------------------------------------------------------------+ bool checkIFsymbolExists( string &SymbolsArray[], string passedSymbol, int as ) { for(int i =0; i < as; i++) { if( SymbolsArray[i] == passedSymbol ) { return(true); } } return( false ); } //+------------------------------------------------------------------+
Not tested
Thanks for the code Watford.
Adding this "as" simply solved the repeated symbols in the array, but it still loops from emptying to filling the array.
I've found this indicator that has that function inside. I'm Just trying to figure out where it's coded and get the logic :D
Thanks for the code Watford.
Adding this "as" simply solved the repeated symbols in the array, but it still loops from emptying to filling the array.
I've found this indicator that has that function inside. I'm Just trying to figure out where it's coded and get the logic :D
My name is Keith, my surname is Watford, please don't call me by my surname, it is not polite.
Using as did not solve the repeated symbols in the array. It saves the repeated calls to ArraySize().
Yes, it fills the array every time, that way you will only have symbols with open trades in the array.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi there,
I'm trying to get a list of all pairs with a trade active to finally make a table with a "marketwatch" (to show some stuff on a chart) dinamically adding and removing them from the list.
I think creating an array is the right way to go. So, this is my logic:
- loop into active trades
- get OrderSymbol()
- write symbol in an array
- check if this symbol already exists in the array (don't want duplicates)
- and finally end the loop.
On the terminal I see a print line with the right symbols, but they are repeated and the array seems to be in a loop being wiped and filled, wiped, filled (gradually) and then wiped again.
This is the code:
This is my output, and it loops very fast
Where am I doing wrong?
Any tips to think different?
Thanks in advance,
Francesco