Easier than I thought, for anyone curious:
double adr[]; int period=2; //Number of days to analyse (must run the indicator on TF<=60m) Alert(""); Alert(""); Alert("------"); ArrayResize(adr,10*period); //10 hours a day to be averaged times the numbers of days int array_index; for(int i=1;i<24*period+1;i++){ // 24 1H candles to go trough times the numbers of chosen days if(TimeHour(iTime(0,60,i))>=8&&TimeHour(iTime(0,60,i))<18) //If index time is between desidered hour range then fill array with TR values of 1H candles { Alert(""); Alert(iTime(0,60,i)); Alert("High: "+iHigh(0,60,i)); Alert("Low: "+iLow(0,60,i)); adr[array_index] = iHigh(0,60,i) - iLow(0,60,i); Alert("Index n. "+array_index+" ATR: "+adr[array_index]); array_index++; }
From there it's quite easy to find an average of all array values.
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
Hi everyone, I'm still a noob so please excuse errors.
I'm trying to calculate ATR of 1H based only on certain candles defined by input. For example if input are 8,18 and 10, then the code will calculate the true range of all 1H candles from 08:00 AM to 18:00 AM in the last 10 days and then it will calculate the average of all stored values.
What I tried to do was:
This is how far I got and apparently no values are getting stored inside the array or the code actually stop working because if I try to put the atr_Array inside an alert nothing happen and no values are being displayed. Can someone please point me out my errors? Thanks.