Label showing new high of week


Category:
0
0

Hello Mr. Hahn,

I need help building a script that allows  to check if the current daily high of a given week has passed the previous daily high of the same week. It will display a label box with the following information: if broken, “New high achieved”, otherwise, “No New high achieved”. I wish to run it on a daily aggregation period. I have tried to write a script as follows :

def newWeek = GetWeek()== GetWeek()[1];

def newday = GetDay()<>GetDay()[1];

def CDH = if !newWeek then Double.NaN
else if newday then high else if high > CDH[1] then high else CDH[1];

AddLabel(yes, Concat(“DH: “, CDH), Color.green);
AddLabel(yes, if CDH>CDH[1] then “New high achieved” else “No New high achieved”, if CDH>CDH[1] then color.greeN else color.red); ”

The script only compares with the previous day, not with the earlier days of the same week.

Any help is much appreciated.

Thanks,

Fais

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 26, 2023 7:29 pm
68 views
0
Private answer

Since the solution your requested is to display a label on a chart I have moved your question out of the "Stock Scanners" topic and into the "Chart Studies" topic.

I have also updated the title of your question so that it more clearly describes the context.

The following solution merely checks if the current high is above the previous weekly high. At the start of each new week, the level resets. I know you asked to include some sort of comparison from day to day. But I did not see that as being necessary and that level of complexity is a bit beyond the scope of free solutions I can provide in this forum.

def newWeek = GetWeek() <> GetWeek()[1];
rec weeklyHigh = if newWeek then high else if high > weeklyHigh[1] then high else weeklyHigh[1];
def newWeeklyHigh = weeklyHigh > weeklyHigh[1];
AddLabel(yes, if newWeeklyHigh then "New high achieved" else "No New high achieved", Color.WHITE);

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on January 27, 2023 11:56 am