Daily Average True range  [SOLVED]

Questions about MultiCharts and user contributed studies.
waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Daily Average True range

Postby waveslider » 19 Oct 2011

Hello, my first post - glad to be a TS convert!

I am moving over a function called "avgtrueranged(30)" and it is not outputting properly. The function returns the avg. true range of the daily bar (in this case for the past 30 days). There are 4 parts to the function.

Does anyone have a use-able function that will perform this task?

thanks,

ws

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

Re: Daily Average True range

Postby TJ » 19 Oct 2011

Hello, my first post - glad to be a TS convert!

I am moving over a function called "avgtrueranged(30)" and it is not outputting properly. The function returns the avg. true range of the daily bar (in this case for the past 30 days). There are 4 parts to the function.

Does anyone have a use-able function that will perform this task?

thanks,

ws
What do you mean by "it is not outputting properly"?
Can you describe the error?

What are the 4 parts you are referring to?

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Daily Average True range

Postby waveslider » 19 Oct 2011

Thanks for the reply

The output (to a file using print statements) goes into negative numbers, average true range should always be positive of course.

The function I have calls "truehighd","truelowd",and "trueranged" functions.

The .eld file is attached which contains these.
Attachments
2003923123516_AvgTrueRangeDaily.eld
avg true range day
(4.05 KiB) Downloaded 697 times

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

Re: Daily Average True range

Postby TJ » 19 Oct 2011

Thanks for the reply

The output (to a file using print statements) goes into negative numbers, average true range should always be positive of course.

The function I have calls "truehighd","truelowd",and "trueranged" functions.

The .eld file is attached which contains these.
I do not understand the question you are asking...

you are saying a function called "avgtrueranged(30)" is giving you negative numbers?

do you have the code that calls this function?



ps. there is an indicator called "Average True Range" that comes with MultiCharts.
Please apply this indicator and see if the chart shows negative value.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Daily Average True range

Postby waveslider » 19 Oct 2011

The function should provide the value of the average true range of the past 30 DAYS of a DAILY charts on an intraday chart. The code is in an ELD file attached to my last message.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Daily Average True range

Postby waveslider » 19 Oct 2011

correct, I am getting negative values.

The avg. true range function within MC applied on an intraday chart would provide the average true range of the bars on that intraday chart - not the daily chart.

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

Re: Daily Average True range

Postby TJ » 19 Oct 2011

correct, I am getting negative values.

The avg. true range function within MC applied on an intraday chart would provide the average true range of the bars on that intraday chart - not the daily chart.
You have to check with the original author on how this function works.

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Daily Average True range

Postby waveslider » 19 Oct 2011

Thanks for trying to help, the issue is not the function - which works fine in TS, and I know how it works already.
There is a problem with the conversion into Multicharts.

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: Daily Average True range

Postby escamillo » 19 Oct 2011

Alternative 1: AvgRangeD(30) range might work for you. If you can live without having gaps included.

Alternative 2: see if this works. within the Function code document AvgTrueRangeD, at the bottom of the code below the last semicolon put:

Code: Select all

AvgTrueRangeD = Value1 ;
Edit: I thought I had AvgTrueRangeD working by using Alternative 2 but now it appears not. AvgRangeD does work for me. If you need the function code for AvgRangeD, then let me know.
Last edited by escamillo on 19 Oct 2011, edited 1 time in total.

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

Re: Daily Average True range

Postby TJ » 19 Oct 2011

make a back up copy of your AvgTrueRangeD function,
then give this a try and see if the result matches what you have in TS:

Code: Select all

[LegacyColorValue = TRUE];
// Ffunction: AvgTrueRangeD
// Version: beta 0.1 for MultiCharts


inputs:
Length(numericsimple);

var:
dayHi(0),
dayLo(0);

if Length = 0 or Length = 1 then
AvgTrueRangeD = TrueRangeD(Length)
else
begin
if date <> date[1]
then { new day }
{ throw away the first day, and add today }
AvgTrueRangeD = (AvgTrueRangeD[1]
- TrueRangeD(Length)/Length
+ TrueRangeD(0) )/Length
else
begin { same day as last bar }
dayHi = HighD(0);
dayLo = LowD(0);

if dayHi = dayHi[1] and dayLo = dayLo[1] then
{ same day, same day low & day high }
{ reuse whatever was in last bar }
AvgTrueRangeD = AvgTrueRangeD[1]
else
{ same day, but different day low or different day high }
{ throw away today and add today using new data }
AvgTrueRangeD = (AvgTrueRangeD[1]
- TrueRangeD(0)[1]/Length
+ TrueRangeD(0) )/Length
;
end;
end;

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Daily Average True range

Postby sptrader » 19 Oct 2011

TJ - in the code above(previous post) you call the "TrueRangeD" function, could you please post that function ?

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

Re: Daily Average True range

Postby TJ » 19 Oct 2011

TJ - in the code above(previous post) you call the "TrueRangeD" function, could you please post that function ?
It is in post #3.

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Daily Average True range

Postby SP » 20 Oct 2011

waveslider, that is what i use for calculation, maybe it works for you too:

Code: Select all

Input:
Modus ( 1 ),
//Modus = 1 : Calculate the ATR including the current date, the ATR drops on the start of the trading
//day. Same calculation as on a daily chart using the standard
//Average True Range function with "Update on every tick" checked
//Modus = 2 : Calculate the ATR over the last ATRLength days excluding today.
//Same calculation as on a daily chart using the standard
//Average True Range function with "Update on every tick" unchecked
ATRLength( 30 );

Variables:
x (0),
AvDailyAtr (0),
Initialized (0);

Array : MyATR [50] (0); //Limit to 50 as OHLCPeriodsAgo used by TrueRangeD /HighD... is
//limited to arr0[ 4, 50 ]( -1 )

once begin
if ATRLength >49 then raiseruntimeerror (" ATRLength needs to be <50 !!!!");
end;

If date <> date[1] then
begin
Initialized = Initialized + 1;
If Bartype < 2 and initialized > ATRLength then
begin
for x = 1 to ATRLength-1
begin
MyATR [x] = TrueRangeD ( x);
end;
end;
end;

if Modus = (1) then MyATR [0] = TrueRangeD ( 0 );
if Modus = (2) then MyATR [0] = TrueRangeD ( ATRLength );

AvDailyAtr = array_sum ( MyATR ,0,ATRLength-1 )/ATRLength;

If initialized > ATRLength then
Plot1(AvDailyAtr ,"Daily ATR");



sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Daily Average True range

Postby sptrader » 20 Oct 2011

TJ - in the code above(previous post) you call the "TrueRangeD" function, could you please post that function ?
It is in post #3.
**********************************
** Thanks TJ, I missed that..

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Daily Average True range

Postby waveslider » 20 Oct 2011

Thanks to all of you for your help, I'll update you with my findings. Glad to be away from TS!

waveslider
Posts: 222
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: Daily Average True range

Postby waveslider » 20 Oct 2011

SP,
your version works great for me, also like how you can drop out the current day - very convenient.
Thanks to all of you.

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

Re: Daily Average True range

Postby cdickerm » 18 Aug 2012

Hi, I've read your discussion on calculating average daily range and have tried getting 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).

Would you please 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. You guys had mentioned TrueRangeD and a few others, but the PowerLanguage editor doesn't highlite or recognize those as functions.

Thank you,
Carey

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

Re: Daily Average True range

Postby TJ » 18 Aug 2012

Hi, I've read your discussion on calculating average daily range and have tried getting 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).

Would you please 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. You guys had mentioned TrueRangeD and a few others, but the PowerLanguage editor doesn't highlite or recognize those as functions.

Thank you,
Carey
instead of using HighD(1) in an intraday chart,
you should add a daily chart as data2 and apply average to the high of data2.

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

Re: Daily Average True range

Postby cdickerm » 18 Aug 2012

Hello,

In response to your statement:

"Instead of using HighD(1) in an intraday chart,
you should add a daily chart as data2 and apply average to the high of data2."

Would you please explain what you mean, and how this may be done on MC? A brief example would be super helpful. It seems like MC would be advanced enough to understand daily functions when using an intraday system, no?

Thanks so much for your input.

Carey

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

Re: Daily Average True range

Postby TJ » 19 Aug 2012

Hello,

In response to your statement:

"Instead of using HighD(1) in an intraday chart,
you should add a daily chart as data2 and apply average to the high of data2."

Would you please explain what you mean, and how this may be done on MC? A brief example would be super helpful.... [snip]

Thanks so much for your input.

Carey
see post #4
viewtopic.php?f=16&t=6929

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

Re: Daily Average True range  [SOLVED]

Postby TJ » 19 Aug 2012

Hello,

... It seems like MC would be advanced enough to understand daily functions when using an intraday system, no?

Thanks so much for your input.

Carey
MultiCharts analyzes the chart bar-by-bar.
If the chart is a one minute chart, it will analyze the chart one minute at a time.
If the chart is a daily chart, it will analyze the chart one day at a time.

huric
Posts: 1
Joined: 27 Sep 2012

Re: Daily Average True range

Postby huric » 27 Sep 2012

Try this:
var0=HighD(1);
var1=LowD(1);
Average(var0,30) - Average(var1,30)

In fact, Average function will use HighD(1)[1], but in MC HighD(1)=HighD(1)[1]=HighD(1)[2]


Hi, I've read your discussion on calculating average daily range and have tried getting 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).

Would you please 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. You guys had mentioned TrueRangeD and a few others, but the PowerLanguage editor doesn't highlite or recognize those as functions.

Thank you,
Carey
instead of using HighD(1) in an intraday chart,
you should add a daily chart as data2 and apply average to the high of data2.


Return to “MultiCharts”