I'm putting the final pieces of my code together and I have studied a course on for loops. NOTE: I am a beginner.
I created an indicator successfully and I wish to make the indicator run on all the symbols in my market watch automatically. However, I can't seem to figure out the logic behind this. You don't have to share any codes. Just want to understand the logic so that I can try automating it.
This is the line of code I have been trying to manipulate but it honestly doesn't make sense to me. Where do I input the parameters of my indicator? How can I make the loop end? Please assist
Thanks in advance.
for ( int i= 0 ; i< SymbolsTotal ( 1 ); i++) {
Print ( "SYMBOL: ", SymbolName (i, 1 ), " Found At: ",i);
}
this code means - you are selecting all marketwatch symbols where SymbolsTotal is total number of symbols selected in marketwatch
SymbolName
is the name of the symbol selected in marketwatch
so lets say you want to check the high price of all symbol then you can do as follow
for ( int i= 0 ; i< SymbolsTotal ( 1 ); i++) {
Print ( "SYMBOL: ", SymbolName (i, true ), " Found At: ",i);
double h[];
string symbolsList[];
ArrayResize (h, SymbolsTotal ( true ));
ArrayResize (symbolsList, SymbolsTotal ( true ));
h[i] = iHigh (symbolsList[i], PERIOD_M1, 0 );
Print ( "#" + string (i)+ " Symbol " + symbolsList[i] + " High ; "+ h[i]);
}
code is not tested / compliled.
this code means - you are selecting all marketwatch symbols where SymbolsTotal is total number of symbols selected in marketwatch
is the name of the symbol selected in marketwatch
so lets say you want to check the high price of all symbol then you can do as follow
code is not tested / compliled.
Excellent explanation Rajesh Kumar Nait #:
I have now created the code. Just a tiny problem left to solve. The close price is not being updated as the indicator goes through all the charts. Sigh.
//---code from Rajesh Kumar Nait----to loop for all symbols for (int i=0; i<SymbolsTotal(1); i++) { MqlRates PriceInformation []; // defines closePrice. Source: https://www.youtube.com/watch?v=H10QFIZoUYA ArraySetAsSeries(PriceInformation,true); int Data=CopyRates(Symbol(),PERIOD_D1,0,Bars(Symbol(),PERIOD_D1),PriceInformation); double closePrice = PriceInformation[0].close; string symbolsList[]; ArrayResize (ema_10, SymbolsTotal ( true )); ArrayResize (symbolsList, SymbolsTotal ( true )); if ((ema_10[0])>=((closePrice)-0.10) && (ema_10[0])<= ((closePrice)+0.10)) Print("SYMBOL: ",SymbolName(i,1)," Found At: ", +closePrice ); else Print ("Not here", "SYMBOL: ",SymbolName(i,1), +closePrice); }
I attached the updated code and the output I got below. Please anyone.
Notice how the close prices are the same? This makes me not have a valid output for the rest of the pairs
Excellent explanation Rajesh Kumar Nait #:
I have now created the code. Just a tiny problem left to solve. The close price is not being updated as the indicator goes through all the charts. Sigh.
I attached the updated code and the output I got below. Please anyone.
I think I found at least one mistake, see the definition of Symbol():
https://www.mql5.com/en/docs/check/symbol
It will always return the name of the symbol of the chart you're working with, and I don't think that's what you want. Maybe you just forgot to change it in the CopyRates line. Try SymbolName(i,1) instead, like in the rest of your code.
- www.mql5.com
I think I found at least one mistake, see the definition of Symbol():
https://www.mql5.com/en/docs/check/symbol
It will always return the name of the symbol of the chart you're working with, and I don't think that's what you want. Maybe you just forgot to change it in the CopyRates line. Try SymbolName(i,1) instead, like in the rest of your code.
Thank you so much @Jeepack. Your explanation of how and why the code works is incredible. I have successfully created the indicator and I'm really grateful for your help.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm putting the final pieces of my code together and I have studied a course on for loops. NOTE: I am a beginner.
I created an indicator successfully and I wish to make the indicator run on all the symbols in my market watch automatically. However, I can't seem to figure out the logic behind this. You don't have to share any codes. Just want to understand the logic so that I can try automating it.
This is the line of code I have been trying to manipulate but it honestly doesn't make sense to me. Where do I input the parameters of my indicator? How can I make the loop end? Please assist
Thanks in advance.