52 week high and 52 week low  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 399
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 123 times

52 week high and 52 week low

Postby evdl » 17 Dec 2012

In the scanner you can select 52 week high and low. How can I use this value in a indicator. Which reserved word do I use?

I noticed the high52wk and low52wk in the pl editor but those seem not to work in a indicator.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 557 times

Re: 52 week high and 52 week low  [SOLVED]

Postby Andrew MultiCharts » 17 Dec 2012

Hello Evdl,

The values are provided by data source (not all of the supported ones do this). Unfortunately there is no way you can return the same values in EasyLanguage/PowerLanguage script.
These users thanked the author Andrew MultiCharts for the post:
evdl

Xyzzy
Posts: 156
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 76 times

Re: 52 week high and 52 week low

Postby Xyzzy » 19 Dec 2012

It should be possible to calculate these values in your code. One way would be to attach a Data2 series for the same instrument, but with weekly bars. You can then get the highest and lowest values for the last 52 weeks through something like the following (not tested):

value1 = Highest(High of Data2, 52);
value2 = Lowest(Low of Data2, 52);
These users thanked the author Xyzzy for the post:
Andrew MultiCharts

evdl
Posts: 399
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 123 times

Re: 52 week high and 52 week low

Postby evdl » 20 Dec 2012

Thank you Xyzzy,

I made an indicator to calculate the 52 week high and low (you can use this without data2).

Code: Select all

// INDICATOR 52 Week High/Low:
// This indicator calculates 52 weekly high and low of a symbol.

Array:
High52wk_array[52] (0),
Low52wk_array[52] (0);

var:
Dateformat_week(""),
High52wk_value(0),
Low52wk_value(99999),
High_of_week(0),
Low_of_week(99999);

// End declarations

Dateformat_week = formatdate("dd-MM-yyyy", eldatetodatetime(date));

If DayOfWeek( Date ) = 5 and (sessionlastbar = true) then begin

   High_of_week = h;  // resets the variable at the end of last bar on every friday
   Low_of_week = L;  // resets the variable at the end of last bar on every friday
   end
   else
   begin // accumulates high/low data for the week
    if h > High_of_week then High_of_week = h;
    if L < Low_of_week then Low_of_week = L;

// post data to array
   High52wk_array[52] = High_of_week[1];
   Low52wk_array[52]= Low_of_week[1];   
     
   High52wk_value = high52wk_array[52];
   Low52wk_value = low52wk_array[52];
   
   High52wk_value = highest(high52wk_value,52);
   Low52wk_value = lowest(low52wk_value,52);

 //Print(dateformat_week," high ", high52wk_value," low ", low52wk_value);
 plot1(High52wk_value);
 plot2(Low52wk_value);

End;

User avatar
TJ
Posts: 6585
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1907 times

Re: 52 week high and 52 week low

Postby TJ » 20 Dec 2012

evdl wrote:Thank you Xyzzy,

I made an indicator to calculate the 52 week high and low (you can use this without data2).
...


re: your code

Code: Select all

If DayOfWeek( Date ) = 5 and (sessionlastbar = true) then begin


What if Friday is a holiday?

evdl
Posts: 399
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 123 times

Re: 52 week high and 52 week low

Postby evdl » 20 Dec 2012

Yes, that could be a problem if the high or low of the 52 weeks is on that particular day. Although the change of that happening exact on that day is small, but nevertheless, you would have wrong values.

Probably better is this

Code: Select all

If DayOfWeek( Date ) <> dayofweek(date[1]) and (sessionlastbar = true) then begin

User avatar
TJ
Posts: 6585
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1907 times

Re: 52 week high and 52 week low

Postby TJ » 20 Dec 2012

evdl wrote:Yes, that could be a problem if the high or low of the 52 weeks is on that particular day. Although the change of that happening exact on that day is small, but nevertheless, you would have wrong values.

Probably better is this

Code: Select all

If DayOfWeek( Date ) <> dayofweek(date[1]) and (sessionlastbar = true) then begin

What if Thursday is a holiday (eg. Thanksgiving)?

User avatar
TJ
Posts: 6585
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1907 times

Re: 52 week high and 52 week low

Postby TJ » 20 Dec 2012

you can try this:

Code: Select all

If DayOfWeek( Date ) < dayofweek( date[1] ) ...



ps. unless the market closed for more than 5 days.
These users thanked the author TJ for the post (total 2):
evdlJoshM

Xyzzy
Posts: 156
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 76 times

Re: 52 week high and 52 week low

Postby Xyzzy » 20 Dec 2012

For what it's worth, there's also a discussion here about how to build a similar indicator -- one that calculates the high/low of a set time period.

http://markplex.com/free-tutorials/tuto ... art-times/

It deals with similar issues, such as what happens if there isn't a bar for the specified "end time."
These users thanked the author Xyzzy for the post:
evdl

evdl
Posts: 399
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 123 times

Re: 52 week high and 52 week low

Postby evdl » 21 Dec 2012

you can try this:

Code:
If DayOfWeek( Date ) < dayofweek( date[1] ) ...

ps. unless the market closed for more than 5 days.


That is the best option TJ. I will use that.
These users thanked the author evdl for the post:
TJ


Return to “MultiCharts”