Add Labels to Study that turn Green when Triggered


Category:
0
0

Hi Pete- How can I add three labels to a Study that are gray but turn green when the stock is trading within 2.5% of its daily, weekly and monthly highs respectively.

Thanks.

 

Marked as spam
Posted by (Questions: 2, Answers: 2)
Asked on July 14, 2020 10:55 am
119 views
0
Private answer

This solution is for a single label. You can add this to a chart as many times as needed and adjust the time frame, percent threshold and label text as needed. This provide the widest possible flexibility.

input timeFrame = AggregationPeriod.DAY;
input percentThreshold = 2.5;
input labelText = "Daily";
def periodHigh = high(period = timeFrame);
AddLabel(yes, labelText, if close > periodHigh * (1 - percentThreshold * 0.01) then Color.GREEN else Color.GRAY);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 14, 2020 2:39 pm