Here is an adaption of the Tradingview code.
Rather than separate codes for each timeframe, this uses input agg and you select the aggregation period.
A label will show the choice of Filtered Pivots or Classic Pivots as well as the agg period selected.
The Filtered Pivots are colored green/red as bull/bear or white for Classic Pivots.
The R1-3 colors above the pivot are shades of Red and the S1-3 are shades of green.
Bubbles will display the last agg periods lines type.
Rather than separate codes for each timeframe, this uses input agg and you select the aggregation period.
A label will show the choice of Filtered Pivots or Classic Pivots as well as the agg period selected.
The Filtered Pivots are colored green/red as bull/bear or white for Classic Pivots.
The R1-3 colors above the pivot are shades of Red and the S1-3 are shades of green.
Bubbles will display the last agg periods lines type.
Ruby:
#//Created by ChrisMoody 11-23-14 with Special Thanks to TheLark...AKA...The Coding Genius
#study(title="CM_Pivot Points_M-W-D_4H_1H_Filtered", shorttitle="CM_Pivots_Filtered", overlay=true)
#Modified by Sleepyz
input agg = AggregationPeriod.HOUR;
input use_filtered = yes;#input(true,title="Show Filtered Pivots")
input show_avg = yes;#input(true,title="Show Pivot Average")
#sh = input(false, title="Show 1 Hour Pivots?")
#sf = input(false, title="Show 4 Hour Pivots?")
#sd = input(false, title="Show Daily Pivots?")
#sw = input(false, title="Show Weekly Pivots?")
#sm = input(true, title="Show Monthly Pivots?")
#sy = input(false, title="Show Yearly Pivots?")
input show_r3_s3 = no;#input(false, title="Show R3 & S3 Only On 1 Hour & 4 Hour?")
def na = Double.NaN;
def l = low(period = agg);
def h = high(period = agg);
def c = close(period = agg);
#// Classic Pivot
def pivot = (h + l + c ) / 3.0;
#// Filter Cr
def bull = pivot > (pivot + pivot[1]) / 2 + .0025;
def bear = pivot < (pivot + pivot[1]) / 2 - .0025;
AddLabel(1, if use_filtered then "Filtered Pivots" else "Classic Pivots", if use_filtered and bull then Color.GREEN else if use_filtered and bear then Color.RED else Color.WHITE);
AddLabel(1, if agg < AggregationPeriod.HOUR
then (agg / 60000) + " MINUTES"
else if agg < AggregationPeriod.DAY
then (agg / 60000 / 60) + " HOURS"
else if agg < AggregationPeriod.WEEK
then (agg / 60000 /1440 ) + " DAYS"
else if agg == AggregationPeriod.WEEK
then "WEEK"
else if agg == AggregationPeriod.MONTH
then "MONTH"
else if agg == AggregationPeriod.QUARTER
then "QUARTER"
else "YEAR", Color.WHITE);
#// Classic Pivots
def r1 = if use_filtered and bear
then pivot + (pivot - l)
else if use_filtered and bull
then pivot + (h - l)
else pivot + (pivot - l);
def s1 = if use_filtered and bull
then pivot - (h - pivot)
else if use_filtered and bear
then pivot - (h - l)
else pivot - (h - pivot);
def r2 = if use_filtered
then na
else pivot + (h - l);
def s2 = if use_filtered
then na
else pivot - (h - l);
def r3 = if show_r3_s3 and r1 + (h - l)
then r1 + (h - l)
else na;
def s3 = if show_r3_s3 and s1 - (h - l)
then s1 - (h - l)
else na;
#//Pivot Average Calculation
def smaP = SimpleMovingAvg(pivot, 3);
#//1 Hour Pivots
#def htime_pivot = security(tickerid, '60', pivot[1])
#def htime_pivotAvg = security(tickerid, '60', smaP[1])
#def htime_R1 = security(tickerid, '60', r1[1])
#def htime_S1 = security(tickerid, '60', s1[1])
#def htime_R2 = security(tickerid, '60', r2[1])
#def htime_S2 = security(tickerid, '60', s2[1])
#def htime_R3 = security(tickerid, '60', r3[1])
#def htime_S3 = security(tickerid, '60', s3[1])
plot agg_pivot_avg = if show_avg
then smaP
else na;# title="Hourly Pivot Average",style=cross, color=orange,linewidth=2)
plot agg_pivot = pivot;#(sh and htime_pivot ? htime_pivot : na, title="Hourly Pivot",style=circles, color=fuchsia,linewidth=2)
plot agg_r1 = r1;#(sh and htime_R1 ? htime_R1 : na, title="Hourly R1",style=circles, color=#DC143C,linewidth=2)
plot agg_s1 = s1;#(sh and htime_S1 ? htime_S1 : na, title="Hourly S1",style=circles, color=lime,linewidth=2)
plot agg_r2 = r2;#(sh and htime_R2 ? htime_R2 : na, title="Hourly R2",style=circles, color=maroon,linewidth=2)
plot agg_s2 = s2;#(sh and htime_S2 ? htime_S2 : na, title="Hourly S2",style=circles, color=#228B22,linewidth=2)
plot agg_r3 = r3;#(sh and htime_R3 ? htime_R3 : na, title="Hourly R3",style=circles, color=#FA8072,linewidth=2)
plot agg_s3 = s3;#(sh and htime_S3 ? htime_S3 : na, title="Hourly S3",style=circles, color=#CD5C5C,linewidth=2)
agg_pivot_avg.SetDefaultColor(Color.ORANGE);
agg_pivot_avg.SetPaintingStrategy(PaintingStrategy.POINTS);
agg_pivot_avg.SetLineWeight(2);
agg_pivot.AssignValueColor(if use_filtered and bull then Color.GREEN else if use_filtered and bear then Color.RED else Color.WHITE);
agg_pivot.SetPaintingStrategy(PaintingStrategy.SQUARES);
agg_pivot.SetLineWeight(2);
#R1-3 Reds
agg_r1.SetDefaultColor(Color.RED);
agg_r1.SetPaintingStrategy(PaintingStrategy.DASHES);
agg_r1.SetLineWeight(2);
agg_r2.SetDefaultColor(Color.LIGHT_RED);
agg_r2.SetPaintingStrategy(PaintingStrategy.DASHES);
agg_r2.SetLineWeight(2);
agg_r3.SetDefaultColor(Color.DARK_RED);
agg_r3.SetPaintingStrategy(PaintingStrategy.DASHES);
agg_r3.SetLineWeight(2);
#S1-3 - Limes and Greens
agg_s1.SetDefaultColor(Color.LIME);
agg_s1.SetPaintingStrategy(PaintingStrategy.DASHES);
agg_s1.SetLineWeight(2);
agg_s2.SetDefaultColor(Color.GREEN);
agg_s2.SetPaintingStrategy(PaintingStrategy.DASHES);
agg_s2.SetLineWeight(2);
agg_s3.SetDefaultColor(Color.DARK_GREEN);
agg_s3.SetPaintingStrategy(PaintingStrategy.DASHES);
agg_s3.SetLineWeight(2);
input show_bubbles = yes;
input bubblemover = 3;
def b = bubblemover;
def b1 = b + 1;
def bubbles = show_bubbles and IsNaN(close[b]) and !IsNaN(close[b1]);
AddChartBubble(bubbles and agg_pivot_avg[b], agg_pivot_avg[b], "PAvg", agg_pivot_avg.TakeValueColor());
AddChartBubble(bubbles and agg_pivot[b], agg_pivot[b], "Pivot", agg_pivot.TakeValueColor());
AddChartBubble(bubbles and agg_r1[b], agg_r1[b], "R1", agg_r1.TakeValueColor());
AddChartBubble(bubbles and agg_r2[b], agg_r2[b], "R2", agg_r2.TakeValueColor());
AddChartBubble(bubbles and agg_r3[b], agg_r3[b], "R3", agg_r3.TakeValueColor());
AddChartBubble(bubbles and agg_s1[b], agg_s1[b], "S1", agg_s1.TakeValueColor());
AddChartBubble(bubbles and agg_s2[b], agg_s2[b], "S2", agg_s2.TakeValueColor());
AddChartBubble(bubbles and agg_s3[b], agg_s3[b], "S3", agg_s3.TakeValueColor());
Last edited by a moderator: