Only show label during specific time window


Category:
0
0

Hi Pete,
I have a simple label that I would like to only appear before 9:30am. After 9:30am, I would like this label to hide/disappear from view, as it is no longer needed. I will use a simple example with the following code;

 

input recentBars = 10;
def recentVolume = Sum(volume, recentBars)/recentBars;
AddLabel(yes, Concat(“Avg10 Vol: “, recentVolume), if recentVolume>450000 then Color.RED else Color.LIGHT_GRAY);

 

Thank you,

-Davide

Marked as spam
Posted by (Questions: 7, Answers: 12)
Asked on October 13, 2022 1:06 pm
67 views
0
Private answer

This is actually a very common  request but it mostly applied to plots. Since I was not able to find a previous post which specifically mentioned a label I decided to approve this question and provide a solution.

Here is the basic structure of the code used to achieve this:

input startTime = 400;
input endTime = 929;
def okToPlot = SecondsTillTime(endTime) >= 0 and SecondsFromTime(startTime) >= 0;

This solution is weak, in that earliest time you can apply for the "starteTime" input is 4 pm Eastern. But this is the solution I can provide free of chart in this forum.

So you take that code above and immediately below it you can add your code. The modify the AddLabel() statement to use the "okToPlot" variable from above in place of the "yes" value in your original:

input recentBars = 10;
def recentVolume = Sum(volume, recentBars)/recentBars;
AddLabel(okToPlot, Concat(“Avg10 Vol: “, recentVolume), if recentVolume>450000 then Color.RED else Color.LIGHT_GRAY);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 13, 2022 2:49 pm