Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day + ATR Lines for ThinkorSwim

@Wiinii @samer800 @horserider @halcyonguy Can one of you please write this so we can only show market hours for Previous Day High and Previous Day Low? Maybe have an option to select. I have tried for a while now and have been unsuccessful. At this time this study will show Previous Days Premarket High and Pre Market Low for PDH and PDL. Thanks in advance. 🙏

Here is what I attempted to write and it doesn't work. Can someone help with this? or Is it possible to do?

Code:
# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day + ATR Lines
# Created by Wiinii
# V1.6
# Some code based on code by Mobius (premarket) and TraderKevin (ATR lines
# https://usethinkscript.com/threads/previous-day-high-low-close-premarket-high-low-high-low-open-of-day-for-thinkorswim.13139/

declare hide_on_daily;

input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at = {default Expansion, Time};
input locate_bubbles_at_time = 800;
input BarsFromExpansion = 1;
input ShowPricesInBubbles = yes;

def bn = BarNumber();
def na = Double.NaN;
def h  = high;
def l  = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def marketOpen = SecondsFromTime(900) >= 0 and SecondsTillTime(1600) >= 0;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
def isExpansion = locate_bubbles_at == locate_bubbles_at.Expansion and IsNaN(close);
def firstExpansionBar = if !IsNaN(close[-1]) and isExpansion then 1 else if isExpansion then firstExpansionBar[1] + 1 else 0;
def BubbleLocation = if locate_bubbles_at == locate_bubbles_at.Time then timeopen else isExpansion and firstExpansionBar == BarsFromExpansion;

#----- Previous Day High/Low/Close -----#

def PD_HighValue;
def PD_LowValue;
def PD_CloseValue;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PD_HighValue = na;
    PD_LowValue = na;
    PD_CloseValue = na;
} else {
    PD_HighValue = if marketOpen then Highest(high(period = aggregationPeriod)[-displace], length) else na;
    PD_LowValue = if marketOpen then Lowest(low(period = aggregationPeriod)[-displace], length) else na;
    PD_CloseValue = if marketOpen then close(period = aggregationPeriod)[-displace] else na;
}

plot PD_High = PD_HighValue;
plot PD_Low = PD_LowValue;
plot PD_Close = PD_CloseValue;

PD_High.SetDefaultColor(Color.DARK_ORANGE);
PD_High.SetStyle(Curve.LONG_DASH);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(Color.DARK_ORANGE);
PD_Low.SetStyle(Curve.LONG_DASH);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(Color.WHITE);
PD_Close.SetStyle(Curve.LONG_DASH);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

DefineGlobalColor("PD_High", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_High, "PDH: " + (if ShowPricesInBubbles then AsText(PD_High) else ""), GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_Low, "PDL: " + (if ShowPricesInBubbles then AsText(PD_Low) else ""), GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", Color.WHITE);
AddChartBubble(ShowBubbles and BubbleLocation, PD_Close, "PDC: " + (if ShowPricesInBubbles then AsText(PD_Close) else ""), GlobalColor("PD_Close"));

PD_High.HideBubble();
PD_Low.HideBubble();
PD_Close.HideBubble();


#----- Premarket High/Low -----# Thanks to Mobius

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

def vol = if GlobeX and !GlobeX[1]
then v
else if GlobeX
then vol[1] + v
else na;

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 bn
else na;

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 bn
else na;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];

plot PM_High;
plot PM_Low;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PM_High = na;
    PM_Low = na;
} else {
    PM_High = if OverNightHigh > 0 then OverNightHigh else na;
    PM_Low = if OverNightLow > 0 then OverNightLow else na;
}

#PM_High.SetHiding(!PlotOverNightExtremes);
PM_High.SetLineWeight(2);
PM_High.SetDefaultColor(Color.CYAN);
PM_High.SetStyle(Curve.LONG_DASH);
PM_High.HideBubble();
PM_High.HideTitle();

#PM_Low.SetHiding(!PlotOverNightExtremes);
PM_Low.SetStyle(Curve.LONG_DASH);
PM_Low.SetDefaultColor(Color.CYAN);
PM_Low.HideBubble();
PM_Low.HideTitle();

DefineGlobalColor("PM_High", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONhighBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_High, "PMH: " + (if ShowPricesInBubbles then AsText(PM_High) else ""), GlobalColor("PM_High"));

DefineGlobalColor("PM_Low", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_Low, "PML: " + (if ShowPricesInBubbles then AsText(PM_Low) else ""), GlobalColor("PM_Low"), no);


#----- Today Open/High/Low -----#


plot High_of_Day;
plot Low_of_Day;
plot DayOpen;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DayOpen = na;
    High_of_Day = na;
    Low_of_Day = na;
} else {
    DayOpen = open(period = aggregationPeriod)[0];
    High_of_Day = Highest(high(period = aggregationPeriod), length);
    Low_of_Day = Lowest(low(period = aggregationPeriod), length);
}

DayOpen.SetDefaultColor (Color.GRAY);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();

High_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();

Low_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();

DefineGlobalColor("Open", Color.LIGHT_GRAY);
AddChartBubble(ShowBubbles and BubbleLocation, DayOpen, "Open: " + (if ShowPricesInBubbles then AsText(DayOpen) else ""), GlobalColor("Open"));

DefineGlobalColor("High_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, High_of_Day, "HOD: " + (if ShowPricesInBubbles then AsText(High_of_Day) else ""), GlobalColor("High_of_Day"));

DefineGlobalColor("Low_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, Low_of_Day, "LOD: " + (if ShowPricesInBubbles then AsText(Low_of_Day) else ""), GlobalColor("Low_of_Day"), no);

#----- ATR Lines -----# Thaanks to TraderKevin
input showAtrLines = Yes;
input atrLinesFrom = {default pdc, dayOpen};
input ATRlength = 14;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRlength);

plot hatr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen + ATR else PD_Close + ATR;
plot latr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen - ATR else PD_Close - ATR;

hatr.SetLineWeight(5);
hatr.SetDefaultColor(Color.RED);
hatr.SetStyle(Curve.LONG_DASH);
hatr.HideBubble();
hatr.HideTitle();
hatr.SetHiding(showAtrLines == no);

latr.SetLineWeight(5);
latr.SetStyle(Curve.LONG_DASH);
latr.SetDefaultColor(Color.GREEN);
latr.HideBubble();
latr.HideTitle();
latr.SetHiding(showAtrLines == no);

DefineGlobalColor("hatr", Color.PINK);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, hatr, "ATRH: " + (if ShowPricesInBubbles then AsText(hatr) else ""), GlobalColor("hatr"));

DefineGlobalColor("latr", Color.LIGHT_GREEN);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, latr, "ATRL: " + (if ShowPricesInBubbles then AsText(latr) else ""), GlobalColor("latr"), no);;
replace marketOpen and timeOpen with this

CSS:
def timeopen = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEND(GetYYYYMMDD());
 
replace marketOpen and timeOpen with this

CSS:
def timeopen = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and GetTime() <= RegularTradingEND(GetYYYYMMDD());
@samer800 , This is still pulling pre market highs and lows as PDH and PDL.

@samer800 See attached image. It appears as though it is still picking up Pre market somehow. Is there a way to fix this?
 

Attachments

  • Screenshot 2023-08-23 194818.jpg
    Screenshot 2023-08-23 194818.jpg
    183.1 KB · Views: 434
Last edited by a moderator:
@samer800 , This is still pulling pre market highs and lows as PDH and PDL.

@samer800 See attached image. It appears as though it is still picking up Pre market somehow. Is there a way to fix this?
Can anyone that knows how to code, change this. I do not want Previous Days Pre Market H/L to show as Previous days High/Low.
 
I added some fibs between the PMH and PML. And extensions up to 200% for fans of fibs.

1695263220633.png


Code:
# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day + ATR Lines
# Created by Wiinii
# V1.6
# Some code based on code by Mobius (premarket) and TraderKevin (ATR lines
# https://usethinkscript.com/threads/previous-day-high-low-close-premarket-high-low-high-low-open-of-day-for-thinkorswim.13139/

declare hide_on_daily;

input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at = {default Expansion, Time};
input locate_bubbles_at_time = 800;
input BarsFromExpansion = 15;
input ShowPricesInBubbles = yes;

def bn = BarNumber();
def na = Double.NaN;
def h  = high;
def l  = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
def isExpansion = locate_bubbles_at == locate_bubbles_at.Expansion and IsNaN(close);
def firstExpansionBar = if !IsNaN(close[-1]) and isExpansion then 1 else if isExpansion then firstExpansionBar[1] + 1 else 0;
def BubbleLocation = if locate_bubbles_at == locate_bubbles_at.Time then timeopen else isExpansion and firstExpansionBar == BarsFromExpansion;

#----- Previous Day High/Low/Close -----#


plot PD_High;
plot PD_Low;
plot PD_Close;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PD_High = na;
    PD_Low = na;
    PD_Close = na;
} else {
    PD_High = Highest(high(period = aggregationPeriod)[-displace], length);
    PD_Low = Lowest(low(period = aggregationPeriod)[-displace], length);
    PD_Close = close(period = aggregationPeriod)[-displace];
}

PD_High.SetDefaultColor(Color.DARK_ORANGE);
PD_High.SetStyle(Curve.LONG_DASH);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(Color.DARK_ORANGE);
PD_Low.SetStyle(Curve.LONG_DASH);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(Color.WHITE);
PD_Close.SetStyle(Curve.LONG_DASH);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

DefineGlobalColor("PD_High", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_High, "PDH: " + (if ShowPricesInBubbles then AsText(PD_High) else ""), GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_Low, "PDL: " + (if ShowPricesInBubbles then AsText(PD_Low) else ""), GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", Color.WHITE);
AddChartBubble(ShowBubbles and BubbleLocation, PD_Close, "PDC: " + (if ShowPricesInBubbles then AsText(PD_Close) else ""), GlobalColor("PD_Close"));

PD_High.HideBubble();
PD_Low.HideBubble();
PD_Close.HideBubble();


#----- Premarket High/Low -----# Thanks to Mobius

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

def vol = if GlobeX and !GlobeX[1]
then v
else if GlobeX
then vol[1] + v
else na;

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 bn
else na;

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 bn
else na;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];

plot PM_High;
plot PM_Low;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PM_High = na;
    PM_Low = na;
} else {
    PM_High = if OverNightHigh > 0 then OverNightHigh else na;
    PM_Low = if OverNightLow > 0 then OverNightLow else na;
}

#PM_High.SetHiding(!PlotOverNightExtremes);
PM_High.SetLineWeight(2);
PM_High.SetDefaultColor(Color.red);
#PM_High.SetStyle(Curve.LONG_DASH);
PM_High.HideBubble();
PM_High.HideTitle();

#PM_Low.SetHiding(!PlotOverNightExtremes);
PM_Low.SetLineWeight(2);
#PM_Low.SetStyle(Curve.LONG_DASH);
PM_Low.SetDefaultColor(Color.red);
PM_Low.HideBubble();
PM_Low.HideTitle();

DefineGlobalColor("PM_High", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONhighBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_High, "PMH: " + (if ShowPricesInBubbles then AsText(PM_High) else ""), GlobalColor("PM_High"));

DefineGlobalColor("PM_Low", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_Low, "PML: " + (if ShowPricesInBubbles then AsText(PM_Low) else ""), GlobalColor("PM_Low"), no); 

#PM FIBS
def fib1Level = 11.4;
def fib2Level = 21.4;
def fib3Level = 38.2;
def fib4Level = 50;
def fib5Level = 61.8;
def fib6Level = 78.6;
def fib7Level = 88.6;
def fib8Level = 150;
def fib9Level = -50;
def fib10Level = 200;
def fib11Level = -100;
def fib12Level = 250;
def fib13Level = -150;
def fib14Level = 300;
def fib15Level = -200;


def f1 = pm_low + (pm_high - pm_low) * fib1Level / 100;
def f2 = pm_low + (pm_high - pm_low) * fib2Level / 100;
def f3 = pm_low + (pm_high - pm_low) * fib3Level / 100;
def f4 = pm_low + (pm_high - pm_low) * fib4Level / 100;
def f5 = pm_low + (pm_high - pm_low) * fib5Level / 100;
def f6 = pm_low + (pm_high - pm_low) * fib6Level / 100;
def f7 = pm_low + (pm_high - pm_low) * fib7Level / 100;
def f8 = pm_low + (pm_high - pm_low) * fib8Level / 100;
def f9 = pm_low + (pm_high - pm_low) * fib9Level / 100;
def f10 = pm_low + (pm_high - pm_low) * fib10Level / 100;
def f11 = pm_low + (pm_high - pm_low) * fib11Level / 100;
def f12 = pm_low + (pm_high - pm_low) * fib12Level / 100;
def f13 = pm_low + (pm_high - pm_low) * fib13Level / 100;
def f14 = pm_low + (pm_high - pm_low) * fib14Level / 100;
def f15 = pm_low + (pm_high - pm_low) * fib15Level / 100;

plot Fib1 = f1;
#plot Fib1 = if close > f4 then f1 else double.nan;
plot Fib2 = f2;
plot Fib3 = f3;
plot Fib4 = f4;
plot Fib5 = f5;
plot Fib6 = f6;
plot Fib7 = f7;
plot Fib8 = f8;
plot Fib9 = f9;
plot Fib10 = f10;
plot Fib11 = f11;
plot Fib12 = f12;
plot Fib13 = f13;
plot Fib14 = f14;
plot Fib15 = f15;

Fib1.SetPaintingStrategy(PaintingStrategy.dashes);
Fib1.SetDefaultColor(Color.blue);
Fib1.HideBubble();
Fib2.SetPaintingStrategy(PaintingStrategy.dashes);
Fib2.SetDefaultColor(Color.cyan);
Fib2.HideBubble();

Fib3.SetPaintingStrategy(PaintingStrategy.dashes);
Fib3.SetDefaultColor(Color.orange);
Fib3.HideBubble();

Fib4.SetPaintingStrategy(PaintingStrategy.dashes);
Fib4.SetDefaultColor(Color.green);
Fib4.HideBubble();

Fib5.SetPaintingStrategy(PaintingStrategy.dashes);
Fib5.SetDefaultColor(Color.orange);
Fib5.HideBubble();

Fib6.SetPaintingStrategy(PaintingStrategy.dashes);
Fib6.SetDefaultColor(Color.cyan);
Fib6.HideBubble();

Fib7.SetPaintingStrategy(PaintingStrategy.dashes);
Fib7.SetDefaultColor(Color.blue);
Fib7.HideBubble();

Fib8.SetPaintingStrategy(PaintingStrategy.dashes);
Fib8.SetDefaultColor(Color.white);
Fib8.setlineWeight(2);
Fib8.HideBubble();

Fib9.SetPaintingStrategy(PaintingStrategy.dashes);
Fib9.SetDefaultColor(Color.white);
Fib9.setlineWeight(2);
Fib9.HideBubble();

Fib10.SetPaintingStrategy(PaintingStrategy.dashes);
Fib10.SetDefaultColor(Color.white);
Fib10.setlineWeight(2);
Fib10.HideBubble();

Fib11.SetPaintingStrategy(PaintingStrategy.dashes);
Fib11.SetDefaultColor(Color.white);
Fib11.setlineWeight(2);
Fib11.HideBubble();

Fib12.SetPaintingStrategy(PaintingStrategy.dashes);
Fib12.SetDefaultColor(Color.white);
Fib12.setlineWeight(2);
Fib12.HideBubble();

Fib13.SetPaintingStrategy(PaintingStrategy.dashes);
Fib13.SetDefaultColor(Color.white);
Fib13.setlineWeight(2);
Fib13.HideBubble();

Fib14.SetPaintingStrategy(PaintingStrategy.dashes);
Fib14.SetDefaultColor(Color.white);
Fib14.setlineWeight(2);
Fib14.HideBubble();

Fib15.SetPaintingStrategy(PaintingStrategy.dashes);
Fib15.SetDefaultColor(Color.white);
Fib15.setlineWeight(2);
Fib15.HideBubble();

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib8, "50%: " + (if ShowPricesInBubbles then AsText(Fib8) else ""), color.white); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib9, "-50%: " + (if ShowPricesInBubbles then AsText(Fib9) else ""), color.white, no); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib10, "100%: " + (if ShowPricesInBubbles then AsText(Fib10) else ""), color.white); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib11, "-100%: " + (if ShowPricesInBubbles then AsText(Fib11) else ""), color.white, no); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib12, "150%: " + (if ShowPricesInBubbles then AsText(Fib12) else ""), color.white); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib13, "-150%: " + (if ShowPricesInBubbles then AsText(Fib13) else ""), color.white, no); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib14, "200%: " + (if ShowPricesInBubbles then AsText(Fib14) else ""), color.white); 

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib15, "-200%: " + (if ShowPricesInBubbles then AsText(Fib15) else ""), color.white, no); 

#----- Today Open/High/Low -----#


plot High_of_Day;
plot Low_of_Day;
plot DayOpen;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DayOpen = na;
    High_of_Day = na;
    Low_of_Day = na;
} else {
    DayOpen = open(period = aggregationPeriod)[0];
    High_of_Day = Highest(high(period = aggregationPeriod), length);
    Low_of_Day = Lowest(low(period = aggregationPeriod), length);
}

DayOpen.SetDefaultColor (Color.yellow);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();

High_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();

Low_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();

DefineGlobalColor("Open", Color.yellow);
AddChartBubble(ShowBubbles and BubbleLocation, DayOpen, "Open: " + (if ShowPricesInBubbles then AsText(DayOpen) else ""), GlobalColor("Open"));

DefineGlobalColor("High_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, High_of_Day, "HOD: " + (if ShowPricesInBubbles then AsText(High_of_Day) else ""), GlobalColor("High_of_Day"));

DefineGlobalColor("Low_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, Low_of_Day, "LOD: " + (if ShowPricesInBubbles then AsText(Low_of_Day) else ""), GlobalColor("Low_of_Day"), no);

#----- ATR Lines -----# Thaanks to TraderKevin
input showAtrLines = Yes;
input atrLinesFrom = {default pdc, dayOpen};
input ATRlength = 14;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRlength);

plot hatr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen + ATR else PD_Close + ATR;
plot latr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen - ATR else PD_Close - ATR;

hatr.SetLineWeight(5);
hatr.SetDefaultColor(Color.RED);
hatr.SetStyle(Curve.LONG_DASH);
hatr.HideBubble();
hatr.HideTitle();
hatr.SetHiding(showAtrLines == no);

latr.SetLineWeight(5);
latr.SetStyle(Curve.LONG_DASH);
latr.SetDefaultColor(Color.GREEN);
latr.HideBubble();
latr.HideTitle();
latr.SetHiding(showAtrLines == no);

DefineGlobalColor("hatr", Color.PINK);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, hatr, "ATRH: " + (if ShowPricesInBubbles then AsText(hatr) else ""), GlobalColor("hatr"));

DefineGlobalColor("latr", Color.LIGHT_GREEN);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, latr, "ATRL: " + (if ShowPricesInBubbles then AsText(latr) else ""), GlobalColor("latr"), no);
 
@Wiinii
I wanted to see if there were any updates that could be made to the script for Futures Traders.

For the Opening Price it is showing the Open of the Globex Session vs the Market Open (Cash/RTH). I know I can turn off extended hours but there are levels I am looking for on the Overnight session for the Cash Session trading.

On the Market Close, for Futures there is a settlement period vs the RTH close at 1559hrs. Most use the true market close vs including the settlement period.

Perhaps this can be fixed by having a "Time Input" for the Open and Closed times. Similar to the Opening Range Scripts I have seen.

Also, I see the HOD and ONH in the example are the same price, but it really isn't the RTH HOD price and should be different and not the ON High or Low as you already include those levels as a separate plot. I assume it would be the same for the LOD and ONL if the real LOD doesn't get under the ONL.

Anyways anything you can do to help fix that would be appreciated.

Wiinii Script.jpg
 
Hi, Can someone please explain to me why I'm not getting the line for SPX?
And also is there way to remove the prices from inside the bubble just to make the bubble size smaller/neater. Thank you 🙏
 
After playing around with the original script. I was able to get the PD High, Low, Close on SPX chart to show the lines with the bubbles. Credit goes to original creators of the script. Below is what I cut and pasted. Thank you.


# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day
# Some code based on code by Mobius
# Created by Wiinii
# https://usethinkscript.com/threads/...w-high-low-open-of-day-for-thinkorswim.13139/
# https://usethinkscript.com/threads/extend-point-of-control-line-volume-profile.10893/post-112226

declare hide_on_daily;

input extend_plots = yes;
input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at_time = 0930;


def bn = BarNumber();
def na = Double.NaN;
def h = high;
def l = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;

#----- Previous Day High/Low/Close -----#

plot PD_High;
plot PD_Low;
plot PD_Close;
def PD_H = if extend_plots and isnan(close)
then PD_H[1]
else Highest(high(period = aggregationPeriod)[-displace], length);
def PD_L = if extend_plots and isnan(close)
then PD_L[1]
else Lowest(low(period = aggregationPeriod)[-displace], length);
def PD_C = if extend_plots and isnan(close)
then PD_C[1]
else close(period = aggregationPeriod)[-displace];
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
PD_High = na;
PD_Low = na;
PD_Close = na;
} else {
PD_High = PD_H;
PD_Low = PD_L;
PD_Close = PD_C;
}

PD_High.SetDefaultColor(color.DARK_ORANGE);
PD_High.SetpaintingStrategy(paintingStrategy.HORIZONTAL);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(color.DARK_ORANGE);
PD_Low.SetpaintingStrategy(paintingStrategy.HORIZONTAL);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(color.WHITE);
PD_Close.SetPaintingStrategy(paintingStrategy.HORIZONTAL);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

input bubble_placement = {default right_edge, timeopen};

def right_edge = barnumber() == highestall(barnumber() - 1);

DefineGlobalColor("PD_High", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_High, "PD High: " + PD_High, GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_Low, "PD Low: " + PD_Low, GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", color.WHITE);
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_Close, "PD Close: " + PD_Close, GlobalColor("PD_Close"));
 
Last edited by a moderator:
I looked around for a script with all the things and didn't see one, so I made one. You can change the colors and transparency of the bubbles under Globals as seen in 2nd pic, adjust the bubbles position to a specific time, and there is an option to turn off the bubbles altogether. By default the previous day's stuff is dashes, today's stuff is solid (but you can of course customize it all). You can also turn on the option to see previous days' stuff too. Enjoy!

UPDATES (1.6 - 4/7/23):
  • Now includes ATR projected move lines! Option for from open or previous day close.
  • You can now choose to have the bubbles show at a time or in the expansion area! To see it in the expansion area, click on the gear above the chart > go to Time Axis and change the Expansion area to a number that keeps them off your charts (this will vary depending on timeframe and zoom level).
Shared Link: http://tos.mx/LkI7ww4 (or use code below). Click here for --> Easiest way to load shared links

View attachment 16296

View attachment 16297

Code:
# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day + ATR Lines
# Created by Wiinii
# V1.6
# Some code based on code by Mobius (premarket) and TraderKevin (ATR lines
# https://usethinkscript.com/threads/previous-day-high-low-close-premarket-high-low-high-low-open-of-day-for-thinkorswim.13139/

declare hide_on_daily;

input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at = {default Expansion, Time};
input locate_bubbles_at_time = 800;
input BarsFromExpansion = 1;
input ShowPricesInBubbles = yes;

def bn = BarNumber();
def na = Double.NaN;
def h  = high;
def l  = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
def isExpansion = locate_bubbles_at == locate_bubbles_at.Expansion and IsNaN(close);
def firstExpansionBar = if !IsNaN(close[-1]) and isExpansion then 1 else if isExpansion then firstExpansionBar[1] + 1 else 0;
def BubbleLocation = if locate_bubbles_at == locate_bubbles_at.Time then timeopen else isExpansion and firstExpansionBar == BarsFromExpansion;

#----- Previous Day High/Low/Close -----#


plot PD_High;
plot PD_Low;
plot PD_Close;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PD_High = na;
    PD_Low = na;
    PD_Close = na;
} else {
    PD_High = Highest(high(period = aggregationPeriod)[-displace], length);
    PD_Low = Lowest(low(period = aggregationPeriod)[-displace], length);
    PD_Close = close(period = aggregationPeriod)[-displace];
}

PD_High.SetDefaultColor(Color.DARK_ORANGE);
PD_High.SetStyle(Curve.LONG_DASH);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(Color.DARK_ORANGE);
PD_Low.SetStyle(Curve.LONG_DASH);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(Color.WHITE);
PD_Close.SetStyle(Curve.LONG_DASH);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

DefineGlobalColor("PD_High", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_High, "PDH: " + (if ShowPricesInBubbles then AsText(PD_High) else ""), GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_Low, "PDL: " + (if ShowPricesInBubbles then AsText(PD_Low) else ""), GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", Color.WHITE);
AddChartBubble(ShowBubbles and BubbleLocation, PD_Close, "PDC: " + (if ShowPricesInBubbles then AsText(PD_Close) else ""), GlobalColor("PD_Close"));

PD_High.HideBubble();
PD_Low.HideBubble();
PD_Close.HideBubble();


#----- Premarket High/Low -----# Thanks to Mobius

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

def vol = if GlobeX and !GlobeX[1]
then v
else if GlobeX
then vol[1] + v
else na;

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 bn
else na;

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 bn
else na;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];

plot PM_High;
plot PM_Low;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PM_High = na;
    PM_Low = na;
} else {
    PM_High = if OverNightHigh > 0 then OverNightHigh else na;
    PM_Low = if OverNightLow > 0 then OverNightLow else na;
}

#PM_High.SetHiding(!PlotOverNightExtremes);
PM_High.SetLineWeight(2);
PM_High.SetDefaultColor(Color.CYAN);
PM_High.SetStyle(Curve.LONG_DASH);
PM_High.HideBubble();
PM_High.HideTitle();

#PM_Low.SetHiding(!PlotOverNightExtremes);
PM_Low.SetStyle(Curve.LONG_DASH);
PM_Low.SetDefaultColor(Color.CYAN);
PM_Low.HideBubble();
PM_Low.HideTitle();

DefineGlobalColor("PM_High", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONhighBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_High, "PMH: " + (if ShowPricesInBubbles then AsText(PM_High) else ""), GlobalColor("PM_High"));

DefineGlobalColor("PM_Low", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_Low, "PML: " + (if ShowPricesInBubbles then AsText(PM_Low) else ""), GlobalColor("PM_Low"), no);


#----- Today Open/High/Low -----#


plot High_of_Day;
plot Low_of_Day;
plot DayOpen;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DayOpen = na;
    High_of_Day = na;
    Low_of_Day = na;
} else {
    DayOpen = open(period = aggregationPeriod)[0];
    High_of_Day = Highest(high(period = aggregationPeriod), length);
    Low_of_Day = Lowest(low(period = aggregationPeriod), length);
}

DayOpen.SetDefaultColor (Color.GRAY);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();

High_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();

Low_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();

DefineGlobalColor("Open", Color.LIGHT_GRAY);
AddChartBubble(ShowBubbles and BubbleLocation, DayOpen, "Open: " + (if ShowPricesInBubbles then AsText(DayOpen) else ""), GlobalColor("Open"));

DefineGlobalColor("High_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, High_of_Day, "HOD: " + (if ShowPricesInBubbles then AsText(High_of_Day) else ""), GlobalColor("High_of_Day"));

DefineGlobalColor("Low_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, Low_of_Day, "LOD: " + (if ShowPricesInBubbles then AsText(Low_of_Day) else ""), GlobalColor("Low_of_Day"), no);

#----- ATR Lines -----# Thaanks to TraderKevin
input showAtrLines = Yes;
input atrLinesFrom = {default pdc, dayOpen};
input ATRlength = 14;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRlength);

plot hatr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen + ATR else PD_Close + ATR;
plot latr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen - ATR else PD_Close - ATR;

hatr.SetLineWeight(5);
hatr.SetDefaultColor(Color.RED);
hatr.SetStyle(Curve.LONG_DASH);
hatr.HideBubble();
hatr.HideTitle();
hatr.SetHiding(showAtrLines == no);

latr.SetLineWeight(5);
latr.SetStyle(Curve.LONG_DASH);
latr.SetDefaultColor(Color.GREEN);
latr.HideBubble();
latr.HideTitle();
latr.SetHiding(showAtrLines == no);

DefineGlobalColor("hatr", Color.PINK);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, hatr, "ATRH: " + (if ShowPricesInBubbles then AsText(hatr) else ""), GlobalColor("hatr"));

DefineGlobalColor("latr", Color.LIGHT_GREEN);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, latr, "ATRL: " + (if ShowPricesInBubbles then AsText(latr) else ""), GlobalColor("latr"), no);
[/COD
[/QUOTE]
Small request:
Can someone add a drawing/level to this to mark off 50% (1/2 candle) of previous day?
 
For those of us that enjoy premarket analysis and the associate opening, it would be benefitual to have the midpoint plotted to best understand how the market is pivoting. I have tried to update with this variable, with no success. Help?
 
I added some fibs between the PMH and PML. And extensions up to 200% for fans of fibs.

View attachment 19781

Code:
# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day + ATR Lines
# Created by Wiinii
# V1.6
# Some code based on code by Mobius (premarket) and TraderKevin (ATR lines
# https://usethinkscript.com/threads/previous-day-high-low-close-premarket-high-low-high-low-open-of-day-for-thinkorswim.13139/

declare hide_on_daily;

input length = 1;
input showOnlyLastPeriod = yes;
input ShowBubbles = yes;
input locate_bubbles_at = {default Expansion, Time};
input locate_bubbles_at_time = 800;
input BarsFromExpansion = 15;
input ShowPricesInBubbles = yes;

def bn = BarNumber();
def na = Double.NaN;
def h  = high;
def l  = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;
def isExpansion = locate_bubbles_at == locate_bubbles_at.Expansion and IsNaN(close);
def firstExpansionBar = if !IsNaN(close[-1]) and isExpansion then 1 else if isExpansion then firstExpansionBar[1] + 1 else 0;
def BubbleLocation = if locate_bubbles_at == locate_bubbles_at.Time then timeopen else isExpansion and firstExpansionBar == BarsFromExpansion;

#----- Previous Day High/Low/Close -----#


plot PD_High;
plot PD_Low;
plot PD_Close;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PD_High = na;
    PD_Low = na;
    PD_Close = na;
} else {
    PD_High = Highest(high(period = aggregationPeriod)[-displace], length);
    PD_Low = Lowest(low(period = aggregationPeriod)[-displace], length);
    PD_Close = close(period = aggregationPeriod)[-displace];
}

PD_High.SetDefaultColor(Color.DARK_ORANGE);
PD_High.SetStyle(Curve.LONG_DASH);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(Color.DARK_ORANGE);
PD_Low.SetStyle(Curve.LONG_DASH);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(Color.WHITE);
PD_Close.SetStyle(Curve.LONG_DASH);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

DefineGlobalColor("PD_High", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_High, "PDH: " + (if ShowPricesInBubbles then AsText(PD_High) else ""), GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255, 204, 153));
AddChartBubble(ShowBubbles and BubbleLocation, PD_Low, "PDL: " + (if ShowPricesInBubbles then AsText(PD_Low) else ""), GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", Color.WHITE);
AddChartBubble(ShowBubbles and BubbleLocation, PD_Close, "PDC: " + (if ShowPricesInBubbles then AsText(PD_Close) else ""), GlobalColor("PD_Close"));

PD_High.HideBubble();
PD_Low.HideBubble();
PD_Close.HideBubble();


#----- Premarket High/Low -----# Thanks to Mobius

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

def vol = if GlobeX and !GlobeX[1]
then v
else if GlobeX
then vol[1] + v
else na;

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 bn
else na;

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 bn
else na;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];

plot PM_High;
plot PM_Low;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PM_High = na;
    PM_Low = na;
} else {
    PM_High = if OverNightHigh > 0 then OverNightHigh else na;
    PM_Low = if OverNightLow > 0 then OverNightLow else na;
}

#PM_High.SetHiding(!PlotOverNightExtremes);
PM_High.SetLineWeight(2);
PM_High.SetDefaultColor(Color.red);
#PM_High.SetStyle(Curve.LONG_DASH);
PM_High.HideBubble();
PM_High.HideTitle();

#PM_Low.SetHiding(!PlotOverNightExtremes);
PM_Low.SetLineWeight(2);
#PM_Low.SetStyle(Curve.LONG_DASH);
PM_Low.SetDefaultColor(Color.red);
PM_Low.HideBubble();
PM_Low.HideTitle();

DefineGlobalColor("PM_High", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONhighBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_High, "PMH: " + (if ShowPricesInBubbles then AsText(PM_High) else ""), GlobalColor("PM_High"));

DefineGlobalColor("PM_Low", CreateColor(102, 255, 255));
AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, PM_Low, "PML: " + (if ShowPricesInBubbles then AsText(PM_Low) else ""), GlobalColor("PM_Low"), no);

#PM FIBS
def fib1Level = 11.4;
def fib2Level = 21.4;
def fib3Level = 38.2;
def fib4Level = 50;
def fib5Level = 61.8;
def fib6Level = 78.6;
def fib7Level = 88.6;
def fib8Level = 150;
def fib9Level = -50;
def fib10Level = 200;
def fib11Level = -100;
def fib12Level = 250;
def fib13Level = -150;
def fib14Level = 300;
def fib15Level = -200;


def f1 = pm_low + (pm_high - pm_low) * fib1Level / 100;
def f2 = pm_low + (pm_high - pm_low) * fib2Level / 100;
def f3 = pm_low + (pm_high - pm_low) * fib3Level / 100;
def f4 = pm_low + (pm_high - pm_low) * fib4Level / 100;
def f5 = pm_low + (pm_high - pm_low) * fib5Level / 100;
def f6 = pm_low + (pm_high - pm_low) * fib6Level / 100;
def f7 = pm_low + (pm_high - pm_low) * fib7Level / 100;
def f8 = pm_low + (pm_high - pm_low) * fib8Level / 100;
def f9 = pm_low + (pm_high - pm_low) * fib9Level / 100;
def f10 = pm_low + (pm_high - pm_low) * fib10Level / 100;
def f11 = pm_low + (pm_high - pm_low) * fib11Level / 100;
def f12 = pm_low + (pm_high - pm_low) * fib12Level / 100;
def f13 = pm_low + (pm_high - pm_low) * fib13Level / 100;
def f14 = pm_low + (pm_high - pm_low) * fib14Level / 100;
def f15 = pm_low + (pm_high - pm_low) * fib15Level / 100;

plot Fib1 = f1;
#plot Fib1 = if close > f4 then f1 else double.nan;
plot Fib2 = f2;
plot Fib3 = f3;
plot Fib4 = f4;
plot Fib5 = f5;
plot Fib6 = f6;
plot Fib7 = f7;
plot Fib8 = f8;
plot Fib9 = f9;
plot Fib10 = f10;
plot Fib11 = f11;
plot Fib12 = f12;
plot Fib13 = f13;
plot Fib14 = f14;
plot Fib15 = f15;

Fib1.SetPaintingStrategy(PaintingStrategy.dashes);
Fib1.SetDefaultColor(Color.blue);
Fib1.HideBubble();
Fib2.SetPaintingStrategy(PaintingStrategy.dashes);
Fib2.SetDefaultColor(Color.cyan);
Fib2.HideBubble();

Fib3.SetPaintingStrategy(PaintingStrategy.dashes);
Fib3.SetDefaultColor(Color.orange);
Fib3.HideBubble();

Fib4.SetPaintingStrategy(PaintingStrategy.dashes);
Fib4.SetDefaultColor(Color.green);
Fib4.HideBubble();

Fib5.SetPaintingStrategy(PaintingStrategy.dashes);
Fib5.SetDefaultColor(Color.orange);
Fib5.HideBubble();

Fib6.SetPaintingStrategy(PaintingStrategy.dashes);
Fib6.SetDefaultColor(Color.cyan);
Fib6.HideBubble();

Fib7.SetPaintingStrategy(PaintingStrategy.dashes);
Fib7.SetDefaultColor(Color.blue);
Fib7.HideBubble();

Fib8.SetPaintingStrategy(PaintingStrategy.dashes);
Fib8.SetDefaultColor(Color.white);
Fib8.setlineWeight(2);
Fib8.HideBubble();

Fib9.SetPaintingStrategy(PaintingStrategy.dashes);
Fib9.SetDefaultColor(Color.white);
Fib9.setlineWeight(2);
Fib9.HideBubble();

Fib10.SetPaintingStrategy(PaintingStrategy.dashes);
Fib10.SetDefaultColor(Color.white);
Fib10.setlineWeight(2);
Fib10.HideBubble();

Fib11.SetPaintingStrategy(PaintingStrategy.dashes);
Fib11.SetDefaultColor(Color.white);
Fib11.setlineWeight(2);
Fib11.HideBubble();

Fib12.SetPaintingStrategy(PaintingStrategy.dashes);
Fib12.SetDefaultColor(Color.white);
Fib12.setlineWeight(2);
Fib12.HideBubble();

Fib13.SetPaintingStrategy(PaintingStrategy.dashes);
Fib13.SetDefaultColor(Color.white);
Fib13.setlineWeight(2);
Fib13.HideBubble();

Fib14.SetPaintingStrategy(PaintingStrategy.dashes);
Fib14.SetDefaultColor(Color.white);
Fib14.setlineWeight(2);
Fib14.HideBubble();

Fib15.SetPaintingStrategy(PaintingStrategy.dashes);
Fib15.SetDefaultColor(Color.white);
Fib15.setlineWeight(2);
Fib15.HideBubble();

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib8, "50%: " + (if ShowPricesInBubbles then AsText(Fib8) else ""), color.white);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib9, "-50%: " + (if ShowPricesInBubbles then AsText(Fib9) else ""), color.white, no);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib10, "100%: " + (if ShowPricesInBubbles then AsText(Fib10) else ""), color.white);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib11, "-100%: " + (if ShowPricesInBubbles then AsText(Fib11) else ""), color.white, no);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib12, "150%: " + (if ShowPricesInBubbles then AsText(Fib12) else ""), color.white);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib13, "-150%: " + (if ShowPricesInBubbles then AsText(Fib13) else ""), color.white, no);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib14, "200%: " + (if ShowPricesInBubbles then AsText(Fib14) else ""), color.white);

AddChartBubble(ShowBubbles and if locate_bubbles_at == locate_bubbles_at.Time then bn == ONlowBar else isExpansion and firstExpansionBar == BarsFromExpansion, Fib15, "-200%: " + (if ShowPricesInBubbles then AsText(Fib15) else ""), color.white, no);

#----- Today Open/High/Low -----#


plot High_of_Day;
plot Low_of_Day;
plot DayOpen;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DayOpen = na;
    High_of_Day = na;
    Low_of_Day = na;
} else {
    DayOpen = open(period = aggregationPeriod)[0];
    High_of_Day = Highest(high(period = aggregationPeriod), length);
    Low_of_Day = Lowest(low(period = aggregationPeriod), length);
}

DayOpen.SetDefaultColor (Color.yellow);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();

High_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();

Low_of_Day.SetDefaultColor(CreateColor(0, 128, 255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();

DefineGlobalColor("Open", Color.yellow);
AddChartBubble(ShowBubbles and BubbleLocation, DayOpen, "Open: " + (if ShowPricesInBubbles then AsText(DayOpen) else ""), GlobalColor("Open"));

DefineGlobalColor("High_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, High_of_Day, "HOD: " + (if ShowPricesInBubbles then AsText(High_of_Day) else ""), GlobalColor("High_of_Day"));

DefineGlobalColor("Low_of_Day", CreateColor(102, 178, 255));
AddChartBubble(ShowBubbles and BubbleLocation, Low_of_Day, "LOD: " + (if ShowPricesInBubbles then AsText(Low_of_Day) else ""), GlobalColor("Low_of_Day"), no);

#----- ATR Lines -----# Thaanks to TraderKevin
input showAtrLines = Yes;
input atrLinesFrom = {default pdc, dayOpen};
input ATRlength = 14;
input averageType = AverageType.WILDERS;

def ATR = MovingAverage(averageType, TrueRange(high(period = ”DAY”)[1], close(period = ”DAY”)[1], low(period = ”DAY”)[1]), ATRlength);

plot hatr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen + ATR else PD_Close + ATR;
plot latr = if atrLinesFrom  == atrLinesFrom .dayOpen then DayOpen - ATR else PD_Close - ATR;

hatr.SetLineWeight(5);
hatr.SetDefaultColor(Color.RED);
hatr.SetStyle(Curve.LONG_DASH);
hatr.HideBubble();
hatr.HideTitle();
hatr.SetHiding(showAtrLines == no);

latr.SetLineWeight(5);
latr.SetStyle(Curve.LONG_DASH);
latr.SetDefaultColor(Color.GREEN);
latr.HideBubble();
latr.HideTitle();
latr.SetHiding(showAtrLines == no);

DefineGlobalColor("hatr", Color.PINK);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, hatr, "ATRH: " + (if ShowPricesInBubbles then AsText(hatr) else ""), GlobalColor("hatr"));

DefineGlobalColor("latr", Color.LIGHT_GREEN);
AddChartBubble(ShowBubbles and showAtrLines and BubbleLocation, latr, "ATRL: " + (if ShowPricesInBubbles then AsText(latr) else ""), GlobalColor("latr"), no);
@chewie76 Can you take a look at this code that you provided when you get a sec. I cannot get the FIBS to change based on length. No matter what length I use, The Fibs are static.

*** Also, can someone please rewrite the code so that PDL,PDH is only based on market open time from 9:30 - 1600 and not Previous days Pre Market.
@SleepyZ @samer800 @halcyonguy @Wiinii @BenTen
1705978927943.png


1705979080777.png


1705979159494.png

1705979262969.png
 
Sure, see input extend_plots = yes;
I've been using a slimmed down version of these studies to simply show the RTH Hi/Lo/Mid which is shown as a horizontal line. Does anyone know if it is possible to show these lines as they develop during the day, ie RTH-Hi ratches up bar-by-bar? Thanks for any help



Ruby:
def na = Double.NaN;
def bn = BarNumber();
def h = high;
def l = low;

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];

def hRTH = HighestAll(RTH);
def hGX = HighestAll(globex);

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);

plot
CurrentHigh = RTHhigh;
CurrentHigh.SetDefaultColor(Color.Green);
CurrentHigh.SetPaintingStrategy(PaintingStrategy.Line);
CurrentHigh.SetStyle(Curve.Short_Dash);
CurrentHigh.SetLineWeight(1);
CurrentHigh.HideBubble();
CurrentHigh.HideTitle();

plot
CurrentLow = RTHlow;
CurrentLow.SetDefaultColor(Color.Red);
CurrentLow.SetPaintingStrategy(PaintingStrategy.Line);
CurrentLow.SetStyle(Curve.Short_Dash);
CurrentLow.SetLineWeight(1);
CurrentLow.HideBubble();
CurrentLow.HideTitle();

plot RTHMid = (RTHhigh + RTHlow) / 2 ;
RTHMid.SetDefaultColor(Color.Dark_Orange);
# Halfback.SetPaintingStrategy(PaintingStrategy.Line);
RTHMid.SetStyle(curve.POINTS);
RTHMid.SetLineWeight(1);
RTHMid.HideBubble();
RTHMid.HideTitle();
 
Can someone please let us know why this apparently can't be done. Many trader have requested for the PDL/PDH to be set to market hours instead of preMarket for the previous day. I am curious as to why that cannot be achieved and also, Is there a more technical reason for not giving this option.
 
@chewie76 Can you take a look at this code that you provided when you get a sec. I cannot get the FIBS to change based on length. No matter what length I use, The Fibs are static.

*** Also, can someone please rewrite the code so that PDL,PDH is only based on market open time from 9:30 - 1600 and not Previous days Pre Market.
@SleepyZ @samer800 @halcyonguy @Wiinii @BenTen
View attachment 20773

View attachment 20774

View attachment 20775
View attachment 20776
The fibs are static because it is measuring from the high and low of that day.
 
Hello everyone. Been away for a while. I also have been using this indicator and would like the option to only show trading hours previous day highs/lows. Is this possible?
 
i know its been a while on this thread, but would it be possible to add a level for the 630am PST market open. need this for futures/stocks. up to now i only see the overnight 4pmPST open.

[Edit to have RTHrs for current day to work on Futures as well as Stocks]

Regrettably, It appears I haven't looked at this thread, as well, since the post you referenced.

1. The line you want is the one that started at 4am PST open. That is how the AggregationPeriod.DAY plots.
2. It actually is the regular trading open at 9:30am (6:30 am PST).
3. The following line in the code will shrink this line to start at the beginning of RTHours as you want.
4. Here is the revised code with that change
Screenshot 2024-02-16 162141.png

Code:
# Previous Day High/Low/Close + Premarket High/Low + RTHrs High/Low/Open of Day
# Some code based on code by Mobius
# Created by Wiinii
# Sleepyz added input option coding
# PM_Mid added

declare hide_on_daily;

input extend_plots       = yes;
input length             = 1;
input showOnlyLastPeriod = yes;
input showexpansiononly  = no;
input ShowBubbles        = yes;
input locate_bubbles_at_time = 0930;


def bn = BarNumber();
def na = Double.NaN;
def h  = high;
def l  = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;

#----- Previous Day High/Low/Close -----#

plot PD_High;
plot PD_Low;
plot PD_Close;
def PD_H = if extend_plots and isnan(close)
           then PD_H[1]
           else Highest(high(period = aggregationPeriod)[-displace], length);
def PD_L = if extend_plots and isnan(close)
           then PD_L[1]
           else Lowest(low(period = aggregationPeriod)[-displace], length);
def PD_C = if extend_plots and isnan(close)
           then PD_C[1]
           else close(period = aggregationPeriod)[-displace];
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PD_High = na;
    PD_Low = na;
    PD_Close = na;
} else {
    PD_High  = if showexpansiononly and !IsNaN(close)
               then Double.NaN
               else PD_H;
    PD_Low   = if showexpansiononly and !IsNaN(close)
               then Double.NaN
               else PD_L;
    PD_Close = if showexpansiononly and !IsNaN(close)
               then Double.NaN
               else PD_C;
}

PD_High.SetDefaultColor(color.DARK_ORANGE);
PD_High.SetpaintingStrategy(paintingStrategy.HORIZONTAL);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(color.DARK_ORANGE);
PD_Low.SetpaintingStrategy(paintingStrategy.HORIZONTAL);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(color.WHITE);
PD_Close.SetPaintingStrategy(paintingStrategy.HORIZONTAL);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

input bubble_placement = {default right_edge, timeopen};

def right_edge = barnumber() == highestall(barnumber() - 1);

DefineGlobalColor("PD_High", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_High, "PD High: " + PD_High, GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_Low, "PD Low: " + PD_Low, GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", color.WHITE);
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_Close, "PD Close: " + PD_Close, GlobalColor("PD_Close"));


#----- Premarket High/Low -----#

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

def vol = if GlobeX and !GlobeX[1]
then v
else if GlobeX
then vol[1] + v
else na;

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 bn
else na;

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 bn
else na;

def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

def OverNightLow = if BarNumber() == HighestAll(ONlowBar)
then ONlow
else OverNightLow[1];

plot PM_High;
plot PM_Low;
plot PM_Mid;
def  PM_H = if extend_plots and isnan(close)
            then PM_H[1]
            else if OverNightHigh > 0 then OverNightHigh else na;
def  PM_L = if extend_plots and isnan(close)
            then PM_L[1]
            else if OverNightLow > 0 then OverNightLow else na;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PM_High = na;
    PM_Low = na;
    PM_Mid = na;
} else {
    PM_High = if showexpansiononly and !IsNaN(close)
              then Double.NaN
              else PM_H;
    PM_Low  = if showexpansiononly and !IsNaN(close)
              then Double.NaN
              else PM_L;
    PM_Mid  = if showexpansiononly and !IsNaN(close)
              then Double.NaN
              else (PM_H + PM_L) / 2;
}

#PM_High.SetHiding(!PlotOverNightExtremes);
PM_High.SetLineWeight(2);
PM_High.SetDefaultColor(color.CYAN);
PM_High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PM_High.HideBubble();
PM_High.HideTitle();

#PM_Low.SetHiding(!PlotOverNightExtremes);
PM_Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PM_Low.SetDefaultColor(Color.CYAN);
PM_Low.HideBubble();
PM_Low.HideTitle();

#PM_Mid.SetHiding(!PlotOverNightExtremes);
PM_Mid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PM_Mid.SetDefaultColor(Color.CYAN);
PM_Mid.HideBubble();
PM_Mid.HideTitle();

DefineGlobalColor("PM_High", CreateColor(102,255,255));
AddChartBubble(ShowBubbles and right_edge, PM_High, "PM High: " + PM_High, GlobalColor("PM_High"));

DefineGlobalColor("PM_Low", CreateColor(102,255,255));
AddChartBubble(ShowBubbles and right_edge, PM_Low, "PM Low: " + PM_Low, GlobalColor("PM_Low"), no);

DefineGlobalColor("PM_Mid", CreateColor(102,255,255));
AddChartBubble(ShowBubbles and right_edge, PM_Mid, "PM Mid: " + PM_Mid, GlobalColor("PM_Mid"));


#----- Today Open/High/Low -----#

plot High_of_Day;
plot Low_of_Day;
Plot DayOpen;
def DOpen    = if extend_plots and isnan(close)
               then DOpen[1]
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)==0
               then open
               else if ticksize()==.01
               then open(period = aggregationPeriod)[0]
               else Dopen[1];
def H_of_Day = if extend_plots and isnan(close)
               then H_of_Day[1]
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)==0
               then high
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)>0
               then max(high, H_of_Day[1])
               else if ticksize()==.01
               then  Highest(high(period = aggregationPeriod), length)
               else H_of_Day[1];
            
def L_of_Day = if extend_plots and isnan(close)
               then L_of_Day[1]
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)==0
               then low
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)>0
               then min(low, L_of_Day[1])
               else if ticksize()==.01
               then  Lowest(low(period = aggregationPeriod), length)
               else L_of_Day[1];

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DayOpen = na;
    High_of_Day = na;
    Low_of_Day = na;
} else {
    DayOpen     = if showexpansiononly and !IsNaN(close) or secondsfromtime(0930) < 0
                  then Double.NaN
                  else DOpen;
    High_of_Day = if showexpansiononly and !IsNaN(close)
                  then Double.NaN
                  else H_of_Day;
    Low_of_Day  = if showexpansiononly and !IsNaN(close)
                  then Double.NaN
                  else L_of_Day;
}

DayOpen.SetDefaultColor (Color.GRAY);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();

High_of_Day.SetDefaultColor(CreateColor(0,128,255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();

Low_of_Day.SetDefaultColor(CreateColor(0,128,255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();

DefineGlobalColor("Open", color.LIGHT_GRAY);
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, DayOpen, "Open: " + DayOpen, GlobalColor("Open"));

DefineGlobalColor("High_of_Day", CreateColor(102,178,255));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, High_of_Day, "High of Day: " + High_of_Day, GlobalColor("High_of_Day"));

DefineGlobalColor("Low_of_Day", CreateColor(102,178,255));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, Low_of_Day, "Low of Day: " + Low_of_Day, GlobalColor("Low_of_Day"), no);
 
Last edited:
I've been using a slimmed down version of these studies to simply show the RTH Hi/Lo/Mid which is shown as a horizontal line. Does anyone know if it is possible to show these lines as they develop during the day, ie RTH-Hi ratches up bar-by-bar? Thanks for any help



Ruby:
def na = Double.NaN;
def bn = BarNumber();
def h = high;
def l = low;

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];

def hRTH = HighestAll(RTH);
def hGX = HighestAll(globex);

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);

plot
CurrentHigh = RTHhigh;
CurrentHigh.SetDefaultColor(Color.Green);
CurrentHigh.SetPaintingStrategy(PaintingStrategy.Line);
CurrentHigh.SetStyle(Curve.Short_Dash);
CurrentHigh.SetLineWeight(1);
CurrentHigh.HideBubble();
CurrentHigh.HideTitle();

plot
CurrentLow = RTHlow;
CurrentLow.SetDefaultColor(Color.Red);
CurrentLow.SetPaintingStrategy(PaintingStrategy.Line);
CurrentLow.SetStyle(Curve.Short_Dash);
CurrentLow.SetLineWeight(1);
CurrentLow.HideBubble();
CurrentLow.HideTitle();

plot RTHMid = (RTHhigh + RTHlow) / 2 ;
RTHMid.SetDefaultColor(Color.Dark_Orange);
# Halfback.SetPaintingStrategy(PaintingStrategy.Line);
RTHMid.SetStyle(curve.POINTS);
RTHMid.SetLineWeight(1);
RTHMid.HideBubble();
RTHMid.HideTitle();

Sorry, just saw this request.

1. To do what you requested was to remove the highestall and lowestall from the RTHhigh/RTHlow defs/
2. Define the high/low for the day at the starting point, hRTH.
3. Then compare the high/low to the previous high/low , RTHhigh[1]/RTHlow[1], throughout the day.
4. Since you used the no longer TOS supported curve lines, the code in the plots was used to keep the lines showing only on the current day.
Screenshot 2024-02-17 062037.png
Code:
def na = Double.NaN;
def bn = BarNumber();
def h = high;
def l = low;

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];

def hRTH = HighestAll(RTH);
#def hGX = HighestAll(globex);

def RTHhigh = compoundValue(1, if bn == hRTH
then h else if h > RTHhigh[1] && bn >= hRTH
then h else RTHhigh[1], high);
def RTHlow = compoundValue(1, if bn == hRTH
then l else if l < RTHlow[1] && bn >= hRTH
then l else RTHlow[1], low);

plot
CurrentHigh = if bn >= hRTH then  RTHhigh else na;
CurrentHigh.SetDefaultColor(Color.Green);
#CurrentHigh.SetPaintingStrategy(PaintingStrategy.DASHES);
CurrentHigh.SetStyle(Curve.Short_Dash);
CurrentHigh.SetLineWeight(1);
CurrentHigh.HideBubble();
CurrentHigh.HideTitle();

plot
CurrentLow = if bn >= hRTH then RTHlow else na;
CurrentLow.SetDefaultColor(Color.Red);
#CurrentLow.SetPaintingStrategy(PaintingStrategy.DASHES);
CurrentLow.SetStyle(Curve.Short_Dash);
CurrentLow.SetLineWeight(1);
CurrentLow.HideBubble();
CurrentLow.HideTitle();

plot RTHMid = if bn >= hRTH then (RTHhigh + RTHlow) / 2 else na ;
RTHMid.SetDefaultColor(Color.Dark_Orange);
# Halfback.SetPaintingStrategy(PaintingStrategy.Line);
RTHMid.SetStyle(curve.POINTS);
RTHMid.SetLineWeight(1);
RTHMid.HideBubble();
RTHMid.HideTitle();

#
 
Hello everyone. Been away for a while. I also have been using this indicator and would like the option to only show trading hours previous day highs/lows. Is this possible?

This will provide the Previous Day's H/L/C and the current day's RTH H/L/C

Screenshot 2024-02-17 082229.png
Code:
# Previous Day High/Low/Close + RTH High/Low/Open of Day
# Some code based on code by Mobius
# Created by Wiinii
# Sleepyz added input option coding
# PM_Mid added

declare hide_on_daily;

input extend_plots       = yes;
input length             = 1;
input showOnlyLastPeriod = yes;
input showexpansiononly  = no;
input ShowBubbles        = yes;
input locate_bubbles_at_time = 0930;


def bn = BarNumber();
def na = Double.NaN;
def h  = high;
def l  = low;
def o = open;
def c = close;
def v = volume;
def aggregationPeriod = AggregationPeriod.DAY;
def displace = -1;
def timeopen = SecondsFromTime(locate_bubbles_at_time) == 0;

#----- Previous Day High/Low/Close -----#

plot PD_High;
plot PD_Low;
plot PD_Close;
def PD_H = if extend_plots and isnan(close)
           then PD_H[1]
           else Highest(high(period = aggregationPeriod)[-displace], length);
def PD_L = if extend_plots and isnan(close)
           then PD_L[1]
           else Lowest(low(period = aggregationPeriod)[-displace], length);
def PD_C = if extend_plots and isnan(close)
           then PD_C[1]
           else close(period = aggregationPeriod)[-displace];

#Futures Hours - used to limit display of plot on last day to extended RTHrs
def FTH = if extend_plots and isnan(close)
          then FTH[1]
          else secondsfromTime(0930) >= 0 and secondsfromTime(1800) < 0;
#

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PD_High = na;
    PD_Low = na;
    PD_Close = na;
} else {
    PD_High  = if (showexpansiononly and !IsNaN(close)) or (showonlylastperiod and ticksize()!=.01 and !FTH) or (showonlyLastPeriod and ticksize()==.01 and secondsfromTime(0930) < 0)
               then Double.NaN
               else PD_H;
    PD_Low   = if showexpansiononly and !IsNaN(close)  or (showonlylastperiod and ticksize()!=.01 and !FTH) or (showonlyLastPeriod and ticksize()==.01 and secondsfromTime(0930) < 0)
               then Double.NaN
               else PD_L;
    PD_Close = if showexpansiononly and !IsNaN(close) or (showonlylastperiod and ticksize()!=.01 and !FTH) or (showonlyLastPeriod and ticksize()==.01 and secondsfromTime(0930) < 0) 
               then Double.NaN
               else PD_C;
}

PD_High.SetDefaultColor(color.DARK_ORANGE);
PD_High.SetpaintingStrategy(paintingStrategy.HORIZONTAL);
PD_High.SetLineWeight(2);
PD_High.HideTitle();

PD_Low.SetDefaultColor(color.DARK_ORANGE);
PD_Low.SetpaintingStrategy(paintingStrategy.HORIZONTAL);
PD_Low.SetLineWeight(2);
PD_Low.HideTitle();

PD_Close.SetDefaultColor(color.WHITE);
PD_Close.SetPaintingStrategy(paintingStrategy.HORIZONTAL);
PD_Close.SetLineWeight(2);
PD_Close.HideTitle();

input bubble_placement = {default right_edge, timeopen};

def right_edge = barnumber() == highestall(barnumber() - 1);

DefineGlobalColor("PD_High", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_High, "PD High: " + PD_High, GlobalColor("PD_High"));

DefineGlobalColor("PD_Low", CreateColor(255,204,153));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_Low, "PD Low: " + PD_Low, GlobalColor("PD_Low"), no);

DefineGlobalColor("PD_Close", color.WHITE);
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, PD_Close, "PD Close: " + PD_Close, GlobalColor("PD_Close"));




#----- Today Open/High/Low -----#

plot High_of_Day;
plot Low_of_Day;
Plot DayOpen;
def DOpen    = if extend_plots and isnan(close)
               then DOpen[1]
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)==0
               then open
               else if ticksize()==.01
               then open(period = aggregationPeriod)[0]
               else Dopen[1];
def H_of_Day = if extend_plots and isnan(close)
               then H_of_Day[1]
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)==0
               then high
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)>0
               then max(high, H_of_Day[1])
               else if ticksize()==.01
               then  Highest(high(period = aggregationPeriod), length)
               else H_of_Day[1];
              
def L_of_Day = if extend_plots and isnan(close)
               then L_of_Day[1]
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)==0
               then low
               else if ticksize()!=.01 and getday()==getlastday() and secondsFromTime(0930)>0
               then min(low, L_of_Day[1])
               else if ticksize()==.01
               then  Lowest(low(period = aggregationPeriod), length)
               else L_of_Day[1];

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DayOpen = na;
    High_of_Day = na;
    Low_of_Day = na;
} else {
    DayOpen     = if showexpansiononly and !IsNaN(close) or secondsfromtime(0930) < 0
                  then Double.NaN
                  else DOpen;
    High_of_Day = if showexpansiononly and !IsNaN(close)
                  then Double.NaN
                  else H_of_Day;
    Low_of_Day  = if showexpansiononly and !IsNaN(close)
                  then Double.NaN
                  else L_of_Day;
}

DayOpen.SetDefaultColor (Color.GRAY);
DayOpen.SetPaintingStrategy(PaintingStrategy.DASHES);
DayOpen.SetLineWeight(2);
DayOpen.HideTitle();

High_of_Day.SetDefaultColor(CreateColor(0,128,255));
High_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
High_of_Day.SetLineWeight(2);
High_of_Day.HideTitle();

Low_of_Day.SetDefaultColor(CreateColor(0,128,255));
Low_of_Day.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Low_of_Day.SetLineWeight(2);
Low_of_Day.HideTitle();

DefineGlobalColor("Open", color.LIGHT_GRAY);
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, DayOpen, "Open: " + DayOpen, GlobalColor("Open"));

DefineGlobalColor("High_of_Day", CreateColor(102,178,255));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, High_of_Day, "High of Day: " + High_of_Day, GlobalColor("High_of_Day"));

DefineGlobalColor("Low_of_Day", CreateColor(102,178,255));
AddChartBubble(ShowBubbles and
if bubble_placement == bubble_placement.timeopen
then timeopen
else right_edge, Low_of_Day, "Low of Day: " + Low_of_Day, GlobalColor("Low_of_Day"), no);

#
 

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