OK. So here's what I have:
The basic idea is to take Mobius' Pivot Points, count up bars since a high pivot, at the next low pivot start counting down from however many bars you counted up. Plot while those numbers are above zero.
You can see in this image that it finds the pivots, and draws the right half of the T, but it does not display the left top bar of the T. I can't for the life of me get it to draw that part.
The lower indicator, called debug shows the bar counts since a high pivot, and the countdown for the right bar.
This one has a bunch of additional labels as I was trying to sort out what was wonky with the left T bar. This image represents the indicator as it is uploaded here. There is no ToS link, as the indicator is not really functional yet.
Work in progress, uploaded for community help in finishing / polishing.
It is quite sensitive to the length parameter in the pivot point part of the indicator, though I'm not sure I understand quite why.
-mashume
UPPER
LOWER
There may be scale issues if it tries to plot some of the dots on the lower study. I turn things on and off all the time.
The basic idea is to take Mobius' Pivot Points, count up bars since a high pivot, at the next low pivot start counting down from however many bars you counted up. Plot while those numbers are above zero.
You can see in this image that it finds the pivots, and draws the right half of the T, but it does not display the left top bar of the T. I can't for the life of me get it to draw that part.
The lower indicator, called debug shows the bar counts since a high pivot, and the countdown for the right bar.
This one has a bunch of additional labels as I was trying to sort out what was wonky with the left T bar. This image represents the indicator as it is uploaded here. There is no ToS link, as the indicator is not really functional yet.
Work in progress, uploaded for community help in finishing / polishing.
It is quite sensitive to the length parameter in the pivot point part of the indicator, though I'm not sure I understand quite why.
-mashume
UPPER
Code:
declare upper;
## Inputs
## ProjectionPivots_v03_JQ
## 03.04.2019
## Original Code and Concept by Mobius:
# V01.08.2012 Projection Pivots
# mobius
# Notes:
# 03.04.2019 added linits on extensions
# 03.05.2019 adjusted limits on extensions by adding user input upper and lower extenion percent limits
#declare Once_Per_Bar;
## Inputs
input n = 21;
input showLines = yes;
input showValues = no;
input showBarNumbers = no;
input ExtensionLengthBars = 20; # added to control length of Entension
input UpperExtensionPercentLimit = 5;
input LowerExtensionPercentLimit = 5;
# input DisplayLabel = yes; ## JQ 7.8.2018 added
# addlabel (DisplayLabel, "Projection Pivots n:" + n + " " , color.WHITE); ## JQ 7.8.2018 added
# Universal Header _v030429019 _JQ
# code from various sources including Mobius, NoLongerNube and others
# Comment out unnecessary portions to preserve tos memory and enhance speed
# Universal Definitions using Padawan variable naming convention (JQ) v03.04.2019
# iData Definitions
def vHigh = high; # creates the variable vHigh. Use of the variable reduce data calls to tos iData server
# def initHigh = CompoundValue(1, high, high); # creates and initialized variable for High
def vLow = low;
# def initLow = CompoundValue(1, low, low);
def vOpen = open;
# def initOpen = CompoundValue(1, open, open);
def vClose = close;
# def initClose = CompoundValue(1, close, close);
def vVolume = volume;
# def initVolume = CompoundValue(1, volume, volume);
def nan = Double.NaN;
# Bar Time & Date
def bn = BarNumber();
def currentBar = HighestAll(if !IsNaN(vHigh) then bn else nan);
# def Today = GetDay() ==GetLastDay();
# def time = GetTime();
# def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
# def globeX_v2 = if time crosses below RegularTradingEnd(GetYYYYMMDD()) then bn else GlobeX[1];
# def RTS = RegularTradingStart(GetYYYYMMDD());
# def RTE = RegularTradingEnd(GetYYYYMMDD());
# def RTH = GetTime() > RegularTradingStart(GetYYYYMMDD());
# def RTH_v2 = if time crosses above RegularTradingStart(GetYYYYMMDD()) then bn else RTH[1];
# bars that start and end the sessions #(borrowed from nube)
# def rthStartBar = CompoundValue(1,
# if !IsNaN(vClose)
# && time crosses above RegularTradingStart(GetYYYYMMDD())
# then bn
# else rthStartBar[1], 0);
# def rthEndBar = CompoundValue(1,
# if !IsNaN(vClose)
# && time crosses above RegularTradingEnd(GetYYYYMMDD())
# then bn
# else rthEndBar[1], 1);
# def globexStartBar = CompoundValue(1,
# if !IsNaN(vClose)
# && time crosses below RegularTradingEnd(GetYYYYMMDD())
# then bn
# else globexStartBar[1], 1);
# def rthSession = if bn crosses above rthStartBar #+ barsExtendedBeyondSession
# then 1
# else if bn crosses above rthEndBar #+ barsExtendedBeyondSession
# then 0
# else rthSession[1];
# Bubble Locations
def x_AxisLastExpansionBar = BarNumber() == HighestAll(BarNumber()); #corrected 11.12.2018 (JQ)
# syntax: addChartBubble(x_AxisLastExpansionBar, y-axis coordinate," text", Color.LIME); #verified 12.25.2018 (JQ)
def PH;
def PL;
def hh = fold i = 1 to n + 1
with p = 1
while p
do vHigh > getValue(vHigh, -i);
PH = if (bn > n and
vHigh == highest(vHigh, n) and
hh)
then vHigh
else double.NaN;
def ll = fold j = 1 to n + 1
with q = 1
while q
do vLow < getValue(low, -j);
PL = if (bn > n and
vLow == lowest(vLow, n) and
ll)
then vLow
else double.NaN;
def PHBar = if !isNaN(PH)
then bn
else PHBar[1];
def PLBar = if !isNaN(PL)
then bn
else PLBar[1];
def PHL = if !isNaN(PH)
then PH
else PHL[1];
def priorPHBar = if PHL != PHL[1]
then PHBar[1]
else priorPHBar[1];
def PLL = if !isNaN(PL)
then PL
else PLL[1];
def priorPLBar = if PLL != PLL[1]
then PLBar[1]
else priorPLBar[1];
def HighPivots = bn >= highestAll(priorPHBar);
def LowPivots = bn >= highestAll(priorPLBar);
def FirstRpoint = if HighPivots
then bn - PHBar
else 0;
def PriorRpoint = if HighPivots
then bn - PriorPHBar
else 0;
def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
/ (PHBar - PriorPHBar);
def FirstSpoint = if LowPivots
then bn - PLBar
else 0;
def PriorSpoint = if LowPivots
then bn - PriorPLBar
else 0;
def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
/ (PLBar - PriorPLBar);
def RExtend = if bn == highestall(PHBar)
then 1
else RExtend[1];
def SExtend = if bn == highestall(PLBar)
then 1
else SExtend[1];
def pivotHigh = if HighPivots
then PH
else double.NaN;
def pivotHighLine = if PHL > 0 and
HighPivots
then PHL
else double.NaN;
def pivotHighLineBound = if PHL > 0 and
HighPivots
then PHL * 0.98
else double.NaN;
def RLine = pivotHigh;
# Added code to limit resistance estension line (JQ 03.04.2019)
def calc_ResistanceExtension = if RExtend
then (bn - PHBar) * RSlope + PHL
else double.NaN;
# Low Plots
def pivotLow = if LowPivots
then PL
else double.NaN;
plot PivotDot = if !isNaN(pivotHigh)
then pivotHigh
else if !isNaN(pivotLow)
then pivotLow
else double.NaN;
pivotDot.SetDefaultColor(GetColor(7));
pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
pivotDot.SetLineWeight(3);
# End Code
def left_side_count = if !isNaN(pivotHigh) then 0 else if !isNan(left_side_count[1]) then left_side_count[1] + 1 else double.nan;
def right_side_count = if !isNaN(pivotLow) then left_side_count[1] else right_side_count[1] - 1;
def lsc = left_side_count;
def rsc = right_side_count;
def zero = 0;
def left_side_plot = if !IsNaN(left_side_count)
# and left_side_count >= right_side_count
and right_side_count >= 0 then pivotHighLine else Double.NaN;
def right_side_plot = if right_side_count > 0 then if !IsNaN(left_side_plot[0]) then left_side_plot[0] else right_side_plot[1] else Double.NaN;
plot ls = left_side_plot;
plot rs = right_side_plot;
addVerticalLine(!isNan(PivotLow) and !isNaN(left_side_plot), color = Color.BLUE, stroke = Curve.FIRM);
plot end_dot = if right_side_plot[1] and isNaN(right_side_plot) then right_side_plot[1] else double.nan;
end_Dot.SetDefaultColor(GetColor(7));
end_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
end_Dot.SetLineWeight(3);
addChartBubble(pivotDot, HIGH, text = "DOT ==> rsc: " + rsc + " lsc: " + lsc, color.white);
addChartBubble(pivotHigh, high + 5, "HIGH", color.light_gray);
def start_left_side = pivotDot and pivotHigh and rsc != 0 and lsc == 0;
addChartBubble(
start_left_side
,high + 10,
"START_LEFT_SIDE!",
color.light_gray);
def end_left_side = pivotDot and pivotLow;
addchartbubble(pivotLow, low - 5, "LOW", color.light_gray);
addChartBubble(
end_left_side
,high + 5,
"END Left Side!",
color.light_gray);
def left_side_line = if start_left_side then high
else if end_left_side then double.nan
else left_side_line[1];
plot new_left_side_plot = left_side_line;
LOWER
Code:
declare upper;
## Inputs
## ProjectionPivots_v03_JQ
## 03.04.2019
## Original Code and Concept by Mobius:
# V01.08.2012 Projection Pivots
# mobius
# Notes:
# 03.04.2019 added linits on extensions
# 03.05.2019 adjusted limits on extensions by adding user input upper and lower extenion percent limits
#declare Once_Per_Bar;
## Inputs
input n = 21;
input showLines = yes;
input showValues = no;
input showBarNumbers = no;
input ExtensionLengthBars = 20; # added to control length of Entension
input UpperExtensionPercentLimit = 5;
input LowerExtensionPercentLimit = 5;
# input DisplayLabel = yes; ## JQ 7.8.2018 added
# addlabel (DisplayLabel, "Projection Pivots n:" + n + " " , color.WHITE); ## JQ 7.8.2018 added
# Universal Header _v030429019 _JQ
# code from various sources including Mobius, NoLongerNube and others
# Comment out unnecessary portions to preserve tos memory and enhance speed
# Universal Definitions using Padawan variable naming convention (JQ) v03.04.2019
# iData Definitions
def vHigh = high; # creates the variable vHigh. Use of the variable reduce data calls to tos iData server
# def initHigh = CompoundValue(1, high, high); # creates and initialized variable for High
def vLow = low;
# def initLow = CompoundValue(1, low, low);
def vOpen = open;
# def initOpen = CompoundValue(1, open, open);
def vClose = close;
# def initClose = CompoundValue(1, close, close);
def vVolume = volume;
# def initVolume = CompoundValue(1, volume, volume);
def nan = Double.NaN;
# Bar Time & Date
def bn = BarNumber();
def currentBar = HighestAll(if !IsNaN(vHigh) then bn else nan);
# def Today = GetDay() ==GetLastDay();
# def time = GetTime();
# def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
# def globeX_v2 = if time crosses below RegularTradingEnd(GetYYYYMMDD()) then bn else GlobeX[1];
# def RTS = RegularTradingStart(GetYYYYMMDD());
# def RTE = RegularTradingEnd(GetYYYYMMDD());
# def RTH = GetTime() > RegularTradingStart(GetYYYYMMDD());
# def RTH_v2 = if time crosses above RegularTradingStart(GetYYYYMMDD()) then bn else RTH[1];
# bars that start and end the sessions #(borrowed from nube)
# def rthStartBar = CompoundValue(1,
# if !IsNaN(vClose)
# && time crosses above RegularTradingStart(GetYYYYMMDD())
# then bn
# else rthStartBar[1], 0);
# def rthEndBar = CompoundValue(1,
# if !IsNaN(vClose)
# && time crosses above RegularTradingEnd(GetYYYYMMDD())
# then bn
# else rthEndBar[1], 1);
# def globexStartBar = CompoundValue(1,
# if !IsNaN(vClose)
# && time crosses below RegularTradingEnd(GetYYYYMMDD())
# then bn
# else globexStartBar[1], 1);
# def rthSession = if bn crosses above rthStartBar #+ barsExtendedBeyondSession
# then 1
# else if bn crosses above rthEndBar #+ barsExtendedBeyondSession
# then 0
# else rthSession[1];
# Bubble Locations
def x_AxisLastExpansionBar = BarNumber() == HighestAll(BarNumber()); #corrected 11.12.2018 (JQ)
# syntax: addChartBubble(x_AxisLastExpansionBar, y-axis coordinate," text", Color.LIME); #verified 12.25.2018 (JQ)
def PH;
def PL;
def hh = fold i = 1 to n + 1
with p = 1
while p
do vHigh > getValue(vHigh, -i);
PH = if (bn > n and
vHigh == highest(vHigh, n) and
hh)
then vHigh
else double.NaN;
def ll = fold j = 1 to n + 1
with q = 1
while q
do vLow < getValue(low, -j);
PL = if (bn > n and
vLow == lowest(vLow, n) and
ll)
then vLow
else double.NaN;
def PHBar = if !isNaN(PH)
then bn
else PHBar[1];
def PLBar = if !isNaN(PL)
then bn
else PLBar[1];
def PHL = if !isNaN(PH)
then PH
else PHL[1];
def priorPHBar = if PHL != PHL[1]
then PHBar[1]
else priorPHBar[1];
def PLL = if !isNaN(PL)
then PL
else PLL[1];
def priorPLBar = if PLL != PLL[1]
then PLBar[1]
else priorPLBar[1];
def HighPivots = bn >= highestAll(priorPHBar);
def LowPivots = bn >= highestAll(priorPLBar);
def FirstRpoint = if HighPivots
then bn - PHBar
else 0;
def PriorRpoint = if HighPivots
then bn - PriorPHBar
else 0;
def RSlope = (getvalue(PH, FirstRpoint) - getvalue(PH, PriorRpoint))
/ (PHBar - PriorPHBar);
def FirstSpoint = if LowPivots
then bn - PLBar
else 0;
def PriorSpoint = if LowPivots
then bn - PriorPLBar
else 0;
def SSlope = (getvalue(PL, FirstSpoint) - getvalue(PL, PriorSpoint))
/ (PLBar - PriorPLBar);
def RExtend = if bn == highestall(PHBar)
then 1
else RExtend[1];
def SExtend = if bn == highestall(PLBar)
then 1
else SExtend[1];
def pivotHigh = if HighPivots
then PH
else double.NaN;
def pivotHighLine = if PHL > 0 and
HighPivots
then PHL
else double.NaN;
def pivotHighLineBound = if PHL > 0 and
HighPivots
then PHL * 0.98
else double.NaN;
def RLine = pivotHigh;
# Added code to limit resistance estension line (JQ 03.04.2019)
def calc_ResistanceExtension = if RExtend
then (bn - PHBar) * RSlope + PHL
else double.NaN;
# Low Plots
def pivotLow = if LowPivots
then PL
else double.NaN;
def PivotDot = if !isNaN(pivotHigh)
then pivotHigh
else if !isNaN(pivotLow)
then pivotLow
else double.NaN;
# End Code
def left_side_count = if !isNaN(pivotHigh) then 0 else if !isNan(left_side_count[1]) then left_side_count[1] + 1 else double.nan;
def right_side_count = if !isNaN(pivotLow) then left_side_count[1] else right_side_count[1] - 1;
plot lsc = left_side_count;
plot rsc = right_side_count;
plot zero = 0;
def left_side_plot = if (!IsNaN(left_side_count)
# and left_side_count >= right_side_count
and right_side_count >= 0 )
then pivotHighLine else
if left_side_count[1] == 0 then pivotHighLine else Double.NaN;
def left = if pivotHigh
# and isnan(pivotHigh[1])
then pivotHighLine
else if pivotLow then double.nan else left[1];
plot l = left;
def right_side_plot = if right_side_count > 0 then if !IsNaN(left_side_plot[1]) then left_side_plot[1] else right_side_plot[1] else Double.NaN;
# plot ls = left_side_plot;
plot rs = right_side_plot;
addVerticalLine(!isNan(PivotLow) and !isNaN(left_side_plot), color = Color.BLUE, stroke = Curve.FIRM);
plot end_dot = if right_side_plot[1] and isNaN(right_side_plot) then right_side_plot[1] else double.nan;
end_Dot.SetDefaultColor(GetColor(7));
end_Dot.SetPaintingStrategy(PaintingStrategy.POINTS);
end_Dot.SetLineWeight(3);
def start_left_side = if pivotDot and pivotHigh and rsc != 0 and lsc == 0 then 1 else 0;
addChartBubble(
start_left_side
,high + 10,
"START_LEFT_SIDE!",
color.light_gray);
def end_left_side = pivotDot and pivotLow ;
# addchartbubble(pivotLow, low - 5, "LOW", color.light_gray);
# addChartBubble(
# end_left_side
# ,high + 5,
# "END Left Side!",
# color.light_gray);
def left_side_line = if start_left_side != 0 then 50
# else if !isNaN(end_left_side) then double.nan
# else if !isNaN(left_side_line[1]) then left_side_line[1]
else 100;
def a = if pivotDot then 100 else a[1];
plot new_left_side_plot =a;
There may be scale issues if it tries to plot some of the dots on the lower study. I turn things on and off all the time.