Premarket After-market For ThinkOrSwim

Would anyone help add code to this current Globex High and Low indicator so that it only draws lines for current day Globex only. As is the code draws lines on days in the past. I just need the current day. Thanks!

Here is the code:
# TS_GlobexRange
# http://thinkscripter.wordpress.com
# [email protected]
# Last Update 18 JUL 2009

input bubbles = yes;
input bubblemover = 4;
def b =bubblemover;
def b1 = b + 1;
input Globex_Open = 1800;
input Globex_Close = 0929;

def globexOpen = if(secondsFromTime(Globex_Open) >= 0 or secondsTillTime(Globex_Close)>=0, 1, 0);
def globexReset = if globexOpen and !globexOpen[1] then 1 else 0;

rec globexHigh = compoundValue(1, if((high > globexHigh[1] and globexOpen) or globexReset, high,globexHigh[1]),high);
rec globexLow = compoundValue(1, if((low < globexLow[1] and globexOpen) or globexReset, low,globexLow[1]),low);

plot Globex_High = globexHigh;
Globex_high.SetStyle(curve.LONG_DASH);
Globex_High.SetDefaultColor(color.green);
Globex_High.setLineWeight(2);
plot Globex_Low = globexLow;
Globex_Low.SetStyle(curve.LONG_DASH);
Globex_Low.SetDefaultColor(color.red);
Globex_Low.setLineWeight(2);

input showbubble_left = yes;
AddChartBubble(IsNaN(showbubble_left and close[-1]) and !IsNaN(close),Globex_High, "GX High", Color.Light_Green);
AddChartBubble(IsNaN(showbubble_left and close[-1]) and !IsNaN(close),Globex_Low, "GX Low", Color.Red,0);
 
This is a great script, helps w my premarket since i put it on this week. Is there any way to make the pre and post market lines stay after turning off extended hours? I like to see those levels all day on my chart. Thanks in advance!
 
Last edited by a moderator:
This is a great script, helps w my premarket since i put it on this week. Is there any way to make the pre and post market lines stay after turning off extended hours? I like to see those levels all day on my chart. Thanks in advance!
Turning on extended hours says you want pre- and post- market data.
Turning off extended hours says you don't want pre- and post- market data.
Therefore, no, there is a way to keep the lines on all day even when extended hours is turned off
 
Last edited:
@RandyR Here is code for entire Globex

Code:
# 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);

AddChartBubble(bubbles && bn == cb, gXhigh, "Globex High", Color.Light_Green);
AddChartBubble(bubbles && bn == cb, RTHhigh, "RTH High", Color.Green);
AddChartBubble(bubbles && bn == cb, priorRTHhigh, "Previous\n RTH High", Color.Dark_Green);
AddChartBubble(bubbles && bn == cb, gXlow, "Globex Low", Color.Pink,0);
AddChartBubble(bubbles && bn == cb, RTHlow, "RTH Low", Color.Red,0);
AddChartBubble(bubbles && bn == cb, priorRTHlow, "Previous\n RTH Low", Color.Dark_Red,0);
# f/ Globex, RTH and prior RTH High and Low
Is there a way to get bubbles moved over to the right? They end up right over price action at times.
 
Is there a way to get bubbles moved over to the right? They end up right over price action at times.

Yes. I have inserted a bubblemover input, which will move the bubbles right/left by the positive/negative number input.

Screenshot-2022-10-20-114250.png
Ruby:
# 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 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);

input bubblemover = 3;
def bm  = bubblemover;
def bm1 = bm + 1;
def cb   = !IsNaN(close[bm1]) && isnan(close[bm]);
AddChartBubble(bubbles && cb, gXhigh, "Globex High", Color.Light_Green);
AddChartBubble(bubbles && cb, RTHhigh, "RTH High", Color.Green);
AddChartBubble(bubbles && cb, priorRTHhigh, "Previous\n RTH High", Color.Dark_Green);
AddChartBubble(bubbles && cb, gXlow, "Globex Low", Color.Pink,0);
AddChartBubble(bubbles && cb, RTHlow, "RTH Low", Color.Red,0);
AddChartBubble(bubbles && cb, priorRTHlow, "Previous\n RTH Low", Color.Dark_Red,0);
# f/ Globex, RTH and prior RTH High and Low
 
Last edited:
Hello fellow traders.

Recently found this super useful piece of code which I have incorporated into all my intraday charts. Its from this post:

https://usethinkscript.com/threads/premarket-after-market-for-thinkorswim.75/post-1323

I am wondering if there is there a way to make the H/L lines extend left across all historical data in the chart?

Any thoughts?


Rich (BB code):
# Archive Name: GlobeX or Overnight High / Low v.07.2017
# Archive Section: Support Resistance
# Suggested Tos Name: GlobeX_HighLow_v2017_Mobius
# Archive Date: 5.06.2018 May 6, 2018
# Archive Notes: This looks to be a second version

# GlobeX or Overnight High / Low
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
then h
else if Globex and
h > ONhigh[1]
then h
else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
then Bar
else double.nan;
def ONlow = if GlobeX and !GlobeX[1]
then l
else if GlobeX and
l < ONlow[1]
then l
else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow
then Bar
else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];
plot ONH = if OverNightHigh > 0
then OverNightHigh
else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
plot ONL = if OverNightLow > 0
then OverNightLow
else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
ONL.HideBubble();
ONL.HideTitle();
AddLabel(GlobeX, "GlobeX Range = " + AsDollars(ONH - ONL), color.white);
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
Alert((close crosses above ONH) or (close crosses below ONL), "", Alert.Bar, Sound.Bell);
# End Code GlobeX or Overnight High / Low v.07.2017
 
Hello fellow traders.

Recently found this super useful piece of code which I have incorporated into all my intraday charts. Its from this post:

https://usethinkscript.com/threads/premarket-after-market-for-thinkorswim.75/post-1323

I am wondering if there is there a way to make the H/L lines extend left across all historical data in the chart?

Any thoughts?


Rich (BB code):
# Archive Name: GlobeX or Overnight High / Low v.07.2017
# Archive Section: Support Resistance
# Suggested Tos Name: GlobeX_HighLow_v2017_Mobius
# Archive Date: 5.06.2018 May 6, 2018
# Archive Notes: This looks to be a second version

# GlobeX or Overnight High / Low
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
then h
else if Globex and
h > ONhigh[1]
then h
else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
then Bar
else double.nan;
def ONlow = if GlobeX and !GlobeX[1]
then l
else if GlobeX and
l < ONlow[1]
then l
else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow
then Bar
else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];
plot ONH = if OverNightHigh > 0
then OverNightHigh
else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
plot ONL = if OverNightLow > 0
then OverNightLow
else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
ONL.HideBubble();
ONL.HideTitle();
AddLabel(GlobeX, "GlobeX Range = " + AsDollars(ONH - ONL), color.white);
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
Alert((close crosses above ONH) or (close crosses below ONL), "", Alert.Bar, Sound.Bell);
# End Code GlobeX or Overnight High / Low v.07.2017

See if this helps

Screenshot-2022-11-15-030731.png
Ruby:
# Archive Name: GlobeX or Overnight High / Low v.07.2017
# Archive Section: Support Resistance
# Suggested Tos Name: GlobeX_HighLow_v2017_Mobius
# Archive Date: 5.06.2018 May 6, 2018
# Archive Notes: This looks to be a second version

# GlobeX or Overnight High / Low
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
             then h
             else if Globex and
                     h > ONhigh[1]
                  then h
                  else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
                then Bar
                else double.nan;
def ONlow = if GlobeX and !GlobeX[1]
            then l
            else if GlobeX and
                    l < ONlow[1]
                 then l
                 else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow
               then Bar
               else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
                    then ONhigh
                    else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
                   then ONlow
                   else OverNightLow[1];
plot ONH = highestall(OverNightHigh);
#if OverNightHigh > 0
#then OverNightHigh
#else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
plot ONL = highestall(OverNightLow);
#if OverNightLow > 0
#then OverNightLow
#else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
ONL.HideBubble();
ONL.HideTitle();
AddLabel(GlobeX, "GlobeX Range = " + AsDollars(ONH - ONL), color.white);
AddChartBubble(bar == highestall(ONhighBar) #and PlotOverNightExtremes
,ONH, "ONH", Color.BLUE);
AddChartBubble(bar == highestall(ONlowBar)
# and PlotOverNightExtremes
, ONL, "ONL", Color.GRAY, 0);
Alert((close crosses above ONH) or (close crosses below ONL), "", Alert.Bar, Sound.Bell);
# End Code GlobeX or Overnight High / Low v.07.2017
 
@CDJay The code in post #1 will do exactly just that. Did you try it out yet? Can you show a screenshot of what is not working?
Hello @BenTen , Thank you for your help with this. I added the study from post 1 but can't find any settings to display the fib level on each of the line. Can you please help me code how to display the fib levels and price on each line? I like grey color and if possible, I would like to display fib level on the left of the line and the price on the right of the line. Thank a ton!
 
Hello @BenTen , Thank you for your help with this. I added the study from post 1 but can't find any settings to display the fib level on each of the line. Can you please help me code how to display the fib levels and price on each line? I like grey color and if possible, I would like to display fib level on the left of the line and the price on the right of the line. Thank a ton!

This might help https://usethinkscript.com/threads/premarket-after-market-for-thinkorswim.75/post-84840
 
@Tom4235 I think this is what you're talking about.

Rich (BB code):
# Archive Name: GlobeX or Overnight High / Low v.07.2017
# Archive Section: Support Resistance
# Suggested Tos Name: GlobeX_HighLow_v2017_Mobius
# Archive Date: 5.06.2018 May 6, 2018
# Archive Notes: This looks to be a second version

# GlobeX or Overnight High / Low
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
             then h
             else if Globex and
                     h > ONhigh[1]
                  then h
                  else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
                then Bar
                else double.nan;
def ONlow = if GlobeX and !GlobeX[1]
            then l
            else if GlobeX and
                    l < ONlow[1]
                 then l
                 else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow
               then Bar
               else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
                    then ONhigh
                    else OverNightHigh[1];
def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
                   then ONlow
                   else OverNightLow[1];
plot ONH = if OverNightHigh > 0
           then OverNightHigh
           else Double.NaN;
ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle();
plot ONL = if OverNightLow > 0
           then OverNightLow
           else Double.NaN;
ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);
ONL.SetDefaultColor(Color.GRAY);
ONL.HideBubble();
ONL.HideTitle();
AddLabel(GlobeX, "GlobeX Range = " + AsDollars(ONH - ONL), color.white);
AddChartBubble(bar == ONhighBar and PlotOverNightExtremes, ONH, "ONH", Color.BLUE);
AddChartBubble(bar == ONlowBar and PlotOverNightExtremes, ONL, "ONL", Color.GRAY, 0);
Alert((close crosses above ONH) or (close crosses below ONL), "", Alert.Bar, Sound.Bell);
# End Code GlobeX or Overnight High / Low v.07.2017
Hey @BenTen is there any way I can run this script on a 5 minute chart without having the extended hours trading turned on?
 
Is there a way to display the values without adding the bubble? Bubble takes too much chart space and would like to move it out of the way

The bubbles are the only option to display on the fib lines.

However, with the showbubbles set to no, and the TOS right axis bubbles not hidden as in the original code, then you you can see just the values on the right axis.

Screenshot-2022-12-20-113944.png
Ruby:
# GlobeX or Overnight High / Low with Fibonacci Values 

# Mobius 

# V01.2012 

input PlotOverNightExtremes = yes;

input coeff_1 = .236;

input coeff_2 = .327;

# gmh: added the rest of the Fibs 

input coeff_3 = .500;

input coeff_4 = .618;

input coeff_5 = .789;

input coeff_6 = .882;



def o = open;

def h = high;

def l = low;

def c = close;

def v = volume;

def bar = BarNumber();

def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());

def vol = if GlobeX and !GlobeX[1]

          then v

          else if GlobeX

               then vol[1] + v

               else Double.NaN;

def GlobeX_Volume = vol;

def ONhigh = if GlobeX and !GlobeX[1]

             then h

             else if GlobeX and

                     h > ONhigh[1]

                     then h

                  else ONhigh[1];

def ONhighBar = if GlobeX and h == ONhigh

                then bar

                else Double.NaN;

def ONlow = if GlobeX and !GlobeX[1]

            then l

            else if GlobeX and

                    l < ONlow[1]

            then l

                 else ONlow[1];

def ONlowBar = if GlobeX and l == ONlow

               then bar

               else Double.NaN;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)

                    then ONhigh

                    else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)

                   then ONlow

                   else OverNightLow[1];

plot ONH = if OverNightHigh > 0

           then OverNightHigh

           else Double.NaN;

ONH.SetHiding(!PlotOverNightExtremes);

ONH.SetPaintingStrategy(PaintingStrategy.SQUARES);

ONH.SetDefaultColor(Color.BLUE);

#ONH.HideBubble();

ONH.HideTitle();

plot ONL = if OverNightLow > 0

           then OverNightLow

           else Double.NaN;

ONL.SetHiding(!PlotOverNightExtremes);

ONL.SetPaintingStrategy(PaintingStrategy.SQUARES);

ONL.SetDefaultColor(Color.LIGHT_GRAY);

#ONL.HideBubble();

ONL.HideTitle();



def MaxBar = Max(HighestAll(ONhighBar), HighestAll(ONlowBar));



plot coeff1 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_1) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_1)

              else Double.NaN;

plot coeff2 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_2) + OverNightLow

               else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_2)

              else Double.NaN;

plot coeff3 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_3) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_3)

              else Double.NaN;

plot coeff4 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_4) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_4)

              else Double.NaN;

plot coeff5 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_5) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_5)

              else Double.NaN;

plot coeff6 = if HighestAll(ONhighBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then ((OverNightHigh - OverNightLow) * coeff_6) + OverNightLow

              else if HighestAll(ONlowBar) == MaxBar and OverNightLow > 0 and OverNightHigh > 0

              then OverNightHigh - ((OverNightHigh - OverNightLow) * coeff_6)

              else Double.NaN;

input showbubbles = no;
input showprice   = yes;
input bubblemover = 3;
def   b = bubblemover;
def   b1 = b + 1;

AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), coeff1, coeff_1 + " : " + (if !showprice then "" else AsText(coeff1)), Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), coeff2, coeff_2 + " : " + (if !showprice then "" else AsText(coeff2)), Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), coeff3, coeff_3 + " : " + (if !showprice then "" else AsText(coeff3)), Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), coeff4, coeff_4 + " : " + (if !showprice then "" else AsText(coeff4)), Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), coeff5, coeff_5 + " : " + (if !showprice then "" else AsText(coeff5)), Color.WHITE);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), coeff6, coeff_6 + " : " + (if !showprice then "" else AsText(coeff6)), Color.WHITE);


# 

# End Code GlobeX High Low with Fibs 
 
Here is an update to track prev values like that @autolox asked for.

View attachment 8348

Code:
#
# see https://usethinkscript.com/threads/how-to-get-current-days-premarket-high.695/
#
declare once_per_bar;

input PlotPreMktLinesHrsPastOpen = yes;
input ShowChartBubbles = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], nan);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], nan);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH =  if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
            then PMHighBar
            else nan;
plot PML =  if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
            then PMLowBar
            else nan;
plot PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0
             then (PMHighBar + PMLowBar) / 2
             else nan;


def prevPMHigh = if PMStart[-1] then PMHigh[1] else prevPMHigh[1];
plot pPMH = if !IsNaN(prevPMHigh) and prevPMHigh != 0 then prevPMHigh else nan;
pPMH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pPMH.AssignValueColor(PMH.TakeValueColor());

def prevPMLow = if PMStart[-1] then PMLow[1] else prevPMLow[1];
plot pPML = if !IsNaN(prevPMLow) and prevPMLow != 0 then prevPMLow else nan;
pPML.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pPML.AssignValueColor(PML.TakeValueColor());

def prevPMMid = if PMStart[-1] then ((PMHigh[1]+PMLow[1])/2) else prevPMMid[1];
plot pPMM = if !IsNaN(prevPMMid) and prevPMMid != 0 then prevPMMid else nan;
pPMM.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pPMM.AssignValueColor(PMMid.TakeValueColor());


AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PMHigh,
  "PM High",
  Color.GRAY,
  1);

AddChartBubble(ShowChartBubbles and bar == HighestAll(lowBar),
  PMLow,
  "PM Low",
  Color.GRAY,
  0);

AddChartBubble(ShowChartBubbles and bar == Max(HighestAll(highBar), HighestAll(lowBar)),
  (PMHighBar + PMLowBar) / 2,
  "PM Mid",
  Color.GRAY,
  1);

# end of script
Thanks for the great code, I've been trying to get this to work myself for a while, but the prev day's lines seem to be plotting a day off one day forward instead on the day of.

I tried using this code myself but couldn't get it to work at all
partial code, all the prev code the same.

plot PMH;
plot PML;
plot PMMid;

Switch (DisplayTime){
Case Day:
PMH = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
then PMHighBar
else nan;
PML = if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
then PMLowBar
else nan;
PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0
then (PMHighBar + PMLowBar) / 2
else nan;
Case Everyday:
PMH = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
then Highest(high(period = aggregationPeriod)[displace_amount], length)
else nan;
PML = if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
then Highest(low(period = aggregationPeriod)[displace_amount], length)
else nan;
PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0
then (PMHighBar + PMLowBar) / 2
else nan;
}

but didn't work at all.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
428 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top