Plot high and low for specified period


Tags:
Category:
0
0

Hey Pete, I would like horizontal lines to show the high and low of /ES between the hours of 2am-5am MST (4am-7am EST, the London open). I tried modifying this code to suit my needs: https://www.hahn-tech.com/ans/premarket-highlow-label/

input startTime = 200;
input endTime = 500;
def timeUntilClose = SecondsTillTime(endTime);
def timeUntilOpen = SecondsTillTime(startTime);
def targetPeriod = timeUntilClose > 0;
rec targetPeriodHigh = if targetPeriod and !targetPeriod[1] then high else if targetPeriod and high > targetPeriodHigh[1] then high else targetPeriodHigh[1];
rec targetPeriodLow = if targetPeriod and !targetPeriod[1] then low else if targetPeriod and low < targetPeriodLow[1] and low > 0 then low else targetPeriodLow[1];
plot pmHigh = targetPeriodHigh;
plot pmLow = targetPeriodLow;

On referencing a few minutes ago I noticed you mentioned in the comments that it was not written for futures contracts. Are you able to write one for futures? Thank you for your time.

Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on June 15, 2022 8:42 pm
124 views
0
Private answer

I updated the title of your question as I was not sure why you included "London" in the title. You specified a period of time that only spans 3 hours and the London session is open for more than 8 hours. So I updated the title of your question to express the context of your request and help others who are searching for a similar solution to locate this using the search function.

The source code you want to start with for this is located here:

https://www.hahn-tech.com/ans/draw-a-colored-box-around-the-eth-europelondon-sessions/

Oddly enough, I located that previous post by using the search term "London".

The code below was copied from the previous post and I removed the last line which added the cloud and replaced it with four new lines. Two of them to track the highest high and lowest low during the "alert period". Then two additional lines to plot those values for all bars outside of the "alert period".

Be sure to read the details I provided with that previous post as there is more to learn about where this code originated and what it was intended to do. You may also fined the solution in the previous post useful because it highlights the "alert period" on the chart.

Limitations of this code: It will completely fail if the start time is from the previous day and the end time is from the current day. For example if you set the start time to 1800 and the end time to 700 it will fail. This can be resolved with a more advanced solution but that is well beyond the scope of free solutions I can provide in this forum.

input alertPeriodStart = 400;
input alertPeriodEnd = 700;
def startCounter = SecondsFromTime(alertPeriodStart);
def endCounter = SecondsTillTime(alertPeriodEnd);
def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec trackHigh = if alertPeriod and !alertPeriod[1] then high else if alertPeriod and high > trackHigh[1] then high else trackHigh[1];
rec trackLow = if alertPeriod and !alertPeriod[1] then low else if alertPeriod and low > 0 and low < trackLow[1] then low else trackLow[1];
plot targetPeriodHigh = if !alertPeriod then trackHigh else Double.NaN;
plot targetPeriodLow = if !alertPeriod then trackLow else Double.NaN;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 16, 2022 8:46 am