Weekly and Monthly Pivots Indicator for ThinkorSwim

@Antares66 I added R4, R5, S4 and S5 pivot points. I'm using here TradingView's traditional pivot point formula.


Code:
# WeeklyMonthlyPivots_TS
# http://thinkscripter.wordpress.com
# [email protected]
# Slightly modified by durruha @ useThinkScript

input timeFrame = {default DAY, WEEK, MONTH, QUARTER, YEAR};
input showOnlyToday = yes;

DefineGlobalColor("DAY", CreateColor(255, 255, 255));
DefineGlobalColor("WEEK", CreateColor(144, 191, 143));
DefineGlobalColor("MONTH", CreateColor(19, 240, 207));
DefineGlobalColor("QUARTER", CreateColor(31, 30, 108));
DefineGlobalColor("YEAR", CreateColor(0, 0, 0));

def H = high(period = timeFrame)[1];
def L = low(period = timeFrame)[1];
def C = close(period = timeFrame)[1];

def calc_PP = (H + L + C) / 3;
def calc_R1 = calc_PP * 2 - L;
def calc_S1 = calc_PP * 2 - H;
def calc_R2 = calc_PP + (H - L);
def calc_S2 = calc_PP - (H - L);
def calc_R3 = calc_PP * 2 + (H - 2 * L);
def calc_S3 = calc_PP * 2 - (2 * H - L);
def calc_R4 = calc_PP * 3 + (H - 3 * L);
def calc_S4 = calc_PP * 3 - (3 * H - L);
def calc_R5 = calc_PP * 4 + (H - 4 * L);
def calc_S5 = calc_PP * 4 - (4 * H - L);

plot R5;
plot R4;
plot R3;
plot R2;
plot R1;
plot PP;
plot S1;
plot S2;
plot S3;
plot S4;
plot S5;


if (showOnlyToday and !IsNaN(close(period = timeFrame)[-1])) or
(GetAggregationPeriod() > if timeframe == timeframe.DAY then AggregationPeriod.DAY
else if timeframe == timeframe.WEEK then AggregationPeriod.WEEK
else if timeframe == timeframe.MONTH then AggregationPeriod.MONTH
else if timeframe == timeframe.QUARTER then AggregationPeriod.QUARTER
else AggregationPeriod.YEAR)
then {

    R5 = Double.NaN;
    R4 = Double.NaN;
    R3 = Double.NaN;
    R2 = Double.NaN;
    R1 = Double.NaN;
    PP = Double.NaN;
    S1 = Double.NaN;
    S2 = Double.NaN;
    S3 = Double.NaN;
    S4 = Double.NaN;
    S5 = Double.NaN;

}
else {

    R5 = calc_R5;
    R4 = calc_R4;
    R3 = calc_R3;
    R2 = calc_R2;
    R1 = calc_R1;
    PP = calc_PP;
    S1 = calc_S1;
    S2 = calc_S2;
    S3 = calc_S3;
    S4 = calc_S4;
    S5 = calc_S5;

}

R1.SetDefaultColor(GlobalColor(timeframe));
R2.SetDefaultColor(GlobalColor(timeframe));
R3.SetDefaultColor(GlobalColor(timeframe));
R4.SetDefaultColor(GlobalColor(timeframe));
R5.SetDefaultColor(GlobalColor(timeframe));
S1.SetDefaultColor(GlobalColor(timeframe));
S2.SetDefaultColor(GlobalColor(timeframe));
S3.SetDefaultColor(GlobalColor(timeframe));
S4.SetDefaultColor(GlobalColor(timeframe));
S5.SetDefaultColor(GlobalColor(timeframe));
PP.SetDefaultColor(GlobalColor(timeframe));

R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

PP.SetLineWeight(2);
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Last edited:
Hello ... is there an indicator that places pivot points without premarket on the chart with premarket? I'm looking for it but can't find it.
thanks
 
the script only account for the open market High / Low, right? but the default PivotPoint account for EXT H/L so they don't line up? is there a way to select EXT or open hour?
 
Hi, I have the pivot point indicator now, now I want it to switch automatically to the weekly pivot when I switch to the 4hr or 1hr chart and switch back to the daily pivot when I go to the 5mins or 2mins chart. Please help me with the code

Thank you in advance!!
 
Is there a study that will plot weekly resistance on current time frame charts?

I'm on the 1m timeframe, how do I make the plots extend to the right?

axG5f6N.jpg
 
@geebeeaye Have you gone to Chart Settings > Time Axis > Expansion Area and increased that setting...??? If that doesn't help then we'd need to see about tweaking the study code...
 
@geebeeaye Ok... I got it to act up now... The aggregation as hard-coded won't allow the lines to display and the code needs to be modified for lower timeframes... I was confusing the lines I was seeing with another chart study... My mistake...

The code posted by @durruha has been modified to expand aggregation periods from what @BenTen originally posted but it still needs to be modified for intraday...
 
I'm trying to setup an indicator that would look back at previous pivot points based on a given timeframe and indicate relative strength of that pivot point as a support or resistance for the current day. Is this possible? Does anyone have an example code that I could use?

Ben, Do you know if its possible to compare the previous pivot points to the current pivot points to define levels with greater support or resistance? For example in the plot above the three red lines at 77.5 would be give a higher value than the one R2 level at 80. Another example would be the S1 at 68.18 would be give a higher value than [email protected] and [email protected].
 
Hi Friends - Need help to write a screener that fetches that stocks, when the price opens above weekly central pivot point and price has increased in the last 5 min candles consistently. Here is what I've. Can someone please help me.

Code:
def today = GetWeek() == GetLastWeek();
def mktOpen = SecondsFromTime(630) == 0 or GetWeek() <> GetWeek()[1];
def LweekOpen = if today then LweekOpen[1] else if mktOpen then open else LweekOpen[1]; #Last week open
def LweekHigh = if today then LweekHigh[1] else if mktOpen then high else if high > LweekHigh[1] then high else LweekHigh[1]; #Last week yesterday's high
def LweekLow = if today then LweekLow[1] else if mktOpen then low else if low < LweekLow[1] then low else LweekLow[1]; #Last weeks low
def LweekClose = if today then LweekClose[1] else close; #Last week close

def calc_PP = (LweekHigh + LweekLow + LweekClose) / 3;


def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
plot PatternPlot =
    IsUp[3] and
    IsUp[2] and
    IsUp[1] and
    IsUp[0] and
    open[3] <= low[2] and
    open[2] <= low[1] and
    open[1] <= low[0] and
    calc_PP<=Open[4];
 
Hi Friends - Need help to write a screener that fetches that stocks, when the price opens above weekly central pivot point and price has increased in the last 5 min candles consistently. Here is what I've. Can someone please help me.

Code:
def today = GetWeek() == GetLastWeek();
def mktOpen = SecondsFromTime(630) == 0 or GetWeek() <> GetWeek()[1];
def LweekOpen = if today then LweekOpen[1] else if mktOpen then open else LweekOpen[1]; #Last week open
def LweekHigh = if today then LweekHigh[1] else if mktOpen then high else if high > LweekHigh[1] then high else LweekHigh[1]; #Last week yesterday's high
def LweekLow = if today then LweekLow[1] else if mktOpen then low else if low < LweekLow[1] then low else LweekLow[1]; #Last weeks low
def LweekClose = if today then LweekClose[1] else close; #Last week close

def calc_PP = (LweekHigh + LweekLow + LweekClose) / 3;


def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
plot PatternPlot =
    IsUp[3] and
    IsUp[2] and
    IsUp[1] and
    IsUp[0] and
    open[3] <= low[2] and
    open[2] <= low[1] and
    open[1] <= low[0] and
    calc_PP<=Open[4];
@BenTen can you please help me on this.
 

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