I have also tried this but even though it compiles ok the EA stops working:
double Atr(int shift){ double res;{ if(Period() >= PERIOD_M30){return (res == iATR(Symbol(),Period(),AtrPeriod2,shift));} if(Period() < PERIOD_M30){return (res == iATR(Symbol(),Period(),AtrPeriod,shift));} } if(Digits == 4){return(NormalizeDouble(res,4));} }
Thanks
Antony
You have several coding errors, but you have tried! Maybe try something like
double Atr(int shift){ double res; int theAtrPeriod; if(Period() >= PERIOD_M30) theAtrPeriod = AtrPeriod2; else theAtrPeriod = AtrPeriod; res = iATR(Symbol(),Period(),theAtrPeriod,shift); return(NormalizeDouble(res,Digits)); // want you want but I don't recommend return(res); // what I suggest, but hey, it's your EA! }
Note:
1) this is just copied/typed, not compiled or tested
2) choose which of the two 'return' lines you want - without change it does what you implied you wanted
*edit* fix theAtrPeriod typo
Hi
Thank you for your help you have been most helpful.
Thanks
Antony
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
Hello
I am working on an EA that uses ATR.
On a timeframe of 30min and higher I use ATR 14
On a timeframe of less than 30min I use ATR 10
I new to coding and have been trying something like this:
But with little success, can anyone give me any help with this please?
There is also the case of dealing with the variable:
Thanks
Antony