Premarket After-market For ThinkOrSwim

Last edited by a moderator:
Great code, really appreciate it. Is there a way to combine this with a Previous day High / Low / Close / and current day Open? Trying to use this intraday on 2/5min charts. Thanks.
Thanks appreciate it. I actually figured it out myself. Now I'm trying to figure out if you can move the position of the bubbles more to the right because sometimes they get in the way. Sorry for all the commented out code, didn't really clean it out yet.
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
#input displace = -1;
input displace_amount = {default zero, negative_one};
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], 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];


def displacement;
switch (displace_amount) {
case zero:
    displacement = 0;
case negative_one:
    displacement = -1;
}

input showOnlyLastPeriod = yes;

plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayOpen = Double.NaN;
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayOpen = Highest(open(period = aggregationPeriod)[displace_amount], length);
    PrevDayHigh = Highest(high(period = aggregationPeriod)[displace_amount], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[displace_amount], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[displace_amount], length);
}

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayOpen,
  "Prev Day Open",
  Color.yellow,
  1);
#PrevDayOpen.SetDefaultColor(Color.yellow);
#PrevDayOpen.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayHigh,
  "Prev Day High",
  Color.green,
  1);
#PrevDayHigh.SetDefaultColor(Color.green);
#PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayLow,
  "Prev Day Low",
  Color.red,
  1);
#PrevDayLow.SetDefaultColor(Color.red);
#PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayClose,
  "Prev Day Close",
  Color.white,
  1);
#PrevDayClose.SetDefaultColor(color.whITE);
#PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayClose.SetStyle(Curve.LONG_DASH);
 
Thanks appreciate it. I actually figured it out myself. Now I'm trying to figure out if you can move the position of the bubbles more to the right because sometimes they get in the way. Sorry for all the commented out code, didn't really clean it out yet.
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
#input displace = -1;
input displace_amount = {default zero, negative_one};
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], 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];


def displacement;
switch (displace_amount) {
case zero:
    displacement = 0;
case negative_one:
    displacement = -1;
}

input showOnlyLastPeriod = yes;

plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayOpen = Double.NaN;
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayOpen = Highest(open(period = aggregationPeriod)[displace_amount], length);
    PrevDayHigh = Highest(high(period = aggregationPeriod)[displace_amount], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[displace_amount], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[displace_amount], length);
}

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayOpen,
  "Prev Day Open",
  Color.yellow,
  1);
#PrevDayOpen.SetDefaultColor(Color.yellow);
#PrevDayOpen.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayHigh,
  "Prev Day High",
  Color.green,
  1);
#PrevDayHigh.SetDefaultColor(Color.green);
#PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayLow,
  "Prev Day Low",
  Color.red,
  1);
#PrevDayLow.SetDefaultColor(Color.red);
#PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PrevDayClose,
  "Prev Day Close",
  Color.white,
  1);
#PrevDayClose.SetDefaultColor(color.whITE);
#PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayClose.SetStyle(Curve.LONG_DASH);

See if this helps placing your chart bubbles where you want them. It includes 3 bubble placement methods for you to choose.

The leftbubbles and expansionbubbles can also be moved left/right at the input bubblemover. If choose rightedgebubbles or expansionbubbles, make sure your have enought space in chart settings/time axis for your bubbles to display.

You can replace the bubblemethod in the addchartbubble() code with the method you choose if you like.

Also I changed your displace_amount from a switch to an integer so you can easily change the displacement. You had 0 and -1 options. Zero would be the current day, -1 would be a future day and 1 (the default I imade) would be the Previous Day's data.

The image below shows the bubble method as rightedgebubbles.
Capture.jpg
Ruby:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
#input displace = -1;
input displace_amount = 1;
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], 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];


def displacement = displace_amount;

input showOnlyLastPeriod = yes;

plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayOpen = Double.NaN;
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayOpen = Highest(open(period = aggregationPeriod)[displace_amount], length);
    PrevDayHigh = Highest(high(period = aggregationPeriod)[displace_amount], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[displace_amount], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[displace_amount], length);
}

#Bubble Placement and Movement------------------------------------
input bubblemover = 5;
def b = bubblemover;
def b1 = b + 1;

input bubblemethod   = {default expansionbubbles, rightedgebubbles, leftbubbles};
def bubbletype;
switch (bubblemethod){
case expansionbubbles:
    bubbletype = IsNaN(close[b]) and !IsNaN(close[b1]);
case rightedgebubbles:
    bubbletype = bar == HighestAll(bar);
case leftbubbles:
    bubbletype = bar[b] == HighestAll(highBar[b]);
}
#------------------------------------------------------------------------

AddChartBubble(ShowChartBubbles and bubbletype, #bar == HighestAll(highBar),
  PrevDayOpen[b],
  "Prev Day Open",
  Color.YELLOW,
  1);
#PrevDayOpen.SetDefaultColor(Color.yellow);
#PrevDayOpen.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bubbletype, # bar == HighestAll(highBar),
  PrevDayHigh,
  "Prev Day High",
  Color.GREEN,
  1);
#PrevDayHigh.SetDefaultColor(Color.green);
#PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bubbletype, #bar == HighestAll(highBar),
  PrevDayLow,
  "Prev Day Low",
  Color.RED,
  1);
#PrevDayLow.SetDefaultColor(Color.red);
#PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayOpen.SetStyle(Curve.LONG_DASH);

AddChartBubble(ShowChartBubbles and bubbletype, # bar == HighestAll(highBar),
  PrevDayClose,
  "Prev Day Close",
  Color.WHITE,
  1);
#PrevDayClose.SetDefaultColor(color.whITE);
#PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
#PrevDayClose.SetStyle(Curve.LONG_DASH);
 
See if this helps placing your chart bubbles where you want them. It includes 3 bubble placement methods for you to choose.

The leftbubbles and expansionbubbles can also be moved left/right at the input bubblemover. If choose rightedgebubbles or expansionbubbles, make sure your have enought space in chart settings/time axis for your bubbles to display.

You can replace the bubblemethod in the addchartbubble() code with the method you choose if you like.

Also I changed your displace_amount from a switch to an integer so you can easily change the displacement. You had 0 and -1 options. Zero would be the current day, -1 would be a future day and 1 (the default I imade) would be the Previous Day's data.

The image below shows the bubble method as rightedgebubbles.
Thanks SleepyZ, I finally got a chance to play with it. It seems to mostly work but sometimes only the lines show up without bubbles. I don't know how to paste chart pictures on here to show you. I was able to use the leftbubbles with -25 position just fine and works great. The examples I was going to show you was on a 5min chart with premkt for AAPL and LCID, maybe you can bring it up and see if it's the same for you. Otherwise let me know how I can paste chart pictures on here.
 
Thanks SleepyZ, I finally got a chance to play with it. It seems to mostly work but sometimes only the lines show up without bubbles. I don't know how to paste chart pictures on here to show you. I was able to use the leftbubbles with -25 position just fine and works great. The examples I was going to show you was on a 5min chart with premkt for AAPL and LCID, maybe you can bring it up and see if it's the same for you. Otherwise let me know how I can paste chart pictures on here.
Both AAPL and LCID plot fine for all 3 examples set at default settings as shown in the image below. Likely you may not have enough chart settings, time axis length set to display the bubbles on your chart, especially in the right expansion. It would help you to shorten the text in the bubbles to help with the bubble display. For example, use PDH, PDL PDC and PDO instead of your text.

 
Does anyone know how to make it so it shows multiple of the previous days PMH and PML. Right now this only shows the current day.


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


input PlotPreMktLinesHrsPastOpen = yes;
input ShowChartBubbles = yes;
input ShowTodayOnly = no;

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;


# end of script
 
Does anyone know how to make it so it shows multiple of the previous days PMH and PML. Right now this only shows the current day.


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


input PlotPreMktLinesHrsPastOpen = yes;
input ShowChartBubbles = yes;
input ShowTodayOnly = no;

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;


# end of script

This should show multiple developing aftermarket and premarket highs/lows

Capture.jpg
Ruby:
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 = aftermarket();
plot postmarketLow  = aftermarket().rangelow;
plot premarketHigh  = aftermarket("opening time" = 400, "closing time" = 929);
plot premarketLow   = 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);
 
@SleepyZ , this is great, thank you! Could you please code for it to show/hide previous days' AH-PM plots as well based on an input (e.g. input showTodayOnly = no; )?

Here is your request

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);
 
  • Like
Reactions: bmn
Thank you for these awesome scripts. I used the advanced search to look for "yesterday" keyword so I can add yesterday OHLC onto today 5m chart. But I think secondary aggregation is not allowed in TOS. So this can not be done correct? If there is a way to add yesterday's OHLC onto today chart, will please share the codes?
 
Thank you for these awesome scripts. I used the advanced search to look for "yesterday" keyword so I can add yesterday OHLC onto today 5m chart. But I think secondary aggregation is not allowed in TOS. So this can not be done correct? If there is a way to add yesterday's OHLC onto today chart, will please share the codes?

The following prior day's HLCO can be plotted on a chart. The issue with secondary agg's in TOS is with scans.

Ruby:
input showtodayonly = yes;
input showclose     = yes;
input showhigh      = yes;
input showlow       = yes;
plot dataclose = if showclose==yes
                 then if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1])
                      then Double.NaN
                      else close(period = AggregationPeriod.DAY)[1]
                 else double.nan;
dataclose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
dataclose.SetDefaultColor(Color.MAGENTA);
plot datahigh = if showhigh==yes
                then if showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1])
                     then Double.NaN
                     else high(period = AggregationPeriod.DAY)[1]
                else double.nan;
datahigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
datahigh.SetDefaultColor(Color.GREEN);
plot datalow = if showlow==yes
               then if  showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1])
                    then Double.NaN
                    else low(period = AggregationPeriod.DAY)[1]
               else double.nan;
datalow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
datalow.SetDefaultColor(Color.RED);
plot dataopen = if showlow==yes
                then if  showtodayonly and !IsNaN(close(period = AggregationPeriod.DAY)[-1])
                     then Double.NaN
                     else open(period = AggregationPeriod.DAY)[1]
                else double.nan;
dataopen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
dataopen.SetDefaultColor(Color.WHITE);
 
@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
I know this was an old post, when I load this it scrunches the chart to a flat line. I am trying to figure out why this happens? It doesn't happen to the OG Overnight High Low one though. Thank you.
 
for the TOS watchlist, I would like to combine Premarket high/low and Previous day High/low. This is the code I want to add. However, it does not show. Is anyone make a watchlist, please

input color_candle = yes;
def above;
def below;
def underMid;
def overMid;
above = if close>PrevDayHigh then 1 else 0;
below = if close<PrevDayLow then 1 else 0;
underMid = if close>PMHighBar and close<=PrevDayHigh then 1 else 0;
overMid = if close>PMLowBar and close<=PrevDayLow then 1 else 0;
plot scan = above;
AssignPriceColor(if !color_candle then color.current else if above == 1 then Color.GREEN
else if below == 1 then Color.RED else if overMid == 1 then Color.Gray else Color.BLUE);
assignBackgroundColor(if !color_candle then color.current else if above == 1 then
Color.GREEN else if below == 1 then Color.RED else if overMid == 1 then Color.Gray else
Color.BLUE);
AddLabel(yes,if above ==1 then "A" else if below ==1 then "Z" else if overMid
==1 then "Ovr" else "Und", Color.BLACK);
 
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 : Does this always plot from high to low? Is it possible to put the coefficients & price on the right side or leftside as shown in the figure?

Also: i want to automatically plot weekly/monthly/prior day fibs on top of the pre market fibs...is it possible to do that?


1Hch13H.png
 
Both AAPL and LCID plot fine for all 3 examples set at default settings as shown in the image below. Likely you may not have enough chart settings, time axis length set to display the bubbles on your chart, especially in the right expansion. It would help you to shorten the text in the bubbles to help with the bubble display. For example, use PDH, PDL PDC and PDO instead of your text.
I finally figured out something but don't understand why it works this way. So I changed the text but nothing happened differently. I noticed that on my chart tab it worked fine, but on my trade tab, it didn't. Then I noticed that I had 2 different time frames, so it seems to display correctly only on a 2min or 1min, but once I move higher the bubbles disappear. This is with the standard settings and 1-day daily aggregation. I've checked all the other settings and can't seem to find anything else different. Any ideas? Thanks again for all the help, I still haven't had a chance to integrate premarket as well into the same code.
 
I finally figured out something but don't understand why it works this way. So I changed the text but nothing happened differently. I noticed that on my chart tab it worked fine, but on my trade tab, it didn't. Then I noticed that I had 2 different time frames, so it seems to display correctly only on a 2min or 1min, but once I move higher the bubbles disappear. This is with the standard settings and 1-day daily aggregation. I've checked all the other settings and can't seem to find anything else different. Any ideas? Thanks again for all the help, I still haven't had a chance to integrate premarket as well into the same code.

Since you mentioned timeframes, if you have a chart timeframe that is higher than the lowest bubbles timeframe, then TOS will cause the bubbles to disappear. For example, if you are trying to display the previous day's prices on a weekly chart that you are viewing, then the bubbles will disappear.

Otherwise, you need to provide more specific information about the code used, chart settings, etc for us to understand what any problem might be occurring.
 
Hello, Is it possible to keep the high/low levels even I turn off the extended hours? when trading with 5/15min chart I use the EMAs but w/o the extended market session. Thanks a lot.
 

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