Your variable "number" has an undefined initial value and there is no guarantee that the following line is actually assigning it anything.
if(StringFind(assetlist,",")<0) number = SymbolsTotal(selected);
Instead, if you want to debug it, then have the following line somewhere (untested, simply typed):
EDIT: Also, I fail to understand the purpose of your sample code in terms of what you are trying to achieve with it.PrintFormat( "Symbols — Total: %d, Selected: %d", SymbolsTotal( false ), SymbolsTotal( true ) );
Your variable "number" has an undefined initial value and there is no guarantee that the following line is actually assigning it anything.
Instead, if you want to debug it, then have the following line somewhere (untested, simply typed):
EDIT: Also, I fail to understand the purpose of your sample code in terms of what you are trying to achieve with it.Thank you Fernando
So I was trying to simplify the problem and spare you the following. It is part of an include file which handles 4 possible inputs for the symbols to trade in a multi asset EA.
The 4 possible strings to be handled for assetlist are 'CHART', 'SELECTED', 'ALL', or a comma separated list eg. 'EURUSD,USDJPY'
The outcome is to populate the assets[] array which is available for any EA to then loop through in OnTick().
The complete function is (assets[] having been previously declared):
bool listDefine() { //--- int number = 0; //assets=="ALL"?all:assets=="SELECTED"?selected:list; if(assetlist=="CHART") { ArrayResize(assets,1); assets[0] = _Symbol; return(true); } Print("assetlist = ",assetlist); bool selected = assetlist == "SELECTED"?true:false; Print("selected = ",selected); if(StringFind(assetlist,",")<0) number = SymbolsTotal(selected); Print(StringFind(assetlist,",")); Print("Number = ",number); if(number==0) { string result[]; string sep=","; // A separator as a character ushort u_sep; // The code of the separator character //string result[]; // An array to get strings //--- Get the separator code u_sep=StringGetCharacter(sep,0); //--- Split the string to substrings int k=StringSplit(assetlist,u_sep,result); //assets = result; //--- Now output all obtained strings if(k>0) { for(int i=0;i<k;i++) { string s = result[i]; bool c = false; if(!SymbolExist(s,c)) continue; int z = ArraySize(assets); ArrayResize(assets,z+1); assets[z] = result[i]; } } return(true); } if(assetlist!="SELECTED"&&assetlist!="ALL") { functionLocation=StringFormat("File = %s; Function = %s; routine starts at line #%s.",__FILE__,__FUNCTION__,__LINE__);//Error trapping return(false); } ArrayResize(assets,number); for(int i=0;i<number;i++) { assets[i] = SymbolName(i,selected); Print("Asset ",i," = ",assets[i]); } return(true); }
so number starts off as 0.
Then if assetlist=='CHART' the asset[] resized to 1 and asset[0] assigned _Symbol, returns.
The snippet I posted comes next where number is to be reassigned according to SymbolsTotal, if(StringFind(assetlist,",")<0)
This is where it is malfunctioning in Backtesteronly!!
The crazy thing is my unmodified code works in forward testing as I just found after further research and finding a report from 2010 regarding different behaviour in Backtester and Forward Trading. I got the following log file entries in Forward mode to show I am not crazy!! -
Sooo... any more preferably helpful ideas?CS 0 18:55:22.356 ea2TB (EURUSD,M1) assetlist = SELECTED
CS 0 18:55:22.356 ea2TB (EURUSD,M1) selected = true
CS 0 18:55:22.356 ea2TB (EURUSD,M1) -1
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Number = 29
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Asset 0 = EURUSD
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Asset 1 = GBPUSD
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Asset 2 = USDCHF
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Asset 3 = USDJPY
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Asset 4 = AUDCAD
CS 0 18:55:22.356 ea2TB (EURUSD,M1) Asset 5 = AUDCHF
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 6 = AUDJPY
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 7 = AUDNZD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 8 = AUDUSD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 9 = CADCHF
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 10 = CADJPY
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 11 = CHFJPY
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 12 = EURAUD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 13 = EURCAD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 14 = EURGBP
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 15 = EURJPY
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 16 = EURNZD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 17 = GBPAUD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 18 = GBPCAD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 19 = GBPCHF
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 20 = GBPJPY
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 21 = GBPNZD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 22 = NZDCAD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 23 = NZDCHF
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 24 = NZDJPY
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 25 = NZDUSD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 26 = USDCAD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 27 = EURCHF
CS 0 18:55:22.357 ea2TB (EURUSD,M1) Asset 28 = XAUUSD
CS 0 18:55:22.357 ea2TB (EURUSD,M1) [ 0] "EURUSD" "GBPUSD" "USDCHF" "USDJPY" "AUDCAD" "AUDCHF" "AUDJPY" "AUDNZD" "AUDUSD" "CADCHF" "CADJPY" "CHFJPY" "EURAUD" "EURCAD" "EURGBP"
CS 0 18:55:22.357 ea2TB (EURUSD,M1) [15] "EURJPY" "EURNZD" "GBPAUD" "GBPCAD" "GBPCHF" "GBPJPY" "GBPNZD" "NZDCAD" "NZDCHF" "NZDJPY" "NZDUSD" "USDCAD" "EURCHF" "XAUUSD"

- 2010.09.24
- www.mql5.com
Hi ,
I saw that, but not being able to see this mythical shadow MarketWatch nor use sets with it is very annoying!!
EDIT: And yeah... I know... RTFM, but I am not normally one to get caught out with that, hell, I even bought a PC in the late 90s from a computer manufacturer in UK called RTM!!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
So here is part of my program, in a function designed to loop through all the Symbols in Market Watch:
and here is the output in the log:
But there are 29 symbols in Market Watch:
So number should == 29
Where am I going wrong?