Script to calculate Average Daily Range?

 

Hi,

anyone have a script that will calculate the average daily range of a currency going back "n" days?

e.g. for 50 days

 

I'd like to see this also....

 

isn't it ATR indicator?

 

so if I wanted to see it for the last 50 days I would just look at the last bar's value for the ATR(50)?

 

Ycomp, what do you mean by daily range?

What do you mean by daily range? (High-Low)?

ATR is the average true range for the last n periods. The true range however, is not the High-Low for every day. True range is the maximum value of the following 3:

1.CurrentHigh-CurrentLow

2.Abs(PreviousClose-CurrentHigh)

3.Abs(PreviousClose-CurrentLow)

I hope you understand. Now, please tell me what exactly do you mean by the average daily range.

Bye.

 

#MTF_Average Range

I've attached #MTF_Average Range.mq4

It will give you the average range (high-low) for whatever period it is attached to. If you want the see the average range of a different timeframe, change the TimeFrame input to whatever timeframe you want. (1,5,15,30,60,240,1440,10080,43200)

The TimeFrame value must be greater than the current timeframe.

keris

BTW, unlike other MTF versions of custom indicators I've done, all the code is incorporated in this one file.

Files:
 

thanks keris I think this is what I was looking for... plus a bit more!

 

thanks for the explanation cucurucu.. now I understand better. I was just looking for High-Low.

cucurucu:
What do you mean by daily range? (High-Low)?

ATR is the average true range for the last n periods. The true range however, is not the High-Low for every day. True range is the maximum value of the following 3:

1.CurrentHigh-CurrentLow

2.Abs(PreviousClose-CurrentHigh)

3.Abs(PreviousClose-CurrentLow)

I hope you understand. Now, please tell me what exactly do you mean by the average daily range.

Bye.
 

Here is a simple script to do what you are wanting.

Files:
 

script

Hi Nic,

Appreciate your work.

Nicholishen:
Here is a simple script to do what you are wanting.

I think there is 1 error in this script:

for (int i=0;i<=PeriodsBack;i++)

must be:

for (int i=0;i<PeriodsBack;i++)

In your example it will go 11 times through the for loop

 
nohills:
Hi Nic,

Appreciate your work.

I think there is 1 error in this script:

for (int i=0;i<=PeriodsBack;i++)

must be:

for (int i=0;i<PeriodsBack;i++)

In your example it will go 11 times through the for loop

Thanks for the catch nohills. What i meant to do was:

for (int i=1;i<=PeriodsBack;i++)

I didn't want to take the current bar into calculation. Thanks!

Reason: