Traditional Pivot Points Indicator for ThinkorSwim

Ronin13

Member
VIP
Have searched high and low but cannot find anything akin to the standard Traditional Pivot Points indicator for ToS:

Wq1EmI9.png


Anyone have any leads, please help?

Thanks!
 

Ronin13

Member
VIP
yes i have @BenTen , ToS does have it as a default indicator. however, it is very crude (see image below) , plus the source code is inaccessible. and yes, i have tried all the indicators there, other 3 are variations of the PP

LASk6Pl.png
 

BenTen

Administrative
Staff member
Staff
VIP
Try the following code:

Code:
# Traditional Pivot Points
# Assembled by BenTen at UseThinkScript.com
# Based on the formula from https://www.tradingview.com/support/solutions/43000521824-pivot-points-standard/

input aggregationPeriod = AggregationPeriod.DAY;
def HIGHprev = high(period = aggregationPeriod)[1];
def LOWprev = low(period = aggregationPeriod)[1];
def CLOSEprev = close(period = aggregationPeriod)[1];

plot PP = (HIGHprev + LOWprev + CLOSEprev) / 3;
plot R1 = PP * 2 - LOWprev;
plot S1 = PP * 2 - HIGHprev;
plot R2 = PP + (HIGHprev - LOWprev);
plot S2 = PP - (HIGHprev - LOWprev);
plot R3 = PP * 2 + (HIGHprev - 2 * LOWprev);
plot S3 = PP * 2 - (2 * HIGHprev - LOWprev);

PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 

Bugs_Munny

New member
I am looking for the standard ToS pivot points the provide, but I would like to see the actual lines labeled S1 S2 PP R1 R2 on the right along with the price. Thank you!
 

Ronin13

Member
VIP
thanks @BenTen , gave this a spin. looks good, only the open and close timeframe does not seem to gel with futures contracts O&C.

and yes - can you please advise the code needed to label the lines S3 through R3 (as suggested by @Bugs_Munny) as well as to change line appearance? (e.g. dotted lines)
 

Luis.Fernando

New member
Try the following code:

Code:
# Traditional Pivot Points
# Assembled by BenTen at UseThinkScript.com
# Based on the formula from https://www.tradingview.com/support/solutions/43000521824-pivot-points-standard/

input aggregationPeriod = AggregationPeriod.DAY;
def HIGHprev = high(period = aggregationPeriod)[1];
def LOWprev = low(period = aggregationPeriod)[1];
def CLOSEprev = close(period = aggregationPeriod)[1];

plot PP = (HIGHprev + LOWprev + CLOSEprev) / 3;
plot R1 = PP * 2 - LOWprev;
plot S1 = PP * 2 - HIGHprev;
plot R2 = PP + (HIGHprev - LOWprev);
plot S2 = PP - (HIGHprev - LOWprev);
plot R3 = PP * 2 + (HIGHprev - 2 * LOWprev);
plot S3 = PP * 2 - (2 * HIGHprev - LOWprev);

PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
How can I name the text. S1, S2, S3, PP, R1, R2, R3? Thanks !!!
 

SleepyZ

Active member
How can I name the text. S1, S2, S3, PP, R1, R2, R3? Thanks !!!

This puts bubbles with pivot names and price levels for each pivot point.
Code:
# Traditional Pivot Points
# Assembled by BenTen at UseThinkScript.com
# Based on the formula from https://www.tradingview.com/support/solutions/43000521824-pivot-points-standard/
# Sleepyz - Modifications to show bubbles with label and/or price level


input showonlyLastPeriod = yes;
input show_bubble        = yes;
input show_price         = yes;

input aggregationPeriod = AggregationPeriod.DAY;
def dayCount = CompoundValue(1, if GetYYYYMMDD() != GetYYYYMMDD()[1] then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount) - dayCount) ;
def HIGHprev = high(period = aggregationPeriod)[1];
def LOWprev = low(period = aggregationPeriod)[1];
def CLOSEprev = close(period = aggregationPeriod)[1];

plot PP = if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1])
          then double.nan
          else (HIGHprev + LOWprev + CLOSEprev) / 3;
plot R1 = PP * 2 - LOWprev;
plot S1 = PP * 2 - HIGHprev;
plot R2 = PP + (HIGHprev - LOWprev);
plot S2 = PP - (HIGHprev - LOWprev);
plot R3 = PP * 2 + (HIGHprev - 2 * LOWprev);
plot S3 = PP * 2 - (2 * HIGHprev - LOWprev);

PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else R3 != R3[1],
                R3,
                "R3: "+if !show_price then ""
                       else AsText(Round(R3 / TickSize(), 0) * TickSize()), Color.green);

AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else R2 != R2[1],
                R2,
                "R2: "+if !show_price then ""
                       else AsText(Round(R2 / TickSize(), 0) * TickSize()), Color.yellow);

AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else R1 != R1[1],
                R1,
                "R1: "+if !show_price then ""
                       else AsText(Round(R1 / TickSize(), 0) * TickSize()), Color.red);

AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else PP != PP[1],
                PP,
                "PP: "+if !show_price then ""
                       else AsText(Round(PP / TickSize(), 0) * TickSize()), Color.CYAN);

AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else S3 != S3[1],
                S3,
                "S3: "+if !show_price then ""
                       else AsText(Round(S3 / TickSize(), 0) * TickSize()), Color.gray, no);

AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else S2 != S2[1],
                S2,
                "S2: "+if !show_price then ""
                       else AsText(Round(S2 / TickSize(), 0) * TickSize()), Color.dark_orange, no);

AddChartBubble( show_bubble and
                if showonlyLastPeriod
                then thisDay[1] == 1 and thisDay == 0
                else S1 != S1[1],
                S1,
                "S1: "+if !show_price then ""
                       else AsText(Round(S1 / TickSize(), 0) * TickSize()), Color.white, NO);
Capture.jpg
 

nicktrader

New member
Does anyone know why the above code is "off" from the delivered PivotPoints within TOS? In some cases, they do not line up with any values. I find it strange if they are both using the "traditional" method of calculating the data points. Its all the same math. ??
 

SleepyZ

Active member
TOS pivot points calculation is proprietary and my understanding slightly different than traditional pivot points. Here is the code:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#
# Source code isn't available.

input showOnlyToday = No;
input timeFrame = {default "DAY", "WEEK", "MONTH"};

plot R3 = Double.NaN;
plot R2 = Double.NaN;
plot R1 = Double.NaN;
plot PP = Double.NaN;
plot S1 = Double.NaN;
plot S2 = Double.NaN;
plot S3 = Double.NaN;
 

SleepyZ

Active member
@BenTen I am using standard pivot point study that comes with TOS. Is it possible to enable an alert whenever price crosses the pivot level up or down?
This seems to work by referencing the pivot point as pivotpoints().pp
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#
# Source code isn't available.

input showOnlyToday = No;
input timeFrame = {default "DAY", "WEEK", "MONTH"};

plot R3 = Double.NaN;
plot R2 = Double.NaN;
plot R1 = Double.NaN;
plot PP = Double.NaN;
plot S1 = Double.NaN;
plot S2 = Double.NaN;
plot S3 = Double.NaN;

alert(close crosses pivotpoints().pp, "PP cross", alert.bar, sound.ding);
 

SMB777

New member
VIP
This seems to work by referencing the pivot point as pivotpoints().pp
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#
# Source code isn't available.

input showOnlyToday = No;
input timeFrame = {default "DAY", "WEEK", "MONTH"};

plot R3 = Double.NaN;
plot R2 = Double.NaN;
plot R1 = Double.NaN;
plot PP = Double.NaN;
plot S1 = Double.NaN;
plot S2 = Double.NaN;
plot S3 = Double.NaN;

alert(close crosses pivotpoints().pp, "PP cross", alert.bar, sound.ding);
Thank You @SleepyZ
 

SleepyZ

Active member
Here is the PivotPoints code that will plot the TOS PivotPoints as well as the alert.
#
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#
# Source code isn't available.

input showOnlyToday = No;
input timeFrame = {default "DAY", "WEEK", "MONTH"};

plot R3 = pivotpoints().r3;
plot R2 = pivotpoints().r2;
plot R1 = pivotpoints().r1;
plot PP = pivotpoints().pp;
plot S1 = pivotpoints().s1;
plot S2 = pivotpoints().s2;
plot S3 = pivotpoints().s3;

alert(close crosses pp, "PP cross", alert.bar, sound.ding);

r3.setdefaultColor(color.red);
r2.setdefaultColor(color.red);
r1.setdefaultColor(color.red);
pp.setdefaultColor(color.magenta);
s1.setdefaultColor(color.green);
s2.setdefaultColor(color.green);
s3.setdefaultColor(color.green);
 

Similar threads

Top