Trad Pivot Points Alerts For ThinkOrSwim

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

find below

CSS:
#//@version=4
#study(title="Trad Pivot Points Alerts", shorttitle="Trad Pivot Points Alerts", overlay = true)
#// Function outputs 1 when it's the first bar of the D/W/M/Y
# Converted by Sam4Cok@samer800     = 09 / 2023
#is_newbar(res) =>
script is_newbar {
    input res = "Daily";
    def isLast = !isNaN(close);
    def day = GetDay();
    def week = GetWeek();
    def month = GetMonth();
    def year = GetYear();
    def ch = if res == "Daily"   then day!=day[1] else
             if res == "Weekly"  then week!=week[1] else
             if res == "Monthly" then month!=month[1] else
             if res == "Yearly"  then year!=year[1] else ch[1];
    def con = if ch then yes else con[1];
    plot out = if con and islast then ch else Double.NaN;
}

script nround {
    input x = 0;
    def n = if x < 10 then 3 else if x < 100 then 2 else if x < 1000 then 1 else 0;
    def round1 = Round(x * Power(10, n), 0);
    def nround = round1 / Power(10, n);
    plot out = nround;
}

input pp_period = {default "Daily", "Weekly", "Monthly", "Yearly"};
input show_levels = yes;
input show_label = yes;

def na = Double.NaN;
def last = !isNaN(close);
DefineGlobalColor("line", Color.WHITE);
DefineGlobalColor("s", Color.CYAN);
DefineGlobalColor("r", Color.MAGENTA);
#// Calc High
AddLabel(show_label, pp_period + " Pivot Points", Color.WHITE);
def TimeSelect = is_newbar(pp_period);
def pp_res = TimeSelect;
def high_cur = if pp_res then high else Max(high_cur[1], high);
def phigh = if pp_res then high_cur[1] else phigh[1];

#// Calc Low
def low_cur = if pp_res then low else Min(low_cur[1], low);
def plow = if pp_res then low_cur[1] else plow[1];

#// Calc Close
def pclose = if pp_res then close[1] else pclose[1];

#// CALCULATE traditional pivots //

def vPP = (phigh + plow + pclose) / 3;
def vR1 = vPP    + (vPP   - plow);
def vS1 = vPP    - (phigh - vPP);
def vR2 = vPP    + (phigh - plow);
def vS2 = vPP    - (phigh - plow);
def vR3 = phigh  + 2 * (vPP   - plow);
def vS3 = plow   - 2 * (phigh - vPP);
 
#// PLOTTING //
#// PLOT PIVOTS LEVELS //

plot vpp_p = vPP;
plot vs1_p = vS1;
plot vs2_p = vS2;
plot vs3_p = vS3;
plot vr1_p = vR1;
plot vr2_p = vR2;
plot vr3_p = vR3;

vpp_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vs1_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vs2_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vs3_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vr1_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vr2_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vr3_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

vpp_p.SetDefaultColor(GlobalColor("line"));
vs1_p.SetDefaultColor(GlobalColor("s"));
vs2_p.SetDefaultColor(GlobalColor("s"));
vs3_p.SetDefaultColor(GlobalColor("s"));
vr1_p.SetDefaultColor(GlobalColor("r"));
vr2_p.SetDefaultColor(GlobalColor("r"));
vr3_p.SetDefaultColor(GlobalColor("r"));

#-- Levels
def labCond = pp_res!=pp_res[1] and show_levels;
def vpp_r = nround(vPP);
def vs1_r = nround(vS1);
def vs2_r = nround(vS2);
def vs3_r = nround(vS3);
def vr1_r = nround(vR1);
def vr2_r = nround(vR2);
def vr3_r = nround(vR3);

AddChartBubble(labCond and !labCond[1], vPP, "P " + vpp_r, GlobalColor("line"), yes);
AddChartBubble(labCond and !labCond[1], vS1, "S " + vS1_r, GlobalColor("s"), no);
AddChartBubble(labCond and !labCond[1], vS2, "S " + vS2_r, GlobalColor("s"), no);
AddChartBubble(labCond and !labCond[1], vS3, "S " + vS3_r, GlobalColor("s"), no);
AddChartBubble(labCond and !labCond[1], vR1, "R " + vR1_r, GlobalColor("r"), yes);
AddChartBubble(labCond and !labCond[1], vR2, "R " + vR2_r, GlobalColor("r"), yes);
AddChartBubble(labCond and !labCond[1], vR3, "R " + vR3_r, GlobalColor("r"), yes);

#-- END of CODE
 
  • Love
Reactions: IPA
find below

CSS:
#//@version=4
#study(title="Trad Pivot Points Alerts", shorttitle="Trad Pivot Points Alerts", overlay = true)
#// Function outputs 1 when it's the first bar of the D/W/M/Y
# Converted by Sam4Cok@samer800     = 09 / 2023
#is_newbar(res) =>
script is_newbar {
    input res = "Daily";
    def isLast = !isNaN(close);
    def day = GetDay();
    def week = GetWeek();
    def month = GetMonth();
    def year = GetYear();
    def ch = if res == "Daily"   then day!=day[1] else
             if res == "Weekly"  then week!=week[1] else
             if res == "Monthly" then month!=month[1] else
             if res == "Yearly"  then year!=year[1] else ch[1];
    def con = if ch then yes else con[1];
    plot out = if con and islast then ch else Double.NaN;
}

script nround {
    input x = 0;
    def n = if x < 10 then 3 else if x < 100 then 2 else if x < 1000 then 1 else 0;
    def round1 = Round(x * Power(10, n), 0);
    def nround = round1 / Power(10, n);
    plot out = nround;
}

input pp_period = {default "Daily", "Weekly", "Monthly", "Yearly"};
input show_levels = yes;
input show_label = yes;

def na = Double.NaN;
def last = !isNaN(close);
DefineGlobalColor("line", Color.WHITE);
DefineGlobalColor("s", Color.CYAN);
DefineGlobalColor("r", Color.MAGENTA);
#// Calc High
AddLabel(show_label, pp_period + " Pivot Points", Color.WHITE);
def TimeSelect = is_newbar(pp_period);
def pp_res = TimeSelect;
def high_cur = if pp_res then high else Max(high_cur[1], high);
def phigh = if pp_res then high_cur[1] else phigh[1];

#// Calc Low
def low_cur = if pp_res then low else Min(low_cur[1], low);
def plow = if pp_res then low_cur[1] else plow[1];

#// Calc Close
def pclose = if pp_res then close[1] else pclose[1];

#// CALCULATE traditional pivots //

def vPP = (phigh + plow + pclose) / 3;
def vR1 = vPP    + (vPP   - plow);
def vS1 = vPP    - (phigh - vPP);
def vR2 = vPP    + (phigh - plow);
def vS2 = vPP    - (phigh - plow);
def vR3 = phigh  + 2 * (vPP   - plow);
def vS3 = plow   - 2 * (phigh - vPP);
 
#// PLOTTING //
#// PLOT PIVOTS LEVELS //

plot vpp_p = vPP;
plot vs1_p = vS1;
plot vs2_p = vS2;
plot vs3_p = vS3;
plot vr1_p = vR1;
plot vr2_p = vR2;
plot vr3_p = vR3;

vpp_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vs1_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vs2_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vs3_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vr1_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vr2_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
vr3_p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

vpp_p.SetDefaultColor(GlobalColor("line"));
vs1_p.SetDefaultColor(GlobalColor("s"));
vs2_p.SetDefaultColor(GlobalColor("s"));
vs3_p.SetDefaultColor(GlobalColor("s"));
vr1_p.SetDefaultColor(GlobalColor("r"));
vr2_p.SetDefaultColor(GlobalColor("r"));
vr3_p.SetDefaultColor(GlobalColor("r"));

#-- Levels
def labCond = pp_res!=pp_res[1] and show_levels;
def vpp_r = nround(vPP);
def vs1_r = nround(vS1);
def vs2_r = nround(vS2);
def vs3_r = nround(vS3);
def vr1_r = nround(vR1);
def vr2_r = nround(vR2);
def vr3_r = nround(vR3);

AddChartBubble(labCond and !labCond[1], vPP, "P " + vpp_r, GlobalColor("line"), yes);
AddChartBubble(labCond and !labCond[1], vS1, "S " + vS1_r, GlobalColor("s"), no);
AddChartBubble(labCond and !labCond[1], vS2, "S " + vS2_r, GlobalColor("s"), no);
AddChartBubble(labCond and !labCond[1], vS3, "S " + vS3_r, GlobalColor("s"), no);
AddChartBubble(labCond and !labCond[1], vR1, "R " + vR1_r, GlobalColor("r"), yes);
AddChartBubble(labCond and !labCond[1], vR2, "R " + vR2_r, GlobalColor("r"), yes);
AddChartBubble(labCond and !labCond[1], vR3, "R " + vR3_r, GlobalColor("r"), yes);

#-- END of CODE

Thank you so much.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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