shows the previous day's premarket high and low instead of the previous day's regular trading hours high/low.

autoloader

Member
VIP
This code is exactly how I want it except it still shows the previous day's premarket high and low instead of the previous day's regular trading hours high/low.

Has anyone ever figured out a fix for this?

https://usethinkscript.com/threads/...-open-of-day-atr-lines-for-thinkorswim.13139/
Code:
# Previous Day High/Low/Close + Premarket High/Low + High/Low/Open of Day
# Some code based on code by Mobius
# Created by Wiinii

# tweaked to show previous day's HLC and premarket hi/lo only

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", 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", 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", 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;
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;
} else {
    PM_High = PM_H;
    PM_Low  = PM_L;
}

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

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

DefineGlobalColor("PM_Low", CreateColor(102,255,255));
AddChartBubble(ShowBubbles and right_edge, PM_Low, "PM Low", GlobalColor("PM_Low"), no);
 
Last edited by a moderator:

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