Strong Pivots For ThinkOrSwim

Chemmy

Active member
Hey all, I made a pivot study based off of an interesting idea I saw on TradingView which filters out "weak" pivots, and instead only tries to select stronger pivots based on more extreme/volatile action. In addition to the usual pivot or swing high/low logic that looks for the highest high and lowest low within X number of bars, this indicator also has an added ATR multiplier tacked on top of the average price within a set period, so pivots should generally only be established from strong price action.

Here is QQQ from 8/14/23, as you can see there were existing pivots from the prior trading day that acted both as support right off open and then a solid resistance break after. Then the new pivot that forms at the end of the morning run acts as a strong resistance for the rest of the day:
1692235810146.png


Another great example of how this can be used is from today, 8/16/23 -- Again, the morning resistance holds strong for a triple top and the support pivots hold solid as well for a breakdown play as well as a double bottom:
1692236079245.png


In the code, I've added functionality for all time frames, as well as a filter for pivots to only form within regular trading hours and more. I don't believe that it "repaints", as it shouldn't paint until after the LB number of bars, but let me know if you see anything I don't. Hope some of you find this useful as I have, happy trading!

http://tos.mx/QdcFPDO

Code:
# Filter out Weak pivot highs/lows
input lb = 15; # pivots: lookback/forward
input atrlen = 30;
input atrMult = 1.5; # Spikeyness Index
input useSpikeyCond = yes; # use spikey condition
input confirmOnClose = yes; # wait 1x bar to confirm (avoid repainting)
input project_pivots = yes;
input show_arrows = no;
input usecharttime = yes;
input agg = aggregationperiod.fifteen_min;
input add_boundClouds = yes;
input pivot_margin = 0.25;
input use_rth = yes;
input rth_start = 0930;
input rth_end = 1600;
def rth = SecondsFromTime(rth_start) >= 0 and SecondsTillTime(rth_end) >= 0;

def x = if confirmOnClose then 1 else 0;
def atr = ATR(atrlen);

#//MTF
def TFLow;
def TFHigh;
def TFClose;

if UseChartTime
then {
    TFLow   = low;
    TFHigh  = high;
    TFClose = close;
} else {
    TFLow = low(period = agg);
    TFHigh = high(period = agg);
    TFClose = close(period = agg);
}


# Pivot highs & Pivot lows: filtering out the rounded/unimpressive pivot highs
def pivHigh = if use_rth then (if rth and (Highest(TFHigh, lb) <= TFHigh and highest(TFHigh[-lb], lb) <= TFHigh ) then TFHigh else double.nan) else if (Highest(TFHigh, lb) <= TFHigh and highest(TFHigh[-lb], lb) <= TFHigh ) then TFHigh else double.nan;
def isPivHigh = !IsNaN(pivHigh);
def maH = Average(TFHigh, 2 * lb);
def spikyH = if useSpikeyCond then pivHigh > maH + (atrMult * atr) else pivHigh and TFHigh > maH;;

plot ph = (isPivHigh[x] and spikyH[x]);
ph.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ph.sethiding(!show_arrows);

def pivothigh = if isPivHigh and spikyH then TFHigh else Double.NaN;
def pivothigh1 = if !IsNaN(pivothigh[1]) then pivothigh[1] else pivothigh1[1];

plot project_ph = pivothigh1;
project_ph.setpaintingstrategy(paintingstrategy.horizontal);
project_ph.setdefaultcolor(color.green);
project_ph.sethiding(!project_pivots);

addcloud(if add_boundClouds then project_ph - pivot_margin else double.nan, project_ph + pivot_margin, color.light_green, color.light_green);

### Pivot Lows
def pivLow = if use_rth then (if rth and (Lowest(TFLow, lb) >= TFLow  and lowest(TFLow[-lb], lb) >= TFLow) then TFLow else double.nan) else if (Lowest(TFLow, lb) >= TFLow  and lowest(TFLow[-lb], lb) >= TFLow) then TFLow else double.nan;
def isPivLow = !IsNaN(pivLow);
def maL = Average(TFLow, 2 * lb);
def spikyL = if useSpikeyCond then pivLow < maL - (atrMult * atr) else pivLow and TFLow < maL;;

plot pl = isPivLow[x] and spikyL[x];
pl.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pl.sethiding(!show_arrows);

def pivotlow = if isPivLow and spikyL then TFLow else Double.NaN;
def pivotlow1 = if !IsNaN(pivotlow[1]) then pivotlow[1] else pivotlow1[1];

plot project_pl = pivotlow1;
project_pl.setpaintingstrategy(paintingstrategy.horizontal);
project_pl.setdefaultcolor(color.red);
project_pl.sethiding(!project_pivots);

addcloud(if add_boundClouds then project_pl - pivot_margin else double.nan,  project_pl + pivot_margin, color.light_red, color.light_red);
 
@Chemmy The clouds around the pivot line don't show up... Do you know maybe why?

Edit: Clouds don't show up on futures charts for some odd reason... Works on QQQ for example but not on /NQ.
 
@Chemmy The clouds around the pivot line don't show up... Do you know maybe why?

Edit: Clouds don't show up on futures charts for some odd reason... Works on QQQ for example but not on /NQ.

Interesting.. I'll look into it. I don't trade futures but I also can't think of a reason why it wouldn't work on them.

Edit: The clouds are working for me on futures, but it's almost hidden due to how large the futures prices are. You should be able to see them if you edit the pivot margin setting to a higher number, and I may add functionality to show the clouds as a percentage of price rather than a specific dollar/cent amount.
 
Interesting.. I'll look into it. I don't trade futures but I also can't think of a reason why it wouldn't work on them.

Edit: The clouds are working for me on futures, but it's almost hidden due to how large the futures prices are. You should be able to see them if you edit the pivot margin setting to a higher number, and I may add functionality to show the clouds as a percentage of price rather than a specific dollar/cent amount.
Hello Chemmy. Thank you for this Pivot study. I also trade the /NQ using the 5 min chart. Would appreciate it if looks like the QQQ. The QQQ chart looks great with the think horizontal bars showing points of S/R.

If I am using the 5 min chart, what would be the optimal setting to id points of S/R. Is your default settings optimal for the 5 min chart?

Thank you again for this. I will look to see how it performs on Tuesday 9/4/23.
 
@Chemmy I have few questions about this. I am using this on 5 min chart but when the pivot shifts or shows up in the current day its already an hour later than it shows up any way to make it show sooner so we can take action on it. Second I put in alerts on this script but it doesnt play the sound when the pivot shows up or shifts.
 
Last edited:

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