Hi,
is there a possibility to write s.th. like this:
I tried even hi(string sym=NULL.. ) => compiler error: NULL is not a string, ok. So iHigh must convert NULL into a string which is not "0" :(
Thanks!
gooly
There you referred to https://docs.mql4.com/basis/types/casting
where you can read
string s = NULL; // the constant of type int is cast to the target type of string, the result is "0" (the string containing 1 character)
but this causes (now) a compiler error: 'NULL' - wrong initialization C:\Program Files (x86)...
If this were possible I should be able to write hi(string sym=NULL..
Still no idea to get rid of that line
if (sym=="" ) sym==Symbol();
Gooly
There you referred to https://docs.mql4.com/basis/types/casting
where you can read
but this causes (now) a compiler error: 'NULL' - wrong initialization C:\Program Files (x86)...
If this were possible I should be able to write hi(string sym=NULL..
Still no idea to get rid of that line
Did you look at the sample code I posted ?
Yes I looked at it but I don't want test equality or so, I tried my own code (see above) to find a solution to spare the stupid line, but nothing worked
double hi(sym=NULL,..){ // compiler Error double hi(sym="0",..){ hi() => EURUSD,M1: EURUSD: 0.00000 == 1.37045 double hi(sym="",..){ hi() => EURUSD,M1: EURUSD: 0.00000 == 1.37045 double hi(sym="",..){ hi(NULL) => EURUSD,M1: EURUSD: 0.00000 == 1.37045
Your code won't give me a solution either!
So is there a way to set hi(sym=??,.. in a way that I don't have to ask if(sym=="") sym=Symbol();
Gooly
Yes I looked at it but I don't want test equality or so, I tried my own code (see above) to find a solution to spare the stupid line, but nothing worked
Your code won't give me a solution either!
So is there a way to set hi(sym=??,.. in a way that I don't have to ask if(sym=="") sym=Symbol();
What is the problem doing . . .
if(sym == "") sym = Symbol();
Well, of course it is not a bug it more a question of elegance and a question of speed. If you back-test 10.000 variations a code that's only 1 second faster you spare almost 3 hours and that matters.
Most of the build in functions like iHigh() use default values like NULL for Symbol(), why can't I or better mustn't I initialize sym with the default value of the system?
The symbol is checked or set three times that way: 1) sym="", 2) if(sym=="") sym=Symbol() 3) iHigh(sym.. [ here again because it could be NULL]
gooly
Well, of course it is not a bug it more a question of elegance and a question of speed. If you back-test 10.000 variations a code that's only 1 second faster you spare almost 3 hours and that matters.
Most of the build in functions like iHigh() use default values like NULL for Symbol(), why can't I or better mustn't I initialize sym with the default value of the system?
The symbol is checked or set three times that way: 1) sym="", 2) if(sym=="") sym=Symbol() 3) iHigh(sym.. [ here again because it could be NULL]
gooly
OK, the solution is clear . . .
double hi(string sym, int per = 0, int bar = 0) { Print(Symbol(),": ",DoubleToStr(iHigh(sym, per, bar),Digits)," == ",DoubleToStr( iHigh(NULL, per, bar), Digits)); return( iHigh(sym,per,bar) ); }
. . . and always pass the symbol name when you call the function, it costs no CPU time and there is no if() check within the function . . .
How do you know the built in functions such as iHigh(), etc. don't use exactly the same technique as I suggested ? are they OK because you can't see how they are coded ?
- 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,
is there a possibility to write s.th. like this:
I tried even hi(string sym=NULL.. ) => compiler error: NULL is not a string, ok. So iHigh must convert NULL into a string which is not "0" :(
What would have been an appropriate initialization to spare that stupid line:Thanks!
gooly