Previous week high without aggregation period


Category:
0
0

Hi Hahn,

I am trying to build a scanner where current 5m candle crosses previous week’s high. I tried using aggregation period but it does not allow secondary aggregation period for scan. Request you to help me as to how I can get previous week’s high. Thank you in advance.

 

I tried this based on your previous day’s data, but this is not giving expected result. I may not be using it in the right way.

rec previousWeekHigh = if GetWeek() <> GetWeek()[1] then high[1] else previousWeekHigh[1];

plot h1 = previousWeekHigh;

h1.SetPaintingStrategy(PaintingStrategy.LIne);

h1.setDefaultColor(Color.red);

 

Regards,

Misha

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on May 11, 2021 5:17 pm
75 views
0
Private answer

Since your request is for a custom scan I have moved this post out of the "Chart Studies" topic and into the "Stock Scanners" topic.

The solution requires two sets of recursive variables. One that computes the highest high of each week "weeklyHigh" and a second one that grabs the previous week's highest high at the start of each week "previousWeeklyHigh".

def newWeek = GetWeek() <> GetWeek()[1];
rec weeklyHigh = if newWeek then high else if high > weeklyHigh[1] then high else weeklyHigh[1];
rec previousWeeklyHigh = if newWeek then weeklyHigh[1] else previousWeeklyHigh[1];
plot scan = close crosses above previousWeeklyHigh;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 11, 2021 5:38 pm