Previous Days Pivot Point Projection

woulf1004

Active member
VIP
Hi Team,

Is there anyway possible to extend and project all previous days plots towards the right side of the chart when is not in showonexpansion mode?


input showonlyLastPeriod = no;
input showexpansiononly = yes;
input show_bubble = yes;
input show_price = no;
input showbubbles_rightedge = yes;

def aggregationPeriod = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.DAY
else if GetAggregationPeriod() >= AggregationPeriod.FIFTEEN_MIN and GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.WEEK
else if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.MONTH
else if GetAggregationPeriod() == AggregationPeriod.WEEK and GetAggregationPeriod() == AggregationPeriod.MONTH then AggregationPeriod.YEAR
else AggregationPeriod.MONTH;

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 showexpansiononly and !IsNaN(close) or 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);
#plot R4 = PP * 3 + (HIGHprev - 3 * LOWprev);
#plot S4 = PP * 3 - (3 * HIGHprev - LOWprev);
#plot R5 = PP * 4 + (HIGHprev - 4 * LOWprev);
#plot S5 = PP * 4 - (4 * 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);
#R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#R5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#S5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


#AddChartBubble(show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R5 != R5[1], R5, "R5: " + if !show_price then "" else AsText(Round(R5 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R4 != R4[1], R4, "R4: " + if !show_price then "" else AsText(Round(R4 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R3 != R3[1], R3, "R3: " + if !show_price then "" else AsText(Round(R3 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R2 != R2[1], R2, "R2: " + if !show_price then "" else AsText(Round(R2 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble(show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R1 != R1[1], R1, "R1: " + if !show_price then "" else AsText(Round(R1 / TickSize(), 0) * TickSize()), Color.GRAY);

AddChartBubble( show_bubble and
if showonlyLastPeriod or showexpansiononly
then BarNumber() == HighestAll(BarNumber())
else if showbubbles_rightedge
then thisday!=thisday[-1]
else PP != PP[1]
,
PP,
"PP_"+thisday+": " + if !show_price then ""
else AsText(Round(PP / TickSize(), 0) * TickSize()), Color.ORANGE);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S5 != S5[1], S5, "S5: " + if !show_price then "" else AsText(Round(S5 / TickSize(), 0) * TickSize()), Color.GRAY, no);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S4 != S4[1], S4, "S4: " + if !show_price then "" else AsText(Round(S4 / TickSize(), 0) * TickSize()), Color.GRAY, no);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] 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 or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S2 != S2[1], S2, "S2: " + if !show_price then "" else AsText(Round(S2 / TickSize(), 0) * TickSize()), Color.GRAY, no);

#AddChartBubble(show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S1 != S1[1],S1, "S1: " + if !show_price then "" else AsText(Round(S1 / TickSize(), 0) * TickSize()), Color.GRAY, no);
#
 
Solution
Hi Team,

Is there anyway possible to extend and project all previous days plots towards the right side of the chart when is not in showonexpansion mode?


input showonlyLastPeriod = no;
input showexpansiononly = yes;
input show_bubble = yes;
input show_price = no;
input showbubbles_rightedge = yes;

def aggregationPeriod = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.DAY
else if GetAggregationPeriod() >= AggregationPeriod.FIFTEEN_MIN and GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.WEEK
else if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.MONTH
else if GetAggregationPeriod() == AggregationPeriod.WEEK and GetAggregationPeriod() ==...
Hi Team,

Is there anyway possible to extend and project all previous days plots towards the right side of the chart when is not in showonexpansion mode?


input showonlyLastPeriod = no;
input showexpansiononly = yes;
input show_bubble = yes;
input show_price = no;
input showbubbles_rightedge = yes;

def aggregationPeriod = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.DAY
else if GetAggregationPeriod() >= AggregationPeriod.FIFTEEN_MIN and GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.WEEK
else if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.MONTH
else if GetAggregationPeriod() == AggregationPeriod.WEEK and GetAggregationPeriod() == AggregationPeriod.MONTH then AggregationPeriod.YEAR
else AggregationPeriod.MONTH;

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 showexpansiononly and !IsNaN(close) or 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);
#plot R4 = PP * 3 + (HIGHprev - 3 * LOWprev);
#plot S4 = PP * 3 - (3 * HIGHprev - LOWprev);
#plot R5 = PP * 4 + (HIGHprev - 4 * LOWprev);
#plot S5 = PP * 4 - (4 * 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);
#R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#R5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#S5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


#AddChartBubble(show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R5 != R5[1], R5, "R5: " + if !show_price then "" else AsText(Round(R5 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R4 != R4[1], R4, "R4: " + if !show_price then "" else AsText(Round(R4 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R3 != R3[1], R3, "R3: " + if !show_price then "" else AsText(Round(R3 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R2 != R2[1], R2, "R2: " + if !show_price then "" else AsText(Round(R2 / TickSize(), 0) * TickSize()), Color.GRAY);

#AddChartBubble(show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else R1 != R1[1], R1, "R1: " + if !show_price then "" else AsText(Round(R1 / TickSize(), 0) * TickSize()), Color.GRAY);

AddChartBubble( show_bubble and
if showonlyLastPeriod or showexpansiononly
then BarNumber() == HighestAll(BarNumber())
else if showbubbles_rightedge
then thisday!=thisday[-1]
else PP != PP[1]
,
PP,
"PP_"+thisday+": " + if !show_price then ""
else AsText(Round(PP / TickSize(), 0) * TickSize()), Color.ORANGE);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S5 != S5[1], S5, "S5: " + if !show_price then "" else AsText(Round(S5 / TickSize(), 0) * TickSize()), Color.GRAY, no);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S4 != S4[1], S4, "S4: " + if !show_price then "" else AsText(Round(S4 / TickSize(), 0) * TickSize()), Color.GRAY, no);

#AddChartBubble( show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] 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 or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S2 != S2[1], S2, "S2: " + if !show_price then "" else AsText(Round(S2 / TickSize(), 0) * TickSize()), Color.GRAY, no);

#AddChartBubble(show_bubble and if showonlyLastPeriod or showexpansiononly then BarNumber() == HighestAll(BarNumber()) else if showbubbles_rightedge then thisday!=thisday[-1] else S1 != S1[1],S1, "S1: " + if !show_price then "" else AsText(Round(S1 / TickSize(), 0) * TickSize()), Color.GRAY, no);
#

Here is a modification to a script I did before that gives you 10 previous pivots. More can be created using the logic for the 10 provided.

snip.jpg

Ruby:
script x {

    def ymd      = GetYYYYMMDD();
    def candles  = !IsNaN(close);
    def capture  = candles and ymd != ymd[1];
    def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
    def thisDay  = (HighestAll(dayCount) - dayCount) ;


    input count  = 5;
    input extend = 5;

    def aggregationPeriod = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.DAY
else if GetAggregationPeriod() >= AggregationPeriod.FIFTEEN_MIN and GetAggregationPeriod() < AggregationPeriod.DAY then AggregationPeriod.WEEK
else if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.MONTH
else if GetAggregationPeriod() == AggregationPeriod.WEEK and GetAggregationPeriod() == AggregationPeriod.MONTH then AggregationPeriod.YEAR
else AggregationPeriod.MONTH;

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


    def PPext   = if thisDay == count then (HIGHprev + LOWprev + CLOSEprev) / 3 else PPext[1];
    input show_all_on_today = yes;
    plot PP     = if show_all_on_today == yes and thisDay == 0
                   and Between(thisDay, count - extend, count) and PPext
                   then PPext
                   else if show_all_on_today == no and thisDay >= 0
                   and Between(thisDay, count - extend, count) and PPext
                   then PPext
                   else Double.NaN ;
}
input show_all_on_today = no;
input count             = 10;
def extend = count;

plot p1 = x(count = 1, extend = extend, "show all on today" = show_all_on_today);
plot p2 = x(count = 2, extend = extend, "show all on today" = show_all_on_today);
plot p3 = x(count = 3, extend = extend, "show all on today" = show_all_on_today);
plot p4 = x(count = 4, extend = extend, "show all on today" = show_all_on_today);
plot p5 = x(count = 5, extend = extend, "show all on today" = show_all_on_today);
plot p6 = x(count = 6, extend = extend, "show all on today" = show_all_on_today);
plot p7 = x(count = 7, extend = extend, "show all on today" = show_all_on_today);
plot p8 = x(count = 8, extend = extend, "show all on today" = show_all_on_today);
plot p9 = x(count = 9, extend = extend, "show all on today" = show_all_on_today);
plot p10 = x(count = 10, extend = extend, "show all on today" = show_all_on_today);

DefineGlobalColor("P", Color.MAGENTA);
p1.SetDefaultColor(GlobalColor("P"));
p1.SetLineWeight(2);
p1.SetPaintingStrategy(PaintingStrategy.DASHES);
p2.SetDefaultColor(GlobalColor("P"));
p2.SetLineWeight(2);
p2.SetPaintingStrategy(PaintingStrategy.DASHES);
p3.SetDefaultColor(GlobalColor("P"));
p3.SetLineWeight(2);
p3.SetPaintingStrategy(PaintingStrategy.DASHES);
p4.SetDefaultColor(GlobalColor("P"));
p4.SetLineWeight(2);
p4.SetPaintingStrategy(PaintingStrategy.DASHES);
p5.SetDefaultColor(GlobalColor("P"));
p5.SetLineWeight(2);
p5.SetPaintingStrategy(PaintingStrategy.DASHES);
p6.SetDefaultColor(GlobalColor("P"));
p6.SetLineWeight(2);
p6.SetPaintingStrategy(PaintingStrategy.DASHES);
p7.SetDefaultColor(GlobalColor("P"));
p7.SetLineWeight(2);
p7.SetPaintingStrategy(PaintingStrategy.DASHES);
p8.SetDefaultColor(GlobalColor("P"));
p8.SetLineWeight(2);
p8.SetPaintingStrategy(PaintingStrategy.DASHES);
p9.SetDefaultColor(GlobalColor("P"));
p9.SetLineWeight(2);
p9.SetPaintingStrategy(PaintingStrategy.DASHES);
p10.SetDefaultColor(GlobalColor("P"));
p10.SetLineWeight(2);
p10.SetPaintingStrategy(PaintingStrategy.DASHES);

input showbubbles = yes;
input bubblemover = 5;
def b  = bubblemover;
def b1 = b + 1;
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p1[b], "P1", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p2[b], "P2", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p3[b], "P3", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p4[b], "P4", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p5[b], "P5", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p6[b], "P6", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p7[b], "P7", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p8[b], "P8", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p9[b], "P9", GlobalColor("P"));
AddChartBubble(showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]), p10[b], "P10", GlobalColor("P"));
 
Solution

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