365 day high has occurred in the last 50 days

I am looking to do a show bar when true. I have modified the code below but it is not working – I want to know whether anytime in the last 50 days whether there was a 365 day high – True or false.

Further to the below the calculation should be satisfied across month, week and day charts when assessing whether the 365 day high was in the last 50 days (ie the requirement is 50 days not 50 bars). I hope that makes sense. Coding is below.

//365 day high has occurred in the last 50 days

V1= HIGHESTHIGH(BARS=365, BACKTYPE=Days); High()>V1
TIMESINCESIGNAL(V1, UNIT=Days, FIRSTSIGNALONLY=False) <= 50

Can someone please assist with what I am doing wrong. Thanks.

Hi,

The High() > V1 needs to be on its own line and assigned a different variable, the TimeSinceSignal() then needs to be wrapped around that.

Additionally, for it to run on multiple time frames but return the same result you need to set a time frame override on a few of the lines.

The final script would look like this:

V1 = HIGHESTHIGH(Day(PERIODAMOUNT=1), BACKTYPE=Days, BARS=365) ;
V2 = HIGH(Day(PERIODAMOUNT=1)) CrossesAbove V1 ;
V3 = TIMESINCESIGNAL(V2, UNIT=Days);
V3 <=50

Here’s an example of the output…

Ex7

Hi Matthew,

I have attached a chart using the coding. The green star at the top is the criteria but it is showing more than 1 star for the weekly and monthly charts. How do I get it to show just 1 star above the relevant bar (in each of the daily, weekly and monthly charts)?

Thanks,
Karen

Hi Karen,

It’s because the V1 and V2 variables are loading daily data in a weekly chart, so you can have 5 true results within a weekly bar (and 20+ in a monthly), hence the duplication.

Change V1 and V2 to the following, and it will look back a year no matter the timeframe of the chart, instead of data for 365 calendar days.

V1 = HIGHESTHIGH(BACKTYPE=Weeks, BARS=52);
V2 = HIGH() CrossesAbove V1;

Hi Darren,

The formula results are still not working the way it is intended to work. Please see attached chart - if you scroll to the very start of the chart there are green stars when there are no red stars. I basically am trying to achieve a green star where a red star has appeared provided it is within 80 days of the red star occurring (and this should apply for daily, weekly and monthly charts accordingly). I have tried all types of combinations of codes and if functions but cannot get it to work.

Can you please have a look at it and let me know what is wrong with the formula please.

Thanks and kind regards,
Karen

Hi,

It’s because a value of zero is being returned at the very start, which passes the criteria of V3 (less than or equal to 80). You need to adjust that variable so that 0 is also excluded.

V1 = HIGHESTHIGH(BACKTYPE=Weeks, BARS=52);
V2 = HIGH() CrossesAbove V1;
V3 = TIMESINCESIGNAL(V2, UNIT=Days);
V4 = V3 <=80 and V3 > 0;
V4

With this adjustment, the large group of results at the start of the charts is removed.