Nerds Pivots - All In One For ThinkOrSwim

nerdytrader

New member
I want to give back to the community and share a Thinkscript I've been putting together. I know it can be a pain to find a basic High/ Low pivots that plots how you want it to plot and is clean (as in chart friendly, not too crowded, doesn't block candles etc ). So I came up with this.
Nerds Pivots.png
Nerds Pivots 2.png
Pivots Menu.png

So, this script has all of them and is somewhat user customizable.
Plot Current Day High, Current Day Low, Current Day
The settings allow you to:
  • Use either 4:00am EST as Day Open or Use 9:30am EST as Day Open
  • Disable displaying the Previous Day Pivots while still showing the Current Day Pivots.
  • Plot pivots across the full 24 hours current day only
  • Plot the pivots in the Expansion Area (Price Axis)
  • Or plot both Current days and and Past Days
  • Each Plot Displays a Chart Bubble that does not invade the candles ( They are pinned to the price axis and or will not touch or crowd candles)
The Plots:
  • Current High, Current Low,
  • Current Variable Open (Choose either 4am or 930am)
- Last Close 4pm EST
  • Previous Day High, Previous Day Low,
  • Previous Day Close
  • Opening Range / ORB (Choose What Time You Want To Use, Default Is 930-10am) Displays a cloud for the Range and displays the High, Low and Mid Range. You can either extend the cloud across the chart of Display is in the expansion area only.
  • and the Overnight High and Overnight Low between Last Close And Current Open ( 4pm to 930am).

I was going to work the code to allow for chosing to show Premarket High and Low and Globex High and Low, but everyone has a different idea about when the market opens, depending on Futures or stocks, but everyone can agree that the Regular Trading Close and Regular Trading Open is at 4pm and 930am EST and I feel that regardless of premarket vs globex, the data that matters most will always be the higher high and lower lower. So writing the code in this way, if the premarket has a higher high or lower low, well then it will use that. If the Globex had a higher high but the premarket had a lower low, then it will use the globex high and the premarket low.

## Start Code
#Nerds Pivots
declare upper;

plot Hide = Double.NaN;
Hide.SetDefaultColor(Color.BLACK);

#Select Yes (Use One Setting At A Time) To Display Pivots At Specific Spots On Chart

input ShowAllDays = no ; # Plots Pivot Lines On All Days On Chart Agg
input PriceAxisOnly = yes; # Plots Pivot Lines In The Expansion Area
input TodayOnly = no; # Plots Pivot Lines Across Chart For Current Day Only
input ShowPrevDayHLC = yes; # Show Or Hide Previous Day Pivots
# Yes = 4:00am Est Open Pivot / No = 9:30am Est Open Pivot
input UsePreMarketOpen = yes;
# Yes = Plots ORB Cloud Across Current Day - No = Plots Orb Cloud In Expansion Area
input ExtendOpeningRange = no;
# Opening Range Start Time And End Time
input OR_Start = 930; ## Opening Range Start Time
input OR_Stop = 1000; ## Opening Range Stop Time

def Bar = BarNumber();
def Nan = Double.NaN;
def Day = AggregationPeriod.DAY ;
def H = high(period = Day);
def L = low(period = Day);
def C = close(period = Day);
def O = open(period = Day);
def PdayH = high(period = "day")[1];
def PdayL = low(period = "day")[1];
def PdayC = close(period = "day" )[1];

def PlotsDomain = !IsNaN(close) == ExtendOpeningRange;
def PinToAxis = IsNaN(close) == PriceAxisOnly;

def Today =
GetDay() == GetLastDay() ;
def RegularHours =
GetTime() >= RegularTradingStart(GetYYYYMMDD())
and GetTime() <= RegularTradingEnd(GetYYYYMMDD());
def PmOpenTime =
SecondsTillTime (400) == 0;
def OpenPremarket =
if SecondsTillTime (400) == 0 and SecondsFromTime (400) == 0 then 1 else 0;

def IntradayHours = GetAggregationPeriod() < AggregationPeriod.DAY;
def PreHours = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PostHours = RegularTradingStart (GetYYYYMMDD()) < GetTime();

## ============== DAILY HIGH AND LOW ============== ##

# Intraday High and Low
def DayHigh = if RegularHours then H else if H > DayHigh[1] then H else DayHigh[1];
def DayLow = if RegularHours then L else if L > DayLow[1] then L else DayLow[1];
def DayHighBar = if high == DayHigh then Bar else DayHighBar[1];
def DayLowBar = if low == DayLow then Bar else DayLowBar[1];
def DailyHigh =
if Bar == HighestAll(DayHighBar) then high else DailyHigh[1];
def DailyLow =
if Bar == HighestAll(DayLowBar) then low else DailyLow[1];

def HighAxis = if PinToAxis then DailyHigh else Nan;
def LowAxis = if PinToAxis then DailyLow else Nan;
def HighExpandToday = if TodayOnly == yes then DailyHigh else DailyHigh;
def LowExpandToday = if TodayOnly == yes then DailyLow else Nan;

# Plot High Of Day And Low Of Day
plot Highs =
if PriceAxisOnly == yes then HighAxis
else if ShowAllDays == yes then H
else if TodayOnly == yes then HighExpandToday else Nan;

plot Lows =
if PriceAxisOnly == yes then LowAxis
else if ShowAllDays == yes then L
else if TodayOnly == yes then LowExpandToday else Nan;

## ============== VARIABLE OPEN ( PREMARKET TIME / NORMAL TIME ) LAST DAILY CLOSE ============== ##

# Premarket Open
def PMopenBar = PmOpenTime != PmOpenTime[1];
def PMOpen = if Today and PMopenBar then open else PMOpen[1];
def PremarketOpen = PMOpen ;

def VarOpen = if UsePreMarketOpen == yes then PremarketOpen else open(period = Day);

# Normal Time Open
def OpenAxis = if PriceAxisOnly == yes and PinToAxis then VarOpen else Nan;
def OpenExpandAllDays = if ShowAllDays == yes then VarOpen else Nan;
def OpenExpandToday = if TodayOnly == yes and Today then VarOpen else Nan;

# Last Close
def CloseAxis = if PriceAxisOnly == yes and PinToAxis then C else Nan;
def CloseExpandAllDays = if ShowAllDays == yes then C else Nan;
def CloseExpandToday = if TodayOnly == yes and Today then C else Nan;

# Plot Daily Open And Close
plot Opens =
if PriceAxisOnly == yes then OpenAxis
else if ShowAllDays == yes then OpenExpandAllDays
else if TodayOnly == yes then OpenExpandToday else Nan;

plot Closes =
if PriceAxisOnly == yes then CloseAxis
else if ShowAllDays == yes then CloseExpandAllDays
else if TodayOnly == yes then CloseExpandToday else Nan;

## ============== PREVIOUS DAILY HIGH, LOW, CLOSE ============== ##
## You Can Choose To Display Or Not Display These Plots By Selecting ShowPrevDayHLC in Settings And Choosing Yes Or No

# Previous High
def PrevHighAxis = if PriceAxisOnly == yes and PinToAxis then PdayH else Nan;
def PrevHighExpandToday = if TodayOnly == yes and Today then PdayH else Nan;
# Previous Low
def PrevLowAxis = if PriceAxisOnly == yes and PinToAxis then PdayL else Nan;
def PrevLowExpandToday = if TodayOnly == yes and Today then PdayL else Nan;
# Previous Close
def PrevCloseAxis = if PriceAxisOnly == yes and PinToAxis then PdayC else Nan;
def PrevCloseExpandToday = if TodayOnly == yes and Today then PdayC else Nan;

plot PrevHighs =
if ShowPrevDayHLC == no then nan
else if PriceAxisOnly == yes then PrevHighAxis
else if TodayOnly == yes then PrevHighExpandToday else Nan;

plot PrevLows =
if ShowPrevDayHLC == no then nan
else if PriceAxisOnly == yes then PrevLowAxis
else if TodayOnly == yes then PrevLowExpandToday else Nan;

plot PrevCloses =
if ShowPrevDayHLC == no then nan
else if PriceAxisOnly == yes then PrevCloseAxis
else if TodayOnly == yes then PrevCloseExpandToday else Nan;

## ====================== OPENING RANGE ====================== ##
## Opening Range - In The Settings You Can Select The Time Frame You'd like For The Range And Choose To ExtendOpeningRange The Cloud Across The Day Or Pin It To The Expansion Area By The Price Axis

def Opening_Range_Is_Active =
if SecondsTillTime(OR_Start) <= 0
and SecondsTillTime(OR_Stop) >= 0
then 1 else 0;

def Opening_Range_High =
if SecondsTillTime(OR_Start) == 0 then high
else if Opening_Range_Is_Active
and high > Opening_Range_High[1]
then high else Opening_Range_High[1];

def Opening_Range_Low =
if SecondsTillTime(OR_Start) == 0 then low
else if Opening_Range_Is_Active
and low < Opening_Range_Low[1]
then low else Opening_Range_Low[1];

plot Range_High =
if plotsDomain and BarNumber() >= HighestAll(Opening_Range_High)
then HighestAll(if IsNaN(close[-1]) then Opening_Range_High
else Nan) else Nan;

plot Range_Low =
if plotsDomain and BarNumber() >= HighestAll(Opening_Range_Low)
then HighestAll(if IsNaN(close[-1]) then Opening_Range_Low
else Nan) else Nan;

plot Range_Mid = (Range_High + Range_Low) / 2 ;

## -------------------------- GLOBEX PIVOTS --------------------------- ##
## This Will Plot The FULL OVERNIGHT + PREMARKET Highest High And Lowest Low. It Finds The Highest High And Lowest Low Between 4:00 PM And 9:30 AM By Deciding If The Globex Session Or The Premarket Session Had The Highs Or Lows.

def PostHigh =
if !RegularHours and RegularHours[1] then High
else if !RegularHours and High > PostHigh[1] then High else PostHigh[1];
def PostLow =
if !RegularHours and RegularHours[1] then Low
else if !RegularHours and Low < PostLow[1] then Low else PostLow[1];

def PosthighBar = if !RegularHours and High == PostHigh then Bar else PosthighBar[1];
def PostlowBar = if !RegularHours and Low == PostLow then Bar else PostlowBar[1];

def NightHigh = if Bar== HighestAll(PosthighBar) then High else NightHigh[1];
def NightLow = if Bar == HighestAll(PostlowBar) then Low else NightLow[1];

plot OvernightHigh = if IntradayHours and NightHigh > 0 then NightHigh else Nan;
plot OvernightLow = if IntradayHours and NightLow > 0 then NightLow else Nan;

## -------------------------- PREMARKET PIVOTS --------------------------- ##
def isPremarket = PostHours[1] and PreHours;
def StartPremarket = (GetDay() == GetLastDay()) and SecondsFromTime(010) >= 0 and !IsNaN(close);
def Active_PreMarket = StartPremarket and SecondsTillTime(930) > 0 and SecondsFromTime(010) >= 0 ;

def PMHigh =
if !isPremarket and isPremarket[1] then High
else if !isPremarket and High > PMHigh[1] then High else PMHigh[1];
def PMLow =
if !isPremarket and isPremarket[1] then Low
else if !isPremarket and Low < PMLow[1] then Low else PMLow[1];

def PMHighA =
CompoundValue(1, if isPremarket then High else if PreHours then Max(High, PMHighA[1])
else PMHighA[1], 0);
def PMLowA =
CompoundValue(1, if isPremarket then Low else if PreHours then Min(Low, PMLowA[1])
else PMLowA[1], 0);

def highBar = if PreHours and High == PMHighA then Bar else Nan;
def lowBar = if PreHours and Low == PMLowA then Bar else Nan;
def PMHighBar = if Bar == HighestAll(HighBar) then PMHighA else PMHighBar[1];
def PMLowBar = if Bar == HighestAll(LowBar) then PMLowA else PMLowBar[1];

plot PremarketHigh = if PMHighBar != 0 then PMHighBar else Nan;
plot PremarketLow = if PMLowBar != 0 then PMLowBar else Nan;

# The Logic To Hide The Lower High and Higher Low Of Overnight / Premarket Session
OvernightHigh.sethiding( highestall(OvernightHigh) < highestall(PremarketHigh) );
PremarketHigh.sethiding( highestall(PremarketHigh) < highestall(OvernightHigh));
OvernightLow.sethiding( highestall(OvernightLow) > highestall(PremarketLow));
PremarketLow.sethiding( highestall(PremarketLow)> highestall(OvernightLow));

def "Bubble Off - PmH" = highestall(PremarketHigh) < highestall(OvernightHigh);
def "Bubble Off - PmL" =highestall(PremarketLow) > highestall(OvernightLow);
def "Bubble Off - OnH" = highestall(OvernightHigh) < highestall(PremarketHigh);
def "Bubble Off - OnL" =highestall(OvernightLow) > highestall(PremarketLow);

## ====================== CLOUDS ====================== ##
## Change The Cloud Color Here Or In Settings Under Globals

DefineGlobalColor("OpenRangeCloud", Color.WHITE);
AddCloud(Range_High, Range_Low, GlobalColor("OpenRangeCloud"), GlobalColor("OpenRangeCloud"));

## -------------------------- CHART BUBBLES --------------------------- ##

## Daily High
AddChartBubble(if PriceAxisOnly == yes then Bar == HighestAll(Bar) else Bar == DayHighBar, Highs, "H", Highs.TakeValueColor(), 1);
## Daily Low
AddChartBubble(if PriceAxisOnly == yes then Bar == HighestAll(Bar) else Bar == DayLowBar , Lows, "L", Lows.TakeValueColor(), 0);

## Daily Open
AddChartBubble(Bar == HighestAll(Bar) , Opens , "Open" , Opens.TakeValueColor(), 0);
## Daily Close
AddChartBubble(Bar == HighestAll(Bar) , Closes , "Close" , Closes.TakeValueColor(), 1);

## Previous Day High
AddChartBubble(Bar == HighestAll(Bar), PrevHighs, "< H" , PrevHighs.TakeValueColor(), 1);
## Previous Day Low
AddChartBubble(Bar == HighestAll(Bar), PrevLows, "< L" , PrevLows.TakeValueColor(), 0);
## Previous Day Close
AddChartBubble(Bar == HighestAll(Bar), PrevCloses, "< Close" , PrevCloses.TakeValueColor(), 0);

## Premarket High
AddChartBubble(Bar== if "Bubble Off - PmH" then nan else highestall(HighBar), PMHigh , "ON H", PremarketHigh.takevalueColor (), 1);
## Premarket Low
AddChartBubble( if "Bubble Off - PmL" then nan else Bar == highestall(LowBar), PMLow, "ON L", PremarketLow.takevalueColor (), 0);

## Globex High
AddChartBubble(Bar == if "Bubble Off - OnH" then nan else highestall(PosthighBar), OvernightHigh, "ON H", OvernightHigh.TakeValueColor (), 1);
## Globex Low
AddChartBubble(Bar ==if "Bubble Off - OnL" then nan else highestall(PostlowBar), OvernightLow, "ON L", OvernightLow.TakeValueColor (), 0);


## -------------------------- DEFINE DEFAULT VALUES --------------------------- ##

Opens.SetPaintingStrategy (PaintingStrategy.HORIZONTAL);
Opens.SetDefaultColor (Color.MAGENTA);
Opens.SetLineWeight (2);

Highs.SetPaintingStrategy (PaintingStrategy.HORIZONTAL);
Highs.SetDefaultColor (Color.WHITE);
Highs.SetLineWeight (3);
PrevHighs.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevHighs.SetDefaultColor(Color.LIGHT_GRAY);
PrevHighs.SetLineWeight(2);

Lows.SetPaintingStrategy (PaintingStrategy.HORIZONTAL);
Lows.SetDefaultColor (Color.WHITE);
Lows.SetLineWeight (3);
PrevLows.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevLows.SetDefaultColor(Color.LIGHT_GRAY);
PrevLows.SetLineWeight(2);

Closes.SetPaintingStrategy (PaintingStrategy.HORIZONTAL);
Closes.SetDefaultColor(Color.LIME);
Closes.SetLineWeight (2);
PrevCloses.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PrevCloses.SetDefaultColor(Color.LIME);
PrevCloses.SetLineWeight(2);

PremarketHigh. SetLineWeight (3);
PremarketHigh.setdefaultColor (color.blue);
PremarketHigh.setpaintingStrategy (paintingStrategy.HORIZONTAL);
PremarketLow.SetLineWeight (3);
PremarketLow.setdefaultColor (color.blue);
PremarketLow.setpaintingStrategy (paintingStrategy.HORIZONTAL);

OvernightHigh.SetLineWeight (3);
OvernightHigh.SetDefaultColor(color.blue);
OvernightHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
OvernightLow.SetLineWeight (3);
OvernightLow.SetDefaultColor(color.blue);
OvernightLow. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


# To Unhide Price Bubble, Place a " # " In Front Of The Price Bubble You Want To Hide below
#To Hide Price Bubble, Place a " # " In Front Of The Price Bubble You Want To Hide below

PremarketHigh. HideTitle (); PremarketHigh. HideBubble ();
PremarketLow.HideTitle (); PremarketLow. HideBubble ();
OvernightHigh.HideBubble ();OvernightHigh.HideTitle ();
OvernightLow.HideBubble ();OvernightLow.HideTitle ();
PrevHighs.HideTitle ();PrevHighs.HideBubble();
PrevLows.HideTitle ();PrevLows.HideBubble();
PrevCloses.HideTitle ();PrevCloses.HideBubble();
Closes.HideTitle ();Closes.HideBubble();
Opens.HideTitle ();Opens.HideBubble();
Highs.HideTitle ();Highs.HideBubble();
Lows.HideTitle ();Lows.HideBubble();


## End Nerd Pivots
 

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

Bro .. This is a ton of awesome work ! I have been trying to play with to accomplish plotting out the daily high and low for the past week which works as I am interested. However, I want the lines to plot from 12mid Ny to 12mid NY. I have tried adjusting the 'or start' input to 0 and and the 'or stop' input to 0, but the lines do not seem to change. Is there something else I need to toggle or is the code not made to do these types of adjustments.

Thx in advance.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
387 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