Actually the code you used to start your project was completely inadequate to get the job done. I went straight to our video titled: Thinkorswim Overnight Range Scan Alert. The code provided with that study has an “alert period”, which can be adjusted through the user inputs. The rest of the code is not needed, but those lines that form the alert period are exactly what was needed for this solution.
So here is the code to plot previous day’s high and low on an intraday chart, while limiting those plots to a specified period of time.
input marketOpen = 800;
input marketClose = 1600;
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
def previousDayHigh = high(period = AggregationPeriod.DAY)[1];
def previousDayLow = low(period = AggregationPeriod.DAY)[1];
plot priorDayHigh = if targetHours then previousDayHigh else Double.NaN;
plot priorDayLow = if targetHours then previousDayLow else Double.NaN;
Update: After getting feedback on this code it was brought to my attention I did not follow the requested specification. The actual goal was to capture the high and low of the specified period from the previous day and plot those levels on the current intraday chart. The following code meets this goal.
input marketOpen = 800;
input marketClose = 1600;
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec targetPeriodHigh = if targetHours and !targetHours[1] then high else if targetHours and high > targetPeriodHigh[1] then high else if targetHours then targetPeriodHigh[1] else Double.NaN;
rec targetPeriodLow = if targethours and !targetHours[1] and low > 0 then low else if targetHours and low < targetPeriodLow[1] then low else if targetHours then targetPeriodLow[1] else Double.NaN;
rec previousDayHigh = if targetHours[1] and !targetHours then targetPeriodHigh[1] else previousDayHigh[1];
rec previousDayLow = if targetHours[1] and !targetHours then targetPeriodLow[1] else previousDayLow[1];
plot priorDayHigh = previousDayHigh;
priorDayHigh.SetDefaultColor(Color.GREEN);
plot priorDayLow = previousDayLow;
priorDayLow.SetDefaultColor(Color.RED);
Please provide a link to where the “previous code” was posted. This will help inform everyone as to the context and intent of that code.
And we are going to update this title: “Horizontal Line across previous day high low for US session Forex maket”. The new title to the question will have a broader scope to fit the context of your request.
The new title will be: “Plot lines for prior day high and low across specified time span”
Hi Pete, Thank you for your comment. I used the code from the earlier post titled “Premarket High/Low label” asked on Jan 10, 2019.
The new title for my question looks great.
Hi Pete, If you were waiting on me for posting the link, I could not do it as I was not able to copy the link to that specific post. When I try to grab the link, it takes me to the ThinkOrSwim Chart Studies Q&A page. like this “https://www.hahn-tech.com/thinkorswim-chart-studies/”. Therefore I have given the reference of the title and the date of the post. Thank you.