Calculation of Average Daily Range  [SOLVED]

Questions about MultiCharts and user contributed studies.
cdickerm
Posts: 8
Joined: 11 Aug 2012
Has thanked: 4 times

Calculation of Average Daily Range

Postby cdickerm » 18 Aug 2012

Hi, I've read discussions on calculating average daily range for ## number of days using the "average" function as follows for the last 10, 20, etc. days:

Average(HighD(1), 30) - Average(LowD(1), 30)

As it turns out, when I print the ouput of the above code, I just get yesterday's daily range, NOT the average range of the last 30 days. Basically, the code above gives me the same thing as this: HighD(1) - LowD(1).

Can anyone offer a suggestion on the use of a function or strategy for simply getting the average (high minus low) of the last 30 days? I can't imagine that Multicharts doesn't have such a function. TrueRangeD and a few others have been mentioned, but the PowerLanguage editor doesn't highlite or recognize those as functions.

Thank you,
Carey

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Calculation of Average Daily Range

Postby virginiatrader » 18 Aug 2012

Carey:

If I understand correctly, you are looking for what I call the "simple daily range"and it's average over N-periods, rather than the "average true range" over N-periods, as calculated by Wilder and others.

I created two indicators, call "Simple Range ST" (short term) and "Simple Range LT" (long term). I may be doing it wrong, but the calculations fit my needs:

Simple Range ST -

Code: Select all

plot1 (xaverage(h-l,1));

plot2 (xaverage(h-l,5));

plot3 (xaverage(h-l,20));

plot4 (((xaverage(h-l,1)) + (xaverage(h-l,5)) + (xaverage(h-l,20)))/3);

Simple Range LT -

Code: Select all

plot1 (xaverage(h-l,65));

plot2 (xaverage(h-l,130));

plot3 (xaverage(h-l,260));

plot4 (((xaverage(h-l,65)) + (xaverage(h-l,130)) + (xaverage(h-l,260)))/3);

I use the different N-periods consistently across all tradables, since they correspond to trading windows, i.e., weeks, months, quarters, etc.

Finally, I plot a "composite" of the first three plots. I like to see the relationships between the values over time.

Hope this helps!

virginiatrader
Attachments
Treasury Note 5y.png
(144.2 KiB) Downloaded 1309 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Calculation of Average Daily Range

Postby TJ » 18 Aug 2012

Hi, I've read discussions on calculating average daily range for ## number of days using the "average" function as follows for the last 10, 20, etc. days:

Average(HighD(1), 30) - Average(LowD(1), 30)

As it turns out, when I print the ouput of the above code, I just get yesterday's daily range, NOT the average range of the last 30 days. Basically, the code above gives me the same thing as this: HighD(1) - LowD(1).

Can anyone offer a suggestion on the use of a function or strategy for simply getting the average (high minus low) of the last 30 days? I can't imagine that Multicharts doesn't have such a function. TrueRangeD and a few others have been mentioned, but the PowerLanguage editor doesn't highlite or recognize those as functions.

Thank you,
Carey
When you are doing an average,
you are to average the previous 30 bars, not 30 days.

See my answer to your same question in this thread:
viewtopic.php?f=1&t=9348&p=53137#p53137

cdickerm
Posts: 8
Joined: 11 Aug 2012
Has thanked: 4 times

Re: Calculation of Average Daily Range

Postby cdickerm » 19 Aug 2012

virginiatrader,

In your response, were using a similar format to using data1/data2 to accommodate multiple time frames? If so, would you please explain or show an example of how this is done in MC?

Thanks much,
Carey

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Calculation of Average Daily Range  [SOLVED]

Postby virginiatrader » 19 Aug 2012

Carey:

I do use multiple time frames, in my calculations for trade signals.

Data1 is the base chart of daily bars, and Data2 is the "inserted instrument" chart of weekly bars. I calculate my systems on parameters based on weekly bars, and the output is rendered on the daily bar of the week the signal occurs, and plots as the trade arrow.

You can insert another data stream of any time resolution that MC supports by going to the Menu Bar and clicking "Insert, Instrument", or by using the F5 key. From here, you can choose how you want to format the new instrument.

The procedure is the same for any indicators you apply. When you insert an indicator on a chart with more than one data stream, you can choose which instrument to base it on. In my case, even though my signals are formatted on the weekly data, the use of my indicators "Simple Range ST" and "Simple Range LT" are formatted on the daily data, since I use the values of the indicators to set my stop-loss points.

virginiatrader

cdickerm
Posts: 8
Joined: 11 Aug 2012
Has thanked: 4 times

Re: Calculation of Average Daily Range

Postby cdickerm » 20 Aug 2012

Virginiatrader,

Thanks for that explanation. I'll give that a try.
Is there a particular format for referencing "Data2" in the actual code that runs my signals? This is where I am unclear on this approach. I'll look at your attachment again to see if I can make sense of this aspect.

Thanks again,
Carey

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Calculation of Average Daily Range

Postby virginiatrader » 20 Aug 2012

Carey:

There is the need to reference to each data stream as necessary. I reference the "close of data2" for my calculations, because Data2 is my weekly data. This data gives me my buy and sell signals, based on the closes of the weekly bars. However, I reference Data1, the daily bars, using "close of data1" in the calculations for my stop-loss orders.

The MC Power Language syntax is "close of dataN"...N being the specific data stream, .e.g. 1, 2, etc. Make sure that there is NO space between the word "data" and the number of the stream you are referencing. It shoudl read "data1", "data2", etc.

Good trading!

virginiatrader

cdickerm
Posts: 8
Joined: 11 Aug 2012
Has thanked: 4 times

Re: Calculation of Average Daily Range

Postby cdickerm » 20 Aug 2012

Virginiatrader,

Thanks so much for taking the time to explain this process to me. In your last statement you say, "The MC Power Language syntax is "close of dataN"...N being the specific data stream, .e.g. 1, 2, etc." Does the "close of dataN" actually refer to closing prices on the bars of that timescale, be it daily, weekly, monthly, or is is purely the way MC handles the syntax? I ask this because in my case, I'll be calculating the average range (H - L) of the last 30 days, which of course is not the close of any data series.

Carey

User avatar
virginiatrader
Posts: 79
Joined: 05 May 2007
Location: Virginia
Has thanked: 5 times
Been thanked: 5 times

Re: Calculation of Average Daily Range

Postby virginiatrader » 21 Aug 2012

Carey:

Correct. The "close of dataN" refers to the time frame of the data stream. The reference to "dataN" allows any indicator or system making that reference to calculate on that data.

virginiatrader


Return to “MultiCharts”