# This is a ToS indicator
#//@joebaus
#//Created and maintained by Josh Baus.
#//With contributions from Wim Van Ertvelde.
#study("Wayne's Pivots", shorttitle="Wayne's Pivots", overlay=true)
#// Pivot point bias drop down selection for bulish, bearish, and Out Of Position highlights.
# Converted by Sam4Cok@Samer800 - 04/2023
input biasInput = {"Bullish", "Bearish", "Out of Position", "Range", default "All"}; # "Pivot Point Bias"
input AutoTimeFrame = yes;
input inputTimeFrame = AggregationPeriod.DAY;
def na = Double.NaN;
#----- Color
DefineGlobalColor("plotColorS" , Color.DARK_GREEN);
DefineGlobalColor("plotColorR" , Color.DARK_RED);
DefineGlobalColor("plotColorP" , Color.DARK_ORANGE);
DefineGlobalColor("plotColorSL" , Color.GREEN);
DefineGlobalColor("plotColorRL" , Color.RED);
DefineGlobalColor("plotColorPL" , Color.ORANGE);
#// Automaticly selects a daily, weekly, or monthly pivot point based on the timeframe being used.
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
def timeframe = GetAggregationPeriod();
def defaultTimeFrame = if timeframe < AggregationPeriod.FOUR_HOURS then AggregationPeriod.DAY else
if timeframe < AggregationPeriod.WEEK then AggregationPeriod.MONTH else
if timeframe < AggregationPeriod.QUARTER then AggregationPeriod.YEAR else AggregationPeriod.DAY;
#inputTimeFrame = input(title="Time Frame", type=input.resolution, defval="")
def pResolution = if AutoTimeFrame then defaultTimeFrame else inputTimeFrame;
#// Creating the "avg_resOffset" value to plot the future pivot points.
#f_avgDilationOf(pResolution)
script f_avgDilationOf {
input pResolution = AggregationPeriod.DAY;
def time = if pResolution < AggregationPeriod.FOUR_HOURS then GetDay() else
if pResolution < AggregationPeriod.WEEK then GetMonth() else
if pResolution < AggregationPeriod.QUARTER then GetYear() else GetDay();
def b = barssince(time-time[1]);
def cumTotal = TotalSum(if b == 0 then b[1] + 1 else 0);
def cumCount = TotalSum(if b == 0 then 1 else 0);
def f_avgDilationOf = cumTotal / cumCount;
plot out = f_avgDilationOf;
}
def avg_Offset = Ceil(f_avgDilationOf(pResolution));
def avg_resOffset = if avg_Offset>0 then floor(avg_Offset) else if avg_Offset<0 then Ceil(avg_Offset) else 0;
AddLabel(1, f_avgDilationOf(pResolution), Color.WHITE);
#// Get the high, low, open, and close of the "pResolution" function for pivot point math.
def prevCloseHTF = close(Period = pResolution);
def prevOpenHTF = open(Period = pResolution);
def prevHighHTF = high(Period = pResolution);
def prevLowHTF = low(Period = pResolution);
#// Math for pivot point levels
def pLevel = (prevHighHTF + prevLowHTF + prevCloseHTF) / 3;
def s1Level = pLevel * 2 - prevHighHTF;
def r1Level = pLevel * 2 - prevLowHTF;
def s2Level = pLevel - (r1Level - s1Level);
def r2Level = (pLevel - s1Level) + r1Level;
def s3Level = prevLowHTF - 2.0 * (prevHighHTF - pLevel);
def r3Level = prevHighHTF + 2.0 * (pLevel - prevLowHTF);
def m2Level = pLevel - (pLevel - s1Level) / 2;
def m3Level = pLevel + (r1Level - pLevel) / 2;
def m1Level = s1Level - (s1Level - s2Level) / 2;
def m4Level = r1Level + (r2Level - r1Level) / 2;
#/ Bool conditions for bias settings
def bullBias;# = false
def bearBias;# = false
def oopBias;# = false
def rangeBias;# = false
def allBias;# = false
#/ Bool tree for bias settings
if biasInput == biasInput."Bullish" {
rangeBias = no;
bullBias = yes;
bearBias = no;
oopBias = no;
allBias = no;
} else
if biasInput == biasInput."Bearish" {
rangeBias = no;
bullBias = no;
bearBias = yes;
oopBias = no;
allBias = no;
} else
if biasInput == biasInput."Out of Position" {
rangeBias = no;
bullBias = no;
bearBias = no;
oopBias = yes;
allBias = no;
} else
if biasInput == biasInput."Range" {
rangeBias = yes;
bullBias = no;
bearBias = no;
oopBias = no;
allBias = no;
} else
if biasInput == biasInput."All" {
rangeBias = no;
bullBias = no;
bearBias = no;
oopBias = no;
allBias = yes;
} else {
rangeBias = rangeBias[1];
bullBias = bullBias[1];
bearBias = bearBias[1];
oopBias = oopBias[1];
allBias = allBias[1];
}
#// The indicator's pivot point plots. Pivot level stylization, used for buy and sell zone fills, biased pivots settings, and a gap or breakline "()!=0?na:" between pivots is here.
plot r2Plot = if bullBias or oopBias or allBias then r2Level[1] else na; # "R2"
r2Plot.SetDefaultColor(GlobalColor("plotColorR"));
plot m4Plot = if bullBias or oopBias or allBias then m4Level[1] else na; # "M4"
m4Plot.SetDefaultColor(GlobalColor("plotColorR"));
plot r1Plot = if rangeBias or allBias then r1Level[1] else na; # "R1"
r1Plot.SetDefaultColor(GlobalColor("plotColorRL"));
plot m3Plot = if bearBias or allBias then m3Level[1] else na; # "M3"
m3Plot.SetDefaultColor(GlobalColor("plotColorR"));
plot pPlot = if bullBias or bearBias or oopBias or rangeBias or allBias then pLevel[1] else na; # "PP"
pPlot.SetDefaultColor(GlobalColor("plotColorP"));
plot m2Plot = if bullBias or allBias then m2Level[1] else na; # "M2"
m2Plot.SetDefaultColor(GlobalColor("plotColorS"));
plot s1Plot = if rangeBias or allBias then s1Level[1] else na; # "S1"
s1Plot.SetDefaultColor(GlobalColor("plotColorSL"));
plot m1Plot = if bearBias or oopBias or allBias then m1Level[1] else na; # "M1"
m1Plot.SetDefaultColor(GlobalColor("plotColorS"));
plot s2Plot = if bearBias or oopBias or allBias then s2Level[1] else na; # "S2"
s2Plot.SetDefaultColor(GlobalColor("plotColorS"));
r2Plot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
m4Plot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r1Plot.SetPaintingStrategy(PaintingStrategy.DASHES);
m3Plot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
m2Plot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s1Plot.SetPaintingStrategy(PaintingStrategy.DASHES);
m1Plot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s2Plot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddCloud (r2Plot, m4Plot, CreateColor(39,0,0));
AddCloud (m3Plot, pPlot , CreateColor(39,0,0));
AddCloud (m1Plot, s2Plot, CreateColor(0,39,0));
AddCloud (pPlot, m2Plot , CreateColor(0,39,0));
#--- END Of Code