#
https://usethinkscript.com/threads/pre-market-after-market-for-thinkorswim.75/page-11#post-105276
# Globex, RTH and prior RTH High and Low
# Request for JQ 11.8.18
# v0.02 11.12.18 will plot prior RTH during current RTH
# Nube
# inputs
input bubbles = yes;
# univerals
def na = Double.NaN;
def bn = BarNumber();
def h = high;
def l = low;
script prior {
# subscript for getting prior value of a BarNumber() defined variable
input prior = close;
def priorOf = if prior != prior[1] then prior[1] else priorOf[1];
plot priorBar = priorOf;
}
# variables
def cb = HighestAll(if !IsNaN(h) then bn else na);
def time = GetTime();
def rts = RegularTradingStart(GetYYYYMMDD());
def rte = RegularTradingEnd(GetYYYYMMDD());
def RTH = if time crosses above rts
then bn else RTH[1];
def globex = if time crosses below rte
then bn else globex[1];
# If you want to include the extended session in Globex, then use globex def below
#def globex = if time crosses above rte
# then bn else globex[1];
def priorRTH = prior(RTH);
def priorGlobex = prior(globex);
def hRTH = HighestAll(RTH);
def hGX = HighestAll(globex);
def hPRTH = HighestAll(priorRTH);
def hPGX = HighestAll(priorGlobex);
def gXhigh = HighestAll(if bn >= hGX && bn < hRTH
then h else if hRTH < hGX && bn >= hGX
then h else na);
def gXlow = LowestAll(if bn >= hGX && bn < hRTH
then l else if hRTH < hGX && bn >= hGX
then l else na);
def RTHhigh = HighestAll(if bn >= hRTH && bn < hGX
then h else if hGX < hRTH && bn >= hRTH
then h else na);
def RTHlow = LowestAll(if bn >= hRTH && bn < hGX
then l else if hGX < hRTH && bn >= hRTH
then l else na);
def priorRTHhigh = HighestAll(if bn >= hPRTH
&& bn < if hGX < hRTH
then hGX
else hPGX
then h else na);
def priorRTHlow = LowestAll(if bn >= hPRTH
&& bn < if hGX < hRTH
then hGX
else hPGX
then l else na);
plot
GlobexHigh = gXhigh;
GlobexHigh.SetDefaultColor(Color.LIGHT_GREEN);
plot
GlobexLow = gXlow;
GlobexLow.SetDefaultColor(Color.PINK);
plot
HighRTH = RTHhigh;
HighRTH.SetDefaultColor(Color.GREEN);
plot
LowRTH = RTHlow;
LowRTH.SetDefaultColor(Color.RED);
plot
PreviousHighRTH = priorRTHhigh;
PreviousHighRTH.SetDefaultColor(Color.DARK_GREEN);
plot
PreviousLowRTH = priorRTHlow;
PreviousLowRTH.SetDefaultColor(Color.DARK_RED);
plot ONMid = (gXhigh + gXlow) / 2 ;
plot RTHMid = (RTHhigh + RTHlow) / 2 ;
plot PreviousMid = (PreviousHighRTH + PreviousLowRTH) / 2 ;
AddChartBubble(bubbles && bn == cb, gXhigh, "ONH", Color.LIGHT_GREEN);
AddChartBubble(bubbles && bn == cb, RTHhigh, "HOD", Color.GREEN);
AddChartBubble(bubbles && bn == cb, priorRTHhigh, "YHI", Color.GREEN);
AddChartBubble(bubbles && bn == cb, gXlow, "ONL", Color.RED, 0);
AddChartBubble(bubbles && bn == cb, RTHlow, "LOD", Color.RED, 0);
AddChartBubble(bubbles && bn == cb, priorRTHlow, "YLO", Color.DARK_ORANGE, 0);
AddChartBubble(bubbles && bn == cb, PreviousMid, "YMID", Color.YELLOW, 0);
AddChartBubble(bubbles && bn == cb, RTHMid, "MID", Color.YELLOW, 0);
AddChartBubble(bubbles && bn == cb, ONMid, "ONM", Color.YELLOW, 0);
# f/ Globex, RTH and prior RTH High and Low