Plot horizontal lines from 9:30 – 9:45


Category:
0
0

I’m looking to alter this code to start the plot at 9:30 and have it end at 9:45, only showing the last period.

The first photo is what the code produces now, the second is what I’m trying to get it to look like.

TIA!

input timeFrame = AggregationPeriod.DAY;
input prctLower = 9.5;
input prctUpper = 13;
input showOnlyLastPeriod = yes;

def StartTime = 0930;
def EndTime = 0945;

plot Lower = open(period = timeFrame) * ((prctLower / 100) + 1);
Lower.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Lower.SetDefaultColor(GetColor(5));

plot Upper = open(period = timeFrame) * ((prctUpper / 100) + 1) ;
Upper.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Upper.SetDefaultColor(GetColor(5));

declare hide_on_daily;

 

 

Attachments:
Marked as spam
Posted by (Questions: 4, Answers: 8)
Asked on August 21, 2018 6:18 pm
803 views
0
Private answer

For this solution I will borrow some code from our video titled: “Thinkorswim Overnight Range Scan Alert“. In the code provided with that video we have the elements that control the yellow shaded area known as the “alert zone”. It uses a start and end time to determine the extent of the alert zone.

From the code you provided I see that you have added variables to contain a start and end time but you have not used them to connect to anything. So I will be providing the missing pieces, to connect the start and end time in your existing code to the plots. I will also provide a line of code to connect your user input, showOnlyLastPeriod , to the plots.

It takes three lines of code to connect your start and end times to a true/false variable named alertPeriod.

def startCounter = SecondsFromTime(startTime);
def endCounter = SecondsTillTime(endTime);
def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

This takes care of the requirement to plot only between the start and end time. We still need to connect your user input, showOnlyLastPeriod, to the plots. This is taken directly from the code in the video.

def okToPlot = if showOnlyLastPeriod then GetLastDay() <= GetDay() and GetLastYear() <= GetYear() else yes;

Now we only need to modify your plot statements to include an if/then/else statement, which uses the true/false variables named alertPeriod and showOnlyLastPeriod as the conditions.

plot lower = if okToPlot and alertPeriod then open(period = timeFrame) * ((prctLower / 100) + 1) else Double.NaN;
plot upper = if okToPlot and alertPeriod then open(period = timeFrame) * ((prctUpper / 100) + 1) else Double.NaN;

If alertPeriod is true, we plot the values. When false, we set the plot to NaN.

If user input showOnlyLastPeriod is set to yes, we plot the lines only on the current day.

Screenshot below shows the result.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 22, 2018 8:12 am
0

Great! Thank you Pete.

( at August 22, 2018 10:02 am)