if(!GlobalVariableCheck(gvName)){ Comment("You forgot to to set indicator ATR"); res = iATR(Symbol(),Period(),theAtrPeriod,shift); return(NormalizeDouble(res,Digits));}
your the the iATR value only when GlobalVariableCheck==false.
BTw, why using such a complicated way trough Globalvariables?
Hi
I find the iATR can be slightly inaccurate, and this causes my EA to miss around 3-4 valid trades per weeks, for example the Atr indicator may show 0.0022 and the iAtr will show it as 0.0023, this doesn't seem like a lot but in my strategy it makes all the difference.
So I would like the EA to read data from the Atr idicator attached to the chart, if I forget to add the indicator then the EA can resort back to iATR is back up.
But right now when using the Atr idicator with the EA, it just returns 0.0000 and then 0.0001 for the previous candle.
Thanks
Antony
It seems that in this function you never read the value from the custom indicator. I don't see a GlobalVariableGet() anywhere. And you never set the shift value to the global variable. (note that the indicator will update only at the next tick AFTER the variables have been set)
Also the "normal" way would be to get the custom indicator value trough the iCustom() function, this has also the advantage that you don't need to manually add the indicator.
Another even better solution is to calculate the Atr value inside the EA, if you know the math and don't need a visual drawing this might be the best solution of all.
Hi
I will have to look into this as I am new to coding, many things are still beyond my knowledge, and any examples will be very helpful.
Thanks
Antony
I have read quickly trough your modified ATR and the standart ATR, the calculations is the same, i assume you copy'ed from there. What modifications have you made in order to be more reliable as you said?
Hi
The Atr idicator is just the standard one that comes with metatrader, the calculations are the same but it seems they round off different, please see image:
You can see the difference.
Thanks
Antony
i don't see any rounding operations in any of the indicators, try printing the values with DoubleToStr(value,5);
Also i can't see the code in your indicator which is responsible for printing the values in your indicator window...
Hi
This is the code I use in the EA for displaying the values:
string d_str(double in){return(DoubleToStr(in,Digits+1));}
Then for the Atr vales etc, I use this:
comm=comm+"\nCurrent Rsi: "+d_str(Rsi(0))+" "; comm=comm+"\nPrevious Rsi: "+d_str(Rsi(0+1))+" "; comm=comm+"\nCurrent Macd main: "+d_str(Macd(0,0))+" Signal: "+d_str(Macd(0,1))+""; comm=comm+"\nPrevious Macd main: "+d_str(Macd(0+1,0))+ " Signal: "+d_str(Macd(0+1,1))+" "; comm=comm+"\nCurrent Atr: "+d_str(Atr(0))+" "; comm=comm+"\nPrevious Atr: "+d_str(Atr(0+1))+" ";
Because I use this EA accross many pairs, to get the correct readings by using the Digits+1
At the point shown in the attached image, I traded that pattern manually and, it was a valid trade, but because of issue with the Atr the EA completely missed it. This has been apparent for a few recent trades.
For a while I found just dividing the iAtr by 1.0000000046511560159, corrected the issue on most trades, but there is still a difference, not a lot as you can see by the number but enough to cause major problems for my EA.
As i have traded manually for some time I know that the Standard Atr indicator is correct and the EA is incorrect, this is why I would prefer my EA to read from the standard Atr.
The previous bars shown is just a mod I did to aid manual trading.
Thanks
Antony
- 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 have an EA that uses ATR, because it relies on accuracy I found using the indicator to provide the values is best so here is the code in the EA:
And here is the modified ATR indicator:
The problem is that I am getting an ATR value of 0.0000 for the current and then 1.0000 for the previous candle.
Can anyone suggest what is causing this?
Thanks
Antony