Premarket After-market For ThinkOrSwim

TZYmsgr.png


I have a thinkscript (not written by me) that manually plots levels (RTH and Globex). I would like to limit it so that it only plots the levels for the current RTH and Globex session, not prior days where the levels are no longer relevant (ie the red circled plots in the attached pic). How can I do that? Thanks in advance!

def na = Double.NaN;
def timeStrRTH = (SecondsFromTime(930) > 0) and (SecondsFromTime(1700) < 0);
def timeStrETH = (SecondsFromTime(1700) > 0) AND (SecondsFromTime(930) < 0);
def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PMStart = RMhrs[1] and PMhrs;

input AlgoHigh = 4000;
input AlgoLow = 4800;
input AlgoClose = 4900;
input AlgoHighETH = 4000;
input AlgoLowETH = 4800;
input AlgoCloseETH = 4900;
input ES_offset = 0;
input MarginErrorHigh = 3.6;
input MarginErrorLow = 4.8;
input MarginErrorClose = 22.30;
input ShowCloud = yes;
input ShowTodayOnly = yes;

def today = !showTodayOnly or getDay() == getLastDay() and SecondsFromTime(09300) >= 0;

def AHRTH = AlgoHigh - ES_offset;
def ALRTH = AlgoLow - ES_offset;
def ACRTH = AlgoClose - ES_offset;
def AHETH = AlgoHighETH - ES_offset;
def ALETH = AlgoLowETH - ES_offset;
def ACETH = AlgoCloseETH - ES_offset;

plot AH;
plot AL;
plot AC;

if GetSymbol() == "/ES:XCME" {
AH = if timeStrRTH then AHRTH else if PMStart then AHETH else na ;
AL = if timeStrRTH then ALRTH else if PMStart then ALETH else na ;
AC = if timeStrRTH then ACRTH else if PMStart then ACETH else na ;
} else

if GetSymbol() == "SPX" {
AH = if timeStrRTH then AlgoHigh else na ;
AL = if timeStrRTH then AlgoLow else na ;
AC = if timeStrRTH then AlgoClose else na ;
} else {
AH = na;
AL = na;
AC = na;
}

def upperAH = AH + MarginErrorHigh;
def lowerAH = AH - MarginErrorHigh;
def upperAAH = AH + (MarginErrorHigh*2);
def lowerAAH = AH - (MarginErrorHigh*2);
def upperAL = AL + MarginErrorLow;
def lowerAL = AL - MarginErrorLow;
def upperAC = AC + (MarginErrorClose/2);
def lowerAC = AC - (MarginErrorClose/2);
def upperAAL = AL + (MarginErrorLow*2);
def lowerAAL = AL - (MarginErrorLow*2);


AddCloud(upperAH, lowerAH, Color.LIGHT_RED);
AddCloud(upperAAH, lowerAAH, CreateColor(255, 220, 210));
AddCloud(upperAL, lowerAL, Color.LIGHT_GREEN);
AddCloud(upperAC, lowerAC, Color.LIGHT_ORANGE);
AddCloud(upperAAL, lowerAAL, CreateColor(221, 251, 236));

AH.SetDefaultColor(Color.RED);
AH.SetLineWeight(1);
AH.HideBubble();

AL.SetDefaultColor(Color.GREEN);
AL.SetLineWeight(1);
AL.HideBubble();

AC.SetDefaultColor(Color.ORANGE);
AC.SetLineWeight(1);
 
This indicator for ThinkorSwim will automatically plot overnight High and Low on your chart. In addition, the indicator will also include Fibonacci retracement based on the highest and lowest values from pre-market.

This can be useful for anyone who often plays pre-market breakout or breakdown. You may want to check out this strategy as well.

uUiRGl0.png


thinkScript Code

Rich (BB code):
# 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;

# 

# End Code GlobeX High Low with Fibs 

Shareable Link

https://tos.mx/oNY5Yw
@BenTen : is it possible to add the coefficients and price as bubbles? Also, does this always plot from high to low?
 
This should show multiple developing aftermarket and premarket highs/lows
Could you please show how to add chartbubbles left or right w/offset, but only during real trading duration (offset > 1 will move bubbles into extended hours and that's fine)?
 
Could you please show how to add chartbubbles left or right w/offset, but only during real trading duration (offset > 1 will move bubbles into extended hours and that's fine)?

This has 2 sets of bubbles, post (AH, AL) and Pre Markets (PH, PL), that can be moved seperately at the bubblemover inputs.

Capture.jpg
Ruby:
input showtodayonly = yes;
script aftermarket {
    input openingTime = 1600;
    input closingTime = 0359;

    def sec1    = SecondsFromTime(openingTime);
    def sec2    = SecondsFromTime(closingTime);
    def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
    def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
    def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);

    def rhi        = if inRange and !inRange[1]
                 then high
                 else if inRange[1] and high > rhi[1]
                 then high else rhi[1];
    def rHighBar   = if inRange and high == rhi then 1 else 0;
    def rHighest   = if rHighBar  then rhi else rHighest[1];

    plot rangehigh = if rHighest > 0 then rHighest else Double.NaN;
    rangehigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    rangehigh.SetLineWeight(2);

    def rlow       = if inRange and !inRange[1]
                 then low
                 else if inRange[1] and low < rlow[1]
                 then low else rlow[1];
    def rLowBar    = if inRange and low == rlow then 1 else 0;
    def rlowest    = if rLowBar then rlow else rlowest[1];

    plot rangelow  = if rlowest > 0 then rlowest else Double.NaN;
    rangelow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    rangelow.SetLineWeight(2);

}

plot postmarketHigh = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket();
plot postmarketLow  = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket().rangelow;
plot premarketHigh  = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket("opening time" = 400, "closing time" = 929);
plot premarketLow   = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket("opening time" = 400, "closing time" = 929).rangelow;

postmarketHigh.SetDefaultColor(Color.CYAN);
postmarketLow.SetDefaultColor(Color.CYAN);
premarketHigh.SetDefaultColor(Color.MAGENTA);
premarketLow.SetDefaultColor(Color.MAGENTA);

postmarketHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
postmarketLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premarketHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premarketLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showbubbles = yes;
input bubblemover_post = 2;
def b  = bubblemover_post;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), postmarketHigh[b1], "AH", Color.CYAN);
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), postmarketLow[b1], "AL", Color.CYAN);
input bubblemover_pre = 5;
def bb  = bubblemover_pre;
def bb1 = bb + 1;
AddChartBubble(showbubbles and IsNaN(close[bb]) and !IsNaN(close[bb1]), premarketHigh[bb1], "PH", Color.MAGENTA);
AddChartBubble(showbubbles and IsNaN(close[bb]) and !IsNaN(close[bb1]), premarketLow[bb1], "PL", Color.MAGENTA);
 
  • Like
Reactions: bmn
TZYmsgr.png


I have a thinkscript (not written by me) that manually plots levels (RTH and Globex). I would like to limit it so that it only plots the levels for the current RTH and Globex session, not prior days where the levels are no longer relevant (ie the red circled plots in the attached pic). How can I do that? Thanks in advance!

def na = Double.NaN;
def timeStrRTH = (SecondsFromTime(930) > 0) and (SecondsFromTime(1700) < 0);
def timeStrETH = (SecondsFromTime(1700) > 0) AND (SecondsFromTime(930) < 0);
def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PMStart = RMhrs[1] and PMhrs;

input AlgoHigh = 4000;
input AlgoLow = 4800;
input AlgoClose = 4900;
input AlgoHighETH = 4000;
input AlgoLowETH = 4800;
input AlgoCloseETH = 4900;
input ES_offset = 0;
input MarginErrorHigh = 3.6;
input MarginErrorLow = 4.8;
input MarginErrorClose = 22.30;
input ShowCloud = yes;
input ShowTodayOnly = yes;

def today = !showTodayOnly or getDay() == getLastDay() and SecondsFromTime(09300) >= 0;

def AHRTH = AlgoHigh - ES_offset;
def ALRTH = AlgoLow - ES_offset;
def ACRTH = AlgoClose - ES_offset;
def AHETH = AlgoHighETH - ES_offset;
def ALETH = AlgoLowETH - ES_offset;
def ACETH = AlgoCloseETH - ES_offset;

plot AH;
plot AL;
plot AC;

if GetSymbol() == "/ES:XCME" {
AH = if timeStrRTH then AHRTH else if PMStart then AHETH else na ;
AL = if timeStrRTH then ALRTH else if PMStart then ALETH else na ;
AC = if timeStrRTH then ACRTH else if PMStart then ACETH else na ;
} else

if GetSymbol() == "SPX" {
AH = if timeStrRTH then AlgoHigh else na ;
AL = if timeStrRTH then AlgoLow else na ;
AC = if timeStrRTH then AlgoClose else na ;
} else {
AH = na;
AL = na;
AC = na;
}

def upperAH = AH + MarginErrorHigh;
def lowerAH = AH - MarginErrorHigh;
def upperAAH = AH + (MarginErrorHigh*2);
def lowerAAH = AH - (MarginErrorHigh*2);
def upperAL = AL + MarginErrorLow;
def lowerAL = AL - MarginErrorLow;
def upperAC = AC + (MarginErrorClose/2);
def lowerAC = AC - (MarginErrorClose/2);
def upperAAL = AL + (MarginErrorLow*2);
def lowerAAL = AL - (MarginErrorLow*2);


AddCloud(upperAH, lowerAH, Color.LIGHT_RED);
AddCloud(upperAAH, lowerAAH, CreateColor(255, 220, 210));
AddCloud(upperAL, lowerAL, Color.LIGHT_GREEN);
AddCloud(upperAC, lowerAC, Color.LIGHT_ORANGE);
AddCloud(upperAAL, lowerAAL, CreateColor(221, 251, 236));

AH.SetDefaultColor(Color.RED);
AH.SetLineWeight(1);
AH.HideBubble();

AL.SetDefaultColor(Color.GREEN);
AL.SetLineWeight(1);
AL.HideBubble();

AC.SetDefaultColor(Color.ORANGE);
AC.SetLineWeight(1);


This is one method that generally works to limit the plots to just the last day/one. Just add the 'if statement' to the beginning of each plot.

Ruby:
input ShowTodayOnly = yes;     
if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else

Code:
def na = Double.NaN;
def timeStrRTH = (SecondsFromTime(930) > 0) and (SecondsFromTime(1700) < 0);
def timeStrETH = (SecondsFromTime(1700) > 0) AND (SecondsFromTime(930) < 0);
def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PMStart = RMhrs[1] and PMhrs;

input AlgoHigh = 4000;
input AlgoLow = 4800;
input AlgoClose = 4900;
input AlgoHighETH = 4000;
input AlgoLowETH = 4800;
input AlgoCloseETH = 4900;
input ES_offset = 0;
input MarginErrorHigh = 3.6;
input MarginErrorLow = 4.8;
input MarginErrorClose = 22.30;
input ShowCloud = yes;
input ShowTodayOnly = yes;

def today = !showTodayOnly or getDay() == getLastDay() and SecondsFromTime(0930) >= 0;

def AHRTH = AlgoHigh - ES_offset;
def ALRTH = AlgoLow - ES_offset;
def ACRTH = AlgoClose - ES_offset;
def AHETH = AlgoHighETH - ES_offset;
def ALETH = AlgoLowETH - ES_offset;
def ACETH = AlgoCloseETH - ES_offset;

plot AH;
plot AL;
plot AC;

if GetSymbol() == "/ES:XCME" {
AH = if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else if timeStrRTH then AHRTH else if PMStart then AHETH else na ;
AL = if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else if timeStrRTH then ALRTH else if PMStart then ALETH else na ;
AC = if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else if timeStrRTH then ACRTH else if PMStart then ACETH else na ;

} else
if GetSymbol() == "SPX" {
AH = if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else if timeStrRTH then AlgoHigh else na ;
AL = if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else if timeStrRTH then AlgoLow else na ;
AC = if showtodayOnly and !isnan(close(period=aggregationPeriod.DAY)[-1]) then double.nan else if timeStrRTH then AlgoClose else na ;

} else {
AH = na;
AL = na;
AC = na;
}

def upperAH = AH + MarginErrorHigh;
def lowerAH = AH - MarginErrorHigh;
def upperAAH = AH + (MarginErrorHigh*2);
def lowerAAH = AH - (MarginErrorHigh*2);
def upperAL = AL + MarginErrorLow;
def lowerAL = AL - MarginErrorLow;
def upperAC = AC + (MarginErrorClose/2);
def lowerAC = AC - (MarginErrorClose/2);
def upperAAL = AL + (MarginErrorLow*2);
def lowerAAL = AL - (MarginErrorLow*2);


AddCloud(upperAH, lowerAH, Color.LIGHT_RED);
AddCloud(upperAAH, lowerAAH, CreateColor(255, 220, 210));
AddCloud(upperAL, lowerAL, Color.LIGHT_GREEN);
AddCloud(upperAC, lowerAC, Color.LIGHT_ORANGE);
AddCloud(upperAAL, lowerAAL, CreateColor(221, 251, 236));

AH.SetDefaultColor(Color.RED);
AH.SetLineWeight(1);
AH.HideBubble();

AL.SetDefaultColor(Color.GREEN);
AL.SetLineWeight(1);
AL.HideBubble();

AC.SetDefaultColor(Color.ORANGE);
AC.SetLineWeight(1);
 
@BenTen : is it possible to add the coefficients and price as bubbles? Also, does this always plot from high to low?

Here are bubbles applied to Ben's post of Mobius' script. You can move the bubbles left/right and optionally display the price in the bubble with the coeff.

Capture.jpg
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 = yes;
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);

coeff1.HideBubble();
coeff2.HideBubble();
coeff3.HideBubble();
coeff4.HideBubble();
coeff5.HideBubble();
coeff6.HideBubble();
# 

# End Code GlobeX High Low with Fibs 
 
This has 2 sets of bubbles, post (AH, AL) and Pre Markets (PH, PL), that can be moved seperately at the bubblemover inputs.
Thanks @SleepyZ for adding code for bubbles. I was actually thinking if it's possible to "clip-off" bubbles at start/end (left/right) of the real trading duration.

Something like this Up/Down arrows are the desired bubbles' locations and left and right arrows indicate how increasing offset would move those bubbles.

Is that sort of placement possible?
 
Thanks @SleepyZ for adding code for bubbles. I was actually thinking if it's possible to "clip-off" bubbles at start/end (left/right) of the real trading duration.

Something like this Up/Down arrows are the desired bubbles' locations and left and right arrows indicate how increasing offset would move those bubbles.

Is that sort of placement possible?

This appears to be what you requested in your image. The prior day's bubbles will move in opposite directions based upon the input bubblemover_prior, set at 8 in the image below.

Capture.jpg
Ruby:
input showtodayonly = yes;
script aftermarket {
    input openingTime = 1600;
    input closingTime = 0359;

    def sec1    = SecondsFromTime(openingTime);
    def sec2    = SecondsFromTime(closingTime);
    def isTime1 = (sec1 >= 0 and sec1[1] < 0) or (sec1 < sec1[1] and sec1 >= 0);
    def isTime2 = (sec2 >= 0 and sec2[1] < 0) or (sec2 < sec2[1] and sec2 >= 0);
    def inRange = CompoundValue(1, if isTime1 then 1 else if isTime2 then 0 else inRange[1], 0);

    def rhi        = if inRange and !inRange[1]
                 then high
                 else if inRange[1] and high > rhi[1]
                 then high else rhi[1];
    def rHighBar   = if inRange and high == rhi then 1 else 0;
    def rHighest   = if rHighBar  then rhi else rHighest[1];

    plot rangehigh = if rHighest > 0 then rHighest else Double.NaN;
    rangehigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    rangehigh.SetLineWeight(2);

    def rlow       = if inRange and !inRange[1]
                 then low
                 else if inRange[1] and low < rlow[1]
                 then low else rlow[1];
    def rLowBar    = if inRange and low == rlow then 1 else 0;
    def rlowest    = if rLowBar then rlow else rlowest[1];

    plot rangelow  = if rlowest > 0 then rlowest else Double.NaN;
    rangelow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
    rangelow.SetLineWeight(2);

}

plot postmarketHigh = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket();
plot postmarketLow  = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket().rangelow;
plot premarketHigh  = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket("opening time" = 400, "closing time" = 929);
plot premarketLow   = if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1]) then Double.NaN else aftermarket("opening time" = 400, "closing time" = 929).rangelow;

postmarketHigh.SetDefaultColor(Color.CYAN);
postmarketLow.SetDefaultColor(Color.CYAN);
premarketHigh.SetDefaultColor(Color.MAGENTA);
premarketLow.SetDefaultColor(Color.MAGENTA);

postmarketHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
postmarketLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premarketHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premarketLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#Prior Day's Bubbles-------------------------------------------

input showbubbles = yes;
input bubblemover_prior = 8;
def bb  = bubblemover_prior;
def bb1 = bb + 1;
AddChartBubble(showbubbles  and GetTime()[bb + 1] crosses above RegularTradingEnd(GetYYYYMMDD()[bb1 + 1]), postmarketHigh[bb1 + 1], "PAH", Color.CYAN);
AddChartBubble(showbubbles  and GetTime()[-bb + 1] crosses above RegularTradingStart(GetYYYYMMDD()[-bb + 1]), postmarketHigh[-bb1 + 1], "PAH", Color.CYAN);
AddChartBubble(showbubbles  and GetTime()[bb + 1] crosses above RegularTradingEnd(GetYYYYMMDD()[bb1 + 1]), postmarketlow[bb1 + 1], "PAH", Color.CYAN);
AddChartBubble(showbubbles  and GetTime()[-bb + 1] crosses above RegularTradingStart(GetYYYYMMDD()[-bb + 1]), postmarketlow[-bb1 + 1], "PAH", Color.CYAN);

AddChartBubble(showbubbles  and GetTime()[bb + 1] crosses above RegularTradingEnd(GetYYYYMMDD()[bb1 + 1]), premarketHigh[bb1 + 1], "PPH", Color.magenta);
AddChartBubble(showbubbles  and GetTime()[-bb + 1] crosses above RegularTradingStart(GetYYYYMMDD()[-bb + 1]), premarketHigh[-bb1 + 1], "PPH", Color.magenta);
AddChartBubble(showbubbles  and GetTime()[bb + 1] crosses above RegularTradingEnd(GetYYYYMMDD()[bb1 + 1]), premarketlow[bb1 + 1], "PPL", Color.magenta);
AddChartBubble(showbubbles  and GetTime()[-bb + 1] crosses above RegularTradingStart(GetYYYYMMDD()[-bb + 1]), premarketlow[-bb1 + 1], "PPL", Color.magenta);

#Today's bubbles-------------------------------------------------------

input showtodaysbubbles = yes;
input bubblemover_post = 2;
def b  = bubblemover_post;
def b1 = b + 1;
AddChartBubble(showtodaysbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), postmarketHigh[b1], "AH", Color.CYAN);
AddChartBubble(showtodaysbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), postmarketLow[b1], "AL", Color.CYAN);
input bubblemover_pre = 5;
def b_  = bubblemover_pre;
def b_1 = b_ + 1;
AddChartBubble(showtodaysbubbles and IsNaN(close[b_]) and !IsNaN(close[b_1]), premarketHigh[bb1], "PH", Color.MAGENTA);
AddChartBubble(showtodaysbubbles and IsNaN(close[b_]) and !IsNaN(close[b_1]), premarketLow[bb1], "PL", Color.MAGENTA);
 
Last edited:
  • Love
Reactions: bmn
hello, Im looking for an indicator that automatically marks the premarket high and low with a labeled horizontal line and also lines that mark the previous days high and low with labels on the horizontal line. id like each horizontal line to extend until market close for current day. then every day it re-labels the premarket high lows and previous day high lows. id prefer the lines to be a solid white line with maybe the options to change their colors. essentially just automatically charting these two levels for me daily. any assistance would be greatly appreciated. thank you
 
hello, Im looking for an indicator that automatically marks the premarket high and low with a labeled horizontal line and also lines that mark the previous days high and low with labels on the horizontal line. id like each horizontal line to extend until market close for current day. then every day it re-labels the premarket high lows and previous day high lows. id prefer the lines to be a solid white line with maybe the options to change their colors. essentially just automatically charting these two levels for me daily. any assistance would be greatly appreciated. thank you

There is quite a lot available already on your request. Here are a few threads for a start
https://usethinkscript.com/threads/pre-market-after-market-for-thinkorswim.75/
https://usethinkscript.com/threads/previous-day-high-and-low-breakout-indicator-for-thinkorswim.154/
 
@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
thank you for this. is there also a way to tweak this to include to extremes on previous days AH high/lows? so instead of starting the plots from midnight EST, to start it from previous day 4p EST?
 
thank you for this. is there also a way to tweak this to include to extremes on previous days AH high/lows? so instead of starting the plots from midnight EST, to start it from previous day 4p EST?
Could you provide more detail as to the quantitative logic that defines your request?
Provide a marked-up screenshot of what a chart that displays what all your conditions would look like.
Questions without images are much less likely to get a response!
Unsure of how to upload screenshots to the forum, Here are directions.
And here are some Cool Tips For Creating The Perfect Post.
 
Hi,

Was just wondering if someone has a watchlist or could create one where the column will light up and stay lit if the price crosses below the premarket high. If price never reaches above premarket high then the column should stay dark/black.

Thanks.
 
Hi,

Was just wondering if someone has a watchlist or could create one where the column will light up and stay lit if the price crosses below the premarket high. If price never reaches above premarket high then the column should stay dark/black.

Thanks.
HI guys, is there a Watchlist column that will display PMH break or PML break?

This thread contains all the pre-market answers on this forum. Perhaps you will find something here that will help you create what you are looking for.
 
Last edited:
Might as well add the low and the mid and fix issue with drawing lines on 0. It should be possible I think to eliminate that HighestAll call (expensive). Here's my addition for all this sans a HighestAll fix....

I was actually just thinking about this for my charts...I will modify a bit further to change colors, line types, etc. But nice solution @horserider.

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

input PlotPreMktLinesHrsPastOpen = 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], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
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;

# end of script
This script doesn't show PM Low and PM Mid if chart only shows 1 trading day. (Time interval set to "today")
Any idea why and how it can be fixed?
 
I'm aware, thanks. The image shown is an intraday chart. The script does not show PM Low and PM Mid if the intraday chart only shows 1 trading day.
Because you don't have enough data. Extend it out, solves your problem.
 

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
110 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