# Complete Pivot Setup
# Created by @tony_futures
# Inspired from @PostyTrades and @SergeTrades
#declare hide_on_daily;
DefineGlobalColor("MyBlue", CreateColor(0, 54, 191)); #GlobalColor("MyBlue")
DefineGlobalColor("MyYellow", CreateColor(255, 246, 67)); #GlobalColor("MyYellow")
DefineGlobalColor("MyGreen", CreateColor(0, 102, 51)); #GlobalColor("MyGreen")
DefineGlobalColor("MyLightGreen", CreateColor(0, 248, 171)); #GlobalColor("MyLightGreen")
DefineGlobalColor("MyBTDGreen", CreateColor(153, 255, 153)); #GlobalColor("MyBTDGreen")
DefineGlobalColor("MyLBlue", CreateColor(51, 204, 255)); #GlobalColor("MyLBlue")
DefineGlobalColor("MyLBlue2", CreateColor(51, 255, 255)); #GlobalColor("MyLBlue2")
DefineGlobalColor("MyDeepBlue", CreateColor(0, 0, 102)); #GlobalColor("MyDeepBlue")
DefineGlobalColor("MyRed", CreateColor(153, 0, 0)); #GlobalColor("MyRed")
DefineGlobalColor("MyOrange", CreateColor(255, 102, 0)); #GlobalColor("MyOrange")
DefineGlobalColor("MyRed2", createcolor(102,0,102)); #GlobalColor("MyRed2")
DefineGlobalColor("MyRed3", createcolor(204,0,102)); #GlobalColor("MyRed3")
DefineGlobalColor("MyPurple", createcolor(153,0,204)); #GlobalColor("MyPurple")
DefineGlobalColor("MyR2Pink", createcolor(255,88,145)); #GlobalColor("MyR2Pink")
DefineGlobalColor("MyS2Green", createcolor(0,102,102)); #GlobalColor("MyS2Green")
DefineGlobalColor("MyPreviousHL", createcolor(51,153,255)); #GlobalColor("MyPreviousHL")
input aggregationPeriod = {default DAY, WEEK, MONTH, YEAR};
input showCPR = no;
input showPrevious = no;
input showReversalZone = yes;
input showLastStand = yes;
input showLabels = yes;
input showBullTargets = yes;
input showBearTargets = yes;
input showTodayOnly = yes;
input manualClose = 0.00;
input RoundLevel = 0;
input SwingLength = 12; #default is 12
input showBubblesLeft = yes;
input showBubblesRight = No;
input showPreviousBubblesRight = YES;
input displaceRightBubble = 3;
def showBubbleNow = !IsNaN(close) and IsNaN(close[-1]);
def showPreviousBubblesNow = !IsNaN(close) and IsNaN(close[-1]);
def Today = if aggregationPeriod == AggregationPeriod.DAY and GetLastDay() == GetDay() then 1 else if aggregationPeriod == AggregationPeriod.MONTH and GetLastMonth() == GetMonth() then 1 else if aggregationPeriod == AggregationPeriod.WEEK and GetLastWeek() == GetWeek() then 1 else if aggregationPeriod == AggregationPeriod.YEAR and GetLastYEAR() == GetYear() then 1 else 0;
def prevHigh = high(period = aggregationPeriod)[1];
def prevLow = low(period = aggregationPeriod)[1];
def prevClose1 = close(period = aggregationPeriod)[1];
def prevClose = if manualClose != 0 then manualClose else prevClose1;
#Addlabel(aggregationPeriod == AggregationPeriod.DAY," Daily Close: " + prevClose, Color.WHITE);
#####################
#taken from Cam Points DailyAgg
#LL
#S1/R1
#S2/R2
####################
#input CPP_aggregationPeriod = AggregationPeriod.DAY;
#def CPP_PH = high(period = CPP_aggregationPeriod)[1];
#def CPP_PL = low(period = CPP_aggregationPeriod)[1];
#def CPP_PC = close(period = CPP_aggregationPeriod)[1];
input showCPP = yes;
def CPP_R2 = prevClose1 + (prevHigh – prevLow) * 1.1 / 6;
def CPP_S2 = prevClose1 - (prevHigh – prevLow)* 1.1 / 6;
plot CPP_R2Line = if showCPP and showTodayOnly and Today then CPP_R2 else if showCPP and !showTodayOnly then CPP_R2 else Double.NaN;
plot CPP_S2Line = if showCPP and showTodayOnly and Today then CPP_S2 else if showCPP and !showTodayOnly then CPP_S2 else Double.NaN;
CPP_R2Line.SetDefaultColor(GlobalColor("MyR2Pink"));
CPP_S2Line.SetDefaultColor(GlobalColor("MyS2Green"));
#CPP_R2Line.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
CPP_R2Line.SetStyle(Curve.LONG_DASH);
CPP_S2Line.SetStyle(Curve.LONG_DASH);
CPP_R2Line.setlineWeight(2);
CPP_S2Line.setlineWeight(2);
CPP_R2Line.hidebubble();
CPP_S2Line.hidebubble();
#######################
# End TAKEN from Cam points Daily
######################
def pivot = (prevHigh + prevLow + prevClose) / 3; #default 3.0
def bc = (prevHigh + prevLow) / 2; #default 2
def tc = (pivot - bc) + pivot;
def prevDiff = prevHigh - prevLow;
def prevDiff2 = prevDiff*1.1/2; #original is 1.1/2
def prevDiff4 = prevDiff*1.1/4; #original is 1.1/4
def prevDiff8 = prevDiff*1.1/8; #original is 1.1/8
#def prevDiff16 = prevDiff*1.1/16;
def smallR1 = prevClose + (prevDiff*1.12/ SwingLength); #default is 12
def smallS1 = prevClose - (prevDiff*1.12/ SwingLength); #default is 12
def R1 = prevDiff4 + prevClose;
def R3 = RoundDown(prevDiff2 + prevClose, RoundLevel);
def R2 = R3 - prevDiff8;
def R4 = RoundDown(prevDiff + prevClose,RoundLevel);
def R5 = RoundDown((R3 + (1.168 * (R3 - R1))),RoundLevel);
def R6 = RoundDown((R4 + (.28 * (R4 - R2))),RoundLevel);
def S1 = PrevClose - prevDiff4;
#def S1 = PrevClose - (prevHigh – prevLow)* 1.1 / 12;
def S3 = RoundUp(PrevClose - prevDiff2, RoundLevel);
def S2 = S3 + prevDiff8;
def S4 = RoundUp(prevClose - prevDiff, RoundLevel);
def S5 = RoundUp((S3 - (1.168 * ( S1 - S3))), RoundLevel);
def S6 = RoundUp((S4 - (.28 * ( S2 - S4))), RoundLevel);
#######################
#Central Pivot Range - turn off by changing showCPR to no
#######################
input showPivotMiddle = yes;
plot PLine = if showCPR and showTodayOnly and Today and showPivotMiddle then pivot else if showCPR and !showTodayOnly then pivot else Double.NaN;
plot BCLine = if showCPR and showTodayOnly and Today then bc else if showCPR and !showTodayOnly then bc else Double.NaN;
plot TCLine = if showCPR and showTodayOnly and Today then tc else if showCPR and !showTodayOnly then tc else Double.NaN;
PLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PLine.SetDefaultColor(GlobalColor("MyPurple"));
BCLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BCLine.SetDefaultColor(Color.MAGENTA);
TCLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TCLine.SetDefaultColor(Color.MAGENTA);
PLine.setlineWeight(3);
BCLine.setlineWeight(3);
TCLine.setlineWeight(3);
PLine.hidebubble();
BCLine.hidebubble();
TCLine.hidebubble();
PLine.hidetitle();
BCLine.hidetitle();
TCLine.hidetitle();
Input showPriorDayPivotLines = no;
plot BCLinePriorDay = if showPriorDayPivotLines then bc else if showCPR and !showTodayOnly then bc else Double.NaN;
BCLinePriorDay.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BCLinePriorDay.SetDefaultColor(Color.MAGENTA);
BCLinePriorDay .setlineWeight(3);
plot PivotLinePriorDay = if showPriorDayPivotLines and showPivotMiddle then pivot else if showCPR and !showTodayOnly then pivot else Double.NaN;
PivotLinePriorDay.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PivotLinePriorDay.SetDefaultColor(GlobalColor("MyPurple"));
PivotLinePriorDay .setlineWeight(3);
plot TCLinePriorDay = if showPriorDayPivotLines then tc else if showCPR and !showTodayOnly then tc else Double.NaN;;
TCLinePriorDay.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TCLinePriorDay.SetDefaultColor(Color.MAGENTA);
TCLinePriorDay .setlineWeight(3);
# Previous Day High/Low - turn off by changing showPrevious to no
plot PreviousHigh = if showPrevious and showTodayOnly and Today then RoundDown(prevHigh,RoundLevel) else if showPrevious and !showTodayOnly then RoundDown(prevHigh,RoundLevel) else Double.NaN;
PreviousHigh.SetDefaultColor(GlobalColor("MyPreviousHL"));
PreviousHigh.SetLineWeight(4);
plot PreviousLow = if showPrevious and showTodayOnly and Today then RoundUp(prevLow,RoundLevel) else if showPrevious and !showTodayOnly then RoundUp(prevLow,RoundLevel) else Double.NaN;
PreviousLow.setDefaultColor(GlobalColor("MyPreviousHL"));
PreviousLow.SetLineWeight(4);
#######################
# Reversal zones - turn off by changing showReversalZone to no
# R1 and R2 BLUE CLOUD
# R1 and R2 lines
# R1 and R2 Bubbles
#######################
input ShowReversalCloud = no;
AddCloud(if showReversalZone and showTodayOnly and Today and ShowReversalCloud then r1 else if showReversalZone and !showTodayOnly then r1 else Double.NaN, r2, GlobalColor("MyRed"), GlobalColor("MyRed"));
plot R1Line = if showReversalZone and showTodayOnly and Today then R1 else if showReversalZone and !showTodayOnly then r1 else Double.NaN;
R1Line.setDefaultColor(GlobalColor("MyRed"));
R1Line.SetStyle(Curve.LONG_DASH);
R1Line.setlineWeight(2);
plot R2Line = if showReversalZone and showTodayOnly and Today then R2 else if showReversalZone and !showTodayOnly then r2 else Double.NaN;
R2Line.setDefaultColor(GlobalColor("MyRed"));
R2Line.SetStyle(Curve.LONG_DASH);
R2Line.setlineWeight(2);
AddCloud(if showReversalZone and showTodayOnly and Today and ShowReversalCloud then s1 else if showReversalZone and !showTodayOnly then s1 else Double.NaN, s2, GlobalColor("MyBlue"), GlobalColor("MyBlue"));
AddChartBubble(showBubblesRight and showLastStand and showBubbleNow[displaceRightBubble], R1, "R1: " + R1, Color.white, yes);
AddChartBubble(showBubblesRight and showLastStand and showBubbleNow[displaceRightBubble], R2, "R2: " + R2, Color.white, yes);
plot S1Line = if showReversalZone and showTodayOnly and Today then S1 else if showReversalZone and !showTodayOnly then S1 else Double.NaN;
S1Line.setDefaultColor(GlobalColor("MyBlue"));
s1Line.SetStyle(Curve.LONG_DASH);
S1Line.setlineWeight(2);
plot S2Line = if showReversalZone and showTodayOnly and Today then S2 else if showReversalZone and !showTodayOnly then S2 else Double.NaN;
S2Line.setDefaultColor(GlobalColor("MyBlue"));
S2Line.SetStyle(Curve.LONG_DASH);
S2Line.setlineWeight(2);
AddChartBubble(showBubblesRight and showLastStand and showBubbleNow[displaceRightBubble], S1, "S1: " + S1, Color.white, yes);
AddChartBubble(showBubblesRight and showLastStand and showBubbleNow[displaceRightBubble], S2, "S2: " + S2, Color.white, yes);
#AddLabel(showReversalZone and showLabels, "Bear zone: " + RoundDown(R1, RoundLevel) + " to " + RoundDown(R2, RoundLevel), GlobalColor("MyRed2"));
#AddLabel(showReversalZone and showLabels, "Bull zone: " + RoundDown(S1, RoundLevel) + " to " + RoundDown(S2, RoundLevel), GlobalColor("MyRed2"));
#######################
# Last stand lines - turn off by changing ShowLastStand to no
#######################
plot bullLastStand = if showLastStand and showTodayOnly and Today then S3 else if showLastStand and !showTodayOnly then S3 else Double.NaN;
bullLastStand.setDefaultColor(GlobalColor("MyGreen"));
bullLastStand.setlineWeight(3);
plot bearLastStand = if showLastStand and showTodayOnly and Today then R3 else if showLastStand and !showTodayOnly then R3 else Double.NaN;
bearLastStand.setDefaultColor(GlobalColor("MyRed"));
bearLastStand.setlineWeight(3);
AddChartBubble(showBubblesLeft and showLastStand and Today and !Today[1], R3, "Bear Last Stand: " + R3, Color.white, yes);
AddChartBubble(showBubblesLeft and showLastStand and Today and !Today[1], S3, "Bull Last Stand: " + S3, Color.white, no);
AddChartBubble(showBubblesLeft and showPrevious and Today and !Today[1], PrevHigh, "Previous High: " + PrevHigh, Color.white, yes);
AddChartBubble(showBubblesLeft and showPrevious and Today and !Today[1], PrevLow, "Previous Low: " + PrevLow, Color.white, no);
### Bull / Bear TARGET ONE ####
plot bull1 = if showBullTargets and showTodayOnly and Today then R5 else if showBullTargets and !showTodayOnly then R5 else Double.NaN;
bull1.setDefaultColor(GlobalColor("MyRed3"));
plot bear1 = if showBearTargets and showTodayOnly and Today then S5 else if showBearTargets and !showTodayOnly then S5 else Double.NaN;
bear1.setDefaultColor(GlobalColor("MyBTDGreen"));
AddChartBubble(showBubblesLeft and showBullTargets and Today and !Today[1], R5, "Bull Target 1: " + R5, GlobalColor("MyRed3"), yes);
AddChartBubble(showBubblesLeft and showBearTargets and Today and !Today[1], S5, "Bear Target 1: " + S5, GlobalColor("MyBTDGreen"), no);
bull1.setlineWeight(4);
bear1.setlineWeight(4);
### Bull / Bear TARGET TWO ####
plot bull2 = if showBullTargets and showTodayOnly and Today then R4 else if showBullTargets and !showTodayOnly then R4 else Double.NaN;
bull2.setDefaultColor(GlobalColor("MyRed3"));
plot bear2 = if showBearTargets and showTodayOnly and Today then S4 else if showBearTargets and !showTodayOnly then S4 else Double.NaN;
bear2.setDefaultColor(GlobalColor("MyBTDGreen"));
AddChartBubble(showBubblesLeft and showBullTargets and Today and !Today[1], R4, "Bull Target 2: " + R4, GlobalColor("MyRed3"), yes);
AddChartBubble(showBubblesLeft and showBearTargets and Today and !Today[1], S4, "Bear Target 2: " + S4, GlobalColor("MyBTDGreen"), no);
bull2.setlineWeight(4);
bear2.setlineWeight(4);
### Bull / Bear TARGET THREE ####
plot bull3 = if showBullTargets and showTodayOnly and Today then R6 else if showBullTargets and !showTodayOnly then R6 else Double.NaN;
bull3.setDefaultColor(GlobalColor("MyRed3"));
plot bear3 = if showBullTargets and showTodayOnly and Today then S6 else if showBullTargets and !showTodayOnly then S6 else Double.NaN;
bear3.setDefaultColor(GlobalColor("MyBTDGreen"));
AddChartBubble(showBubblesLeft and showBullTargets and Today and !Today[1], R6, "Bull Target 3: " + R6, GlobalColor("MyRed3"), yes);
AddChartBubble(showBubblesLeft and showBearTargets and Today and !Today[1], S6, "BEAR Target 3: " + S6, GlobalColor("MyBTDGreen"), no);
bull3.setlineWeight(4);
bear3.setlineWeight(4);
input showOpen = yes;
AddVerticalLine( Today and !Today[1] and showOpen, concat("Today BEGIN", ""), Color.blue, curve.short_dash);
AddChartBubble(showBubblesRight and showLastStand and showBubbleNow[displaceRightBubble], R3, "Bear Last Stand: " + R3, Color.white, yes);
AddChartBubble(showBubblesRight and showLastStand and showBubbleNow[displaceRightBubble], S3, "Bull Last Stand: " + S3, Color.white, no);
input showPreviousBubbles = yes;
AddChartBubble(showPreviousBubblesRight and showPrevious and showPreviousBubbles and showPreviousBubblesNow[displaceRightBubble], PreviousHigh, "Previous High: " + RoundDown(previousHigh,RoundLevel), GlobalColor("MyPreviousHL"), yes);
AddChartBubble(showPreviousBubblesRight and showPrevious and showPreviousBubbles and showPreviousBubblesNow[displaceRightBubble], PreviousLow, "Previous Low: " + PreviousLow, GlobalColor("MyPreviousHL"), no);
AddChartBubble(showBubblesRight and showBullTargets and showBubbleNow[displaceRightBubble], R5, "Bull Target 1: " + R5, Color.white, yes);
AddChartBubble(showBubblesRight and showBearTargets and showBubbleNow[displaceRightBubble], S5, "Bear Target 1: " + S5, Color.white, no);
AddChartBubble(showBubblesRight and showBullTargets and showBubbleNow[displaceRightBubble], R4, "Bull Target 2: " + R4, Color.white, yes);
AddChartBubble(showBubblesRight and showBearTargets and showBubbleNow[displaceRightBubble], S4, "Bear Target 2: " + S4, Color.white, no);
AddChartBubble(showBubblesRight and showBullTargets and showBubbleNow[displaceRightBubble], R6, "Bull Target 3: " + R6, Color.white, yes);
AddChartBubble(showBubblesRight and showBearTargets and showBubbleNow[displaceRightBubble], S6, "Bear Target 3: " + S6, Color.white, no);
input showWeeklyLabels = yes;
AddChartBubble(showWeeklyLabels and AggregationPeriod == AggregationPeriod.WEEK and Today and !Today[1], (R2 - R1)/2 + R1, "Weekly", Color.WHITE, yes);
AddChartBubble(showWeeklyLabels and AggregationPeriod == AggregationPeriod.WEEK and Today and !Today[1], (S1 - S2)/2 + S2, "Weekly", Color.WHITE, no);
input showSmallCamPoints = yes;
input showSmallCamPointsBubbles = no;
plot smallCamResistance = if showSmallCamPoints and Today then smallR1 else Double.NaN;
smallCamResistance.setDefaultColor(GlobalColor("MyYellow"));
AddChartBubble(showSmallCamPointsBubbles and Today and !Today[1], smallR1, "small Cam R ZONE: " + smallR1, Color.white, no);
smallCamResistance.setlineWeight(3);
plot smallCamSupport = if showSmallCamPoints and Today then smallS1 else Double.NAN;
smallCamSupport.setDefaultColor(GlobalColor("MyBTDGreen"));
AddChartBubble(showSmallCamPointsBubbles and Today and !Today[1], smallS1, "small Cam S ZONE: " + smallS1, Color.white, no);
smallCamSupport.setlineWeight(3);
input showSCPCloud = no;
addcloud(if showSmallCamPoints and showSCPCloud and TOday then smallCamResistance else double.nan, smallCamSupport,GlobalColor("MyOrange"),GlobalColor("MyOrange"), no);