I want to determine if there is a gap in the overnight trading so I need to refer back to the previous days high and low.
I started with code for tracking the opening range and changed the time to be the entire session, 930 - 1600.
I changed the plot function to draw the lines but I can't figure out how to get the previous high or low so I can write a formula
Gap = close > PDHigh or Close < PDLow
Any help would be great.
Thanks
I started with code for tracking the opening range and changed the time to be the entire session, 930 - 1600.
I changed the plot function to draw the lines but I can't figure out how to get the previous high or low so I can write a formula
Gap = close > PDHigh or Close < PDLow
Any help would be great.
Thanks
Code:
# 10-31-24 Rich HIGH/LOW of RTH
# Some code By Prospectus @ http://readtheprospectus.wordpress.com
# Inspired by Trader-X @ http://traderx.blogspot.com
#
# Originally This Thinkscript is designed to plot the OR high, low,
# 50% fib retrace, and fib extensions for the current day.
# This will only work correctly on time-based charts,
# where the OR timeframe is divisible by the bar period
# e.g. 30 minute OR, 10 min bars. An extra fib extension
# may be used if desired to create a target zone.
#
def na = Double.NaN;
#
# Define time that OR begins (in hhmm format,
# 0930 is the default):
#
input ORBegin = 0930;
#
# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
#
input OREnd = 1600;
#
#
# Show Today only? (Default Yes)
#
input ShowTodayOnly = {"No", default "Yes"};
def s = ShowTodayOnly;
#
#
# Create logic for OR definition:
#
def ORActive = if SecondsTillTime(OREnd) > 0 and SecondsFromTime(ORBegin) >= 0 then 1 else 0;
#
# Create logic to paint only current day post-open:
#
def today = if s == 0 or GetDay() == GetLastDay() and SecondsFromTime(ORBegin) >= 0 then 1 else 0;
#
# Track OR High:
#
rec ORHigh = if ORHigh[1] == 0 or ORActive[1] == 0 and ORActive == 1 then high else if ORActive and high > ORHigh[1] then high else ORHigh[1];
#
# Track OR Low:
#
rec ORLow = if ORLow[1] == 0 or ORActive[1] == 0 and ORActive == 1 then low else if ORActive and low < ORLow[1] then low else ORLow[1];
#################################################
#How to save previous days high/low?
def DayEnd = SecondsTillTime(OREnd) < 0;
#if DayEnd then ORHigh = PD_High else na ;
#def PD_High= ORHighLine;
def MarketOpenBar = SecondsFromTime(ORBegin) >= 0 and SecondsFromTime(ORBegin) < 1;
def MarketOpen = if MarketOpenBar then open else na;
plot MarketOpenPrice = MarketOpen;
#def PD_High = if MarketOpen then ORHigh[1] else na;
#def PD_Low = if MarketOpen then ORLow[1] else na;
#plot GapU = PD_High;
#plot GapD = PD_Low;
#addverticalLine(shouldDraw, "London Open at " + timeToDrawLine, getColor(lineColor), Curve.SHORT_DASH);
#AddVerticalLine(MarketOpen, "Open ", Color.CYAN, Curve.SHORT_DASH);
#
# Define all the plots:
#
plot ORL = ORLow;
plot ORH = ORHigh;
#
# Formatting:
#
ORH.SetDefaultColor(Color.GREEN);
ORH.SetStyle(Curve.LONG_DASH);
ORH.SetLineWeight(3);
ORL.SetDefaultColor(Color.RED);
ORL.SetStyle(Curve.LONG_DASH);
ORL.SetLineWeight(3);
#labels
AddLabel (yes, orlow, color.red);
AddLabel (yes, orh, CreateColor(127,255,0));
Last edited by a moderator: