Hi, I'm stuck trying to display a particular value according to the currnt chart's symbol using Comment. Basically if I load this indicator up in GBPUSD, it would display the 1 value at the top left, if I had EURUSD chart open, it would display 2, etc.
It's not the most efficient code but here is what I have so far. Should I just start over again? If so, any hints as to which keyword I should be investigating?
Many errors occur during compiling, mostly with this part.
if(CurrentSymbol="GBPUSD")
'=' - illegal assignment used C:\Program Files (x86)\MetaTrader - SVSFX Demo\experts\indicators\SymbolDetection.mq4 (42, 17)
'GBPUSD' - unexpected token C:\Program Files (x86)\MetaTrader - SVSFX Demo\experts\indicators\SymbolDetection.mq4 (42, 18)
')' - assignment expected C:\Program Files (x86)\MetaTrader - SVSFX Demo\experts\indicators\SymbolDetection.mq4 (42, 25)
Not sure how to interpret these errors yet.
I also tried without the " " around GBPUSD, etc. as below:
double GU=1; double EU=2; double AU=3; string CurrentSymbol=Symbol(); if(CurrentSymbol=GBPUSD) {Comment("Your current symbol is ",Symbol()," and its assigned floating point value is ",DoubleToStr(GU,0));} if(CurrentSymbol=EURUSD) {Comment("Your current symbol is ",Symbol()," and its assigned floating point value is ",DoubleToStr(EU,0));} if(CurrentSymbol=AUDUSD) {Comment("Your current symbol is ",Symbol()," and its assigned floating point value is ",DoubleToStr(AU,0));}
I get the following errors:
'GBPUSD' - variable not defined C:\Program Files (x86)\MetaTrader - SVSFX Demo\experts\indicators\SymbolDetection.mq4 (42, 18)
'EURUSD' - variable not defined C:\Program Files (x86)\MetaTrader - SVSFX Demo\experts\indicators\SymbolDetection.mq4 (43, 18)
'AUDUSD' - variable not defined C:\Program Files (x86)\MetaTrader - SVSFX Demo\experts\indicators\SymbolDetection.mq4 (44, 18)
lol, i just figured it out, i need two == signs. It's pretty cool that you told me my code was pretty much on the right track in the first place so thank you :)
You could have mentioned that it didn't even compile . . . doh ! ;-)
I'll remember that the next time, hehe.
Back to coding, hopefully I won't have any trouble for a few more days.
Yes. Morover.
Constant GBPUSD must be declared prior to its first use:
#define GBPUSD "GBPUSD"
You do not need to cast an integer to a string using DoubleToStr(int,0), it is its default. Using the double makes it complicated.
I'll bear #define in mind because it looks like it could be useful in future. I use double because there are going to be more calculations to determine a final value (i.e. a lot size tailored for each pair) prior to it being displayed as a Comment. So far double is the only way I know - I'm sure there are other ways to do the same thing and I will probably find them in future as I learn more. Cheers.
#define GU 1 #define EU 2 #define AU 3 double pairs.values[] = {GU, EU, AU }; string pairs.names[] = {"GPBUSD", "EURUSD", "AUDUSD"}; for(int iPair=ArraySize(values)-1, iPair >= 0; iPair--) if( pairs.names[iPair] == Symbol()){ Comment( "Your current symbol is ", Symbol(), " and its assigned value is ", pairs.values[iPair]); } if(iPair < 0) Comment(Symbol()," is not supported");

- 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, I'm stuck trying to display a particular value according to the currnt chart's symbol using Comment. Basically if I load this indicator up in GBPUSD, it would display the 1 value at the top left, if I had EURUSD chart open, it would display 2, etc.
It's not the most efficient code but here is what I have so far. Should I just start over again? If so, any hints as to which keyword I should be investigating?