Have some code that checks MA crossovers. I discovered that I only got one type (I think it was positive cross overs) but not the other one
Changed the code and it works ok
Have some code that checks MA crossovers. I discovered that I only got one type (I think it was positive cross overs) but not the other one
Changed the code and it works ok

- www.mql5.com
The code I have given above as "working" is not good.
I still found some inconcistencies in behavior so I made the following changes to the code.
Result:
Consistent behavior, a lot better results
double mult = 10000; w1 = ShrtMA[1] * mult; w2 = LongMA[1] * mult; if(w1 > w2) result = 1; if(w1 < w2) result = -1;
I had similar problems in C++. In some cases comparing double value with 0 gave incorrect result. However, comparing with 0.0 was working fine and as expected.
I have no idea how mql5 compiler interprets code, but try this:
double last = ShrtMA[1] - LongMA[1]; if(last>0.0) result = 1; if(last<0.0) result -1;Share results please, I am really interested about result of this in mql5.
I had similar problems in C++. In some cases comparing double value with 0 gave incorrect result. However, comparing with 0.0 was working fine and as expected.
I have no idea how mql5 compiler interprets code, but try this:
Share results please, I am really interested about result of this in mql5.Out of curiosity, how would you code it??
double epsilon=_Point/2.; if(ShrtMA[1]-LongMA[1] > epsilon) result = 1; if(LongMA[1]-ShrtMA[1] > epsilon) result = -1;
Thanks. Interesting. One thing. You divide by 2. Is that a typo or or does the decimal point signify something?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Have some code that checks MA crossovers. I discovered that I only got one type (I think it was positive cross overs) but not the other one
Changed the code and it works ok