Hmm, that's kinda interesting. From the values you posted, it looks like the ATR indicator rounds it's values when it's on the chart. This code should shift the decimal over, Round the ATR, then shift the decimal back.
double mult=MathPow(10,MarketInfo(Symbol(),MODE_DIGITS)) ATR_Buffer[i]=MathRound(iATR(NULL,0,14,i)*mult)/mult;
Regards,
Loren
Well Loren, rounding is not the problem here ...
The real problem is the value of MA of ATR indicator on chart and the same MA calculated in EA are completely different.
2005.08.02 18:19:50 Test EURUSD,H1: tmp[1] = 0.00153067 // WHICH IS INCORRECT
2005.08.02 18:19:50 Test EURUSD,H1: ATR_Buffer[1] = 0.00218571 // WHICH IS RIGHT
Simon
The real problem is the value of MA of ATR indicator on chart and the same MA calculated in EA are completely different.
2005.08.02 18:19:50 Test EURUSD,H1: tmp[1] = 0.00153067 // WHICH IS INCORRECT
2005.08.02 18:19:50 Test EURUSD,H1: ATR_Buffer[1] = 0.00218571 // WHICH IS RIGHT
Simon
Hmm, that's kinda interesting. From the values you posted, it looks like the ATR indicator rounds it's values when it's on the chart. This code should shift the decimal over, Round the ATR, then shift the decimal back.
double mult=MathPow(10,MarketInfo(Symbol(),MODE_DIGITS)) ATR_Buffer[i]=MathRound(iATR(NULL,0,14,i)*mult)/mult;
Regards,
Loren
Simi,
I hear you, but one of us is misunderstanding the other. Did you try my code? If so, disregard.
Otherwise, let me explain again. If ATR on the chart is rounded, and the MA of the ATR uses the rounded values, then of course the MA on the chart looks different than the MA from your EA.
4. Compare values:
- in Data window I get for 2005-08-02 17:00: ATR = 0.0022, MA = 0.0020
- when I use the code suggested tfor calculating MA with iMAonArray function (post #177), I get
2005.08.02 18:19:50 Test EURUSD,H1: tmp[1] = 0.00153067 // WHICH IS INCORRECT
2005.08.02 18:19:50 Test EURUSD,H1: ATR_Buffer[1] = 0.00218571 // WHICH IS RIGHT
2005.08.02 18:19:50 Test EURUSD,H1: iTime(NULL, 0, 2) = 2005.08.02 17:00
I say this because your ATR value from the chart is 0.0022, and the ATR value from the EA is 0.00218571. Which of those values gets passed to the MA function when you drop it on the ATR indicator? In your expert, I'd be pretty sure it's definitely the unrounded value. But on the chart??? Who knows? It could be the rounded value, which could account for the differences you see. So my idea was to try rounding the values within your expert and see if they agree with the values on the chart.
Regards,
Loren
I hear you, but one of us is misunderstanding the other. Did you try my code? If so, disregard.
Otherwise, let me explain again. If ATR on the chart is rounded, and the MA of the ATR uses the rounded values, then of course the MA on the chart looks different than the MA from your EA.
4. Compare values:
- in Data window I get for 2005-08-02 17:00: ATR = 0.0022, MA = 0.0020
- when I use the code suggested tfor calculating MA with iMAonArray function (post #177), I get
2005.08.02 18:19:50 Test EURUSD,H1: tmp[1] = 0.00153067 // WHICH IS INCORRECT
2005.08.02 18:19:50 Test EURUSD,H1: ATR_Buffer[1] = 0.00218571 // WHICH IS RIGHT
2005.08.02 18:19:50 Test EURUSD,H1: iTime(NULL, 0, 2) = 2005.08.02 17:00
I say this because your ATR value from the chart is 0.0022, and the ATR value from the EA is 0.00218571. Which of those values gets passed to the MA function when you drop it on the ATR indicator? In your expert, I'd be pretty sure it's definitely the unrounded value. But on the chart??? Who knows? It could be the rounded value, which could account for the differences you see. So my idea was to try rounding the values within your expert and see if they agree with the values on the chart.
Regards,
Loren
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Detailed step-by-step:
1. Open new chart eurusd 1h
2. Add Average True Range indicator with default parameters (14)
3. Drag and drop Moving Average indicator on ATR windows with parameters: Period=21, MA Method: linear weighted, Apply to: Previous indicator data
4. Compare values:
- in Data window I get for 2005-08-02 17:00: ATR = 0.0022, MA = 0.0020
- when I use the code suggested tfor calculating MA with iMAonArray function (post #177), I get
2005.08.02 18:19:50 Test EURUSD,H1: tmp[1] = 0.00153067 // WHICH IS INCORRECT
2005.08.02 18:19:50 Test EURUSD,H1: ATR_Buffer[1] = 0.00218571 // WHICH IS RIGHT
2005.08.02 18:19:50 Test EURUSD,H1: iTime(NULL, 0, 2) = 2005.08.02 17:00
The test code is below.Anyone has a good knowledge as to how iMAonArray is implemented ?
Rgrds
Simon