Peaks Valleys Bar Questions

TNTrader5159

Active member
How would I call the BarNumber of a condition in its most recent occurrence prior to either the current bar or counting from x number of bars back? All I saw in the tutorial is that BarNumber() calls up the current bar. I do not understand what that means.

Let's say I want to call up the most recent occurrence of the Low being less than a defined reference in number of bars back, eg Low < Lowest(Low, 34)[1]. Thanks!
 
@TNTTrader5159
Here's my variation on the code by @halcyonguy.
I mainly wrote it just to help myself with the logic being used, still needs a few tweeks.

lWBP4lv.png


Ruby:
input Number_Of_Engulfing_Bars = 2;
def Minimum_Signal_Bars = Number_Of_Engulfing_Bars * 3;

def Bar = if !IsNaN(close) and BarNumber() > 0 then BarNumber() else Bar[1];
def VBar = HighestAll(Bar);

def EngulfingBarsHigh = fold ebh = 0 to Number_Of_Engulfing_Bars
with intebh = high do
if GetValue(high, ebh) > intebh
then GetValue(high, ebh)
else intebh;

def EngulfingBarsLow = fold ebl = 0 to Number_Of_Engulfing_Bars
with intebl = low do
if GetValue(low, -ebl) < intebl
then GetValue(low, -ebl)
else intebl;

def EngulfingHigh = fold ueh = 1 to Minimum_Signal_Bars + 1 with intueh
while high > GetValue(low, Number_Of_Engulfing_Bars - 1)
and high == EngulfingBarsHigh
and GetValue(high, ueh + Number_Of_Engulfing_Bars - 1) <= high
and GetValue(low, ueh + Number_Of_Engulfing_Bars - 1) >= GetValue(low, Number_Of_Engulfing_Bars - 1)
and EngulfingHigh[1] <> Minimum_Signal_Bars
do intueh + 1;

def EngulfingLow = fold uel = 1 to Minimum_Signal_Bars + 1 with intuel
while  low < GetValue(high, Number_Of_Engulfing_Bars - 1)
and low == EngulfingBarsLow
and GetValue(low, uel + Number_Of_Engulfing_Bars - 1) >= low
and GetValue(high, uel + Number_Of_Engulfing_Bars - 1) <= GetValue(high, Number_Of_Engulfing_Bars - 1)
and EngulfingLow[1] <> Minimum_Signal_Bars
do intuel + 1;

def HighEngulfingBN = if EngulfingHigh == Minimum_Signal_Bars then Bar else HighEngulfingBN[1];
def LowEngulfingBN = if EngulfingLow == Minimum_Signal_Bars then Bar else LowEngulfingBN[1];

plot UEHP = if EngulfingHigh == Minimum_Signal_Bars then EngulfingHigh else Double.NaN;
UEHP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot UELP = if EngulfingLow == Minimum_Signal_Bars then EngulfingLow else Double.NaN;
UELP.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);


def EngulfingHighTarget = fold eht = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars) - 1)
while GetValue(EngulfingHigh, -eht) <> Minimum_Signal_Bars
do GetValue(EngulfingHigh, -eht - 1);

def EngulfingLowTarget = fold elt = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars) - 1)
while GetValue(EngulfingLow, -elt) <> Minimum_Signal_Bars
do GetValue(EngulfingLow, -elt - 1);


def HighEngulfingHigh = fold heh = 0 to ((Minimum_Signal_Bars + Number_Of_Engulfing_Bars) - 1)
while GetValue(EngulfingHighTarget, -heh) == Minimum_Signal_Bars
do GetValue(high, -heh - 1);
def HighEngulfingLow = fold hel = 0 to ((Minimum_Signal_Bars + (Number_Of_Engulfing_Bars - 1)))
while GetValue(EngulfingHighTarget, -hel - (Number_Of_Engulfing_Bars - 1)) == Minimum_Signal_Bars
do GetValue(low, -hel - 1);

def LowEngulfingHigh = fold leh = 0 to ((Minimum_Signal_Bars + (Number_Of_Engulfing_Bars - 1)))
while GetValue(EngulfingLowTarget, -leh - (Number_Of_Engulfing_Bars - 1)) == Minimum_Signal_Bars
do GetValue(high, -leh - 1);
def LowEngulfingLow = fold lel = 0 to ((Minimum_Signal_Bars + Number_Of_Engulfing_Bars) - 1)
while GetValue(EngulfingLowTarget, -lel) == Minimum_Signal_Bars
do GetValue(low, -lel - 1);

plot HEHP = if EngulfingHighTarget == Minimum_Signal_Bars and HighEngulfingHigh > 0 then HighEngulfingHigh else double.nan;
HEHP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot HELP = if EngulfingHighTarget == Minimum_Signal_Bars and HighEngulfingLow > 0 then HighEngulfingLow else Double.NaN;
HELP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot LEHP = if EngulfingLowTarget == Minimum_Signal_Bars and LowEngulfingHigh > 0 then LowEngulfingHigh else double.nan;
LEHP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot LELP = if EngulfingLowTarget == Minimum_Signal_Bars and LowEngulfingLow > 0 then LowEngulfingLow else Double.NaN;
LELP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def HighRangeHigh = fold hrh = 0 to Minimum_Signal_Bars + 1
with inthrh = high
while !IsNaN(GetValue(HELP,hrh))
do if GetValue(high, hrh) > inthrh
then GetValue(high, hrh)
else inthrh;

def LowRangeHigh = fold lrh = 0 to Minimum_Signal_Bars + 1
with intlrh = high
while !IsNaN(GetValue(LEHP,lrh))
do if GetValue(high, lrh) > intlrh
then GetValue(high, lrh)
else intlrh;

def HighRangeHighTarget = fold hrht = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingHigh, -hrht-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(HighRangeHigh, -hrht);

def LowRangeHighTarget = fold lrht = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingLow, -lrht-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(LowRangeHigh, -lrht);

def HighRangeLow = fold hrl = 0 to Minimum_Signal_Bars + 1
with inthrl = low
while !IsNaN(GetValue(HELP,hrl))
do if GetValue(low, hrl) < inthrl
then GetValue(low, hrl)
else inthrl;

def LowRangeLow = fold lrl = 0 to Minimum_Signal_Bars + 1
with intlrl = low
while !IsNaN(GetValue(LEHP,lrl))
do if GetValue(low, lrl) < intlrl
then GetValue(low, lrl)
else intlrl;

def HighRangeLowTarget = fold hrlt = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingHigh, -hrlt-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(HighRangeLow, -hrlt);

def LowRangeLowTarget = fold lrlt = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingLow, -lrlt-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(LowRangeLow, -lrlt);
 
plot HRHP = if !IsNaN(HELP) and high == HighRangeHighTarget then high else double.nan;
HRHP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
plot HRLP = if !IsNaN(HELP) and low == HighRangeLowTarget then low else double.nan;
HRLP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
plot LRHP = if !IsNaN(LEHP) and high == LowRangeHighTarget then high else double.nan;
LRHP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
plot LRLP = if !IsNaN(LEHP) and low == LowRangeLowTarget then high else double.nan;
LRLP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

def HighRangeHighBN =  if IsNaN(HEHP[1]) and IsNaN(HEHP) then double.nan else if !IsNaN(HELP) and IsNaN(HighRangeHighBN[1]) and !IsNaN(HRHP) then Bar else HighRangeHighBN[1];
def HighRangeLowBN = if IsNaN(HEHP[1]) and IsNaN(HEHP) then double.nan else if !IsNaN(HELP) and IsNaN(HighRangeLowBN[1]) and !IsNaN(HRLP) then Bar else HighRangeLowBN[1];

def LowRangeHighBN = if IsNaN(LELP[1]) and IsNaN(LELP) then double.nan else if !IsNaN(LEHP) and IsNaN(LowRangeHighBN[1]) and !IsNaN(LRHP) then Bar else LowRangeHighBN[1];
def LowRangeLowBN = if IsNaN(LELP[1]) and IsNaN(LELP) then double.nan else if !IsNaN(LEHP) and IsNaN(LowRangeLowBN[1]) and !IsNaN(LRLP) then Bar else LowRangeLowBN[1];

def HighRangeHighLowFirst = if HighRangeHighBN < HighRangeLowBN then HighRangeHighBN else HighRangeLowBN;
def LowRangeHighLowFirst = if LowRangeHighBN < LowRangeLowBN then LowRangeHighBN else LowRangeLowBN;

def ThrustFactor = if EngulfingHigh == Minimum_Signal_Bars then HighEngulfingBN-HighRangeHighLowFirst else
if EngulfingLow == Minimum_Signal_Bars then LowEngulfingBN-LowRangeHighLowFirst else double.nan;

addchartBubble(EngulfingHigh == Minimum_Signal_Bars,high,"Engulfing Bars "+Number_Of_Engulfing_Bars+"\nBars Engulfed " +Minimum_Signal_Bars+"\nThrust "+ThrustFactor,if HighRangeHighLowFirst==HighRangeHighBN then color.GREEN else color.RED,yes);
addchartbubble(EngulfingLow == Minimum_Signal_Bars,low,"Engulfing Bars "+Number_Of_Engulfing_Bars+"\nBars Engulfed " +Minimum_Signal_Bars+"\nThrust "+ThrustFactor,if LowRangeHighLowFirst==LowRangeHighBN then color.GREEN else color.RED,no);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@TNTTrader5159
Here's my variation on the code by @halcyonguy.
I mainly wrote it just to help myself with the logic being used, still needs a few tweeks.

lWBP4lv.png


Ruby:
input Number_Of_Engulfing_Bars = 2;
def Minimum_Signal_Bars = Number_Of_Engulfing_Bars * 3;

def Bar = if !IsNaN(close) and BarNumber() > 0 then BarNumber() else Bar[1];
def VBar = HighestAll(Bar);

def EngulfingBarsHigh = fold ebh = 0 to Number_Of_Engulfing_Bars
with intebh = high do
if GetValue(high, ebh) > intebh
then GetValue(high, ebh)
else intebh;

def EngulfingBarsLow = fold ebl = 0 to Number_Of_Engulfing_Bars
with intebl = low do
if GetValue(low, -ebl) < intebl
then GetValue(low, -ebl)
else intebl;

def EngulfingHigh = fold ueh = 1 to Minimum_Signal_Bars + 1 with intueh
while high > GetValue(low, Number_Of_Engulfing_Bars - 1)
and high == EngulfingBarsHigh
and GetValue(high, ueh + Number_Of_Engulfing_Bars - 1) <= high
and GetValue(low, ueh + Number_Of_Engulfing_Bars - 1) >= GetValue(low, Number_Of_Engulfing_Bars - 1)
and EngulfingHigh[1] <> Minimum_Signal_Bars
do intueh + 1;

def EngulfingLow = fold uel = 1 to Minimum_Signal_Bars + 1 with intuel
while  low < GetValue(high, Number_Of_Engulfing_Bars - 1)
and low == EngulfingBarsLow
and GetValue(low, uel + Number_Of_Engulfing_Bars - 1) >= low
and GetValue(high, uel + Number_Of_Engulfing_Bars - 1) <= GetValue(high, Number_Of_Engulfing_Bars - 1)
and EngulfingLow[1] <> Minimum_Signal_Bars
do intuel + 1;

def HighEngulfingBN = if EngulfingHigh == Minimum_Signal_Bars then Bar else HighEngulfingBN[1];
def LowEngulfingBN = if EngulfingLow == Minimum_Signal_Bars then Bar else LowEngulfingBN[1];

plot UEHP = if EngulfingHigh == Minimum_Signal_Bars then EngulfingHigh else Double.NaN;
UEHP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot UELP = if EngulfingLow == Minimum_Signal_Bars then EngulfingLow else Double.NaN;
UELP.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);


def EngulfingHighTarget = fold eht = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars) - 1)
while GetValue(EngulfingHigh, -eht) <> Minimum_Signal_Bars
do GetValue(EngulfingHigh, -eht - 1);

def EngulfingLowTarget = fold elt = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars) - 1)
while GetValue(EngulfingLow, -elt) <> Minimum_Signal_Bars
do GetValue(EngulfingLow, -elt - 1);


def HighEngulfingHigh = fold heh = 0 to ((Minimum_Signal_Bars + Number_Of_Engulfing_Bars) - 1)
while GetValue(EngulfingHighTarget, -heh) == Minimum_Signal_Bars
do GetValue(high, -heh - 1);
def HighEngulfingLow = fold hel = 0 to ((Minimum_Signal_Bars + (Number_Of_Engulfing_Bars - 1)))
while GetValue(EngulfingHighTarget, -hel - (Number_Of_Engulfing_Bars - 1)) == Minimum_Signal_Bars
do GetValue(low, -hel - 1);

def LowEngulfingHigh = fold leh = 0 to ((Minimum_Signal_Bars + (Number_Of_Engulfing_Bars - 1)))
while GetValue(EngulfingLowTarget, -leh - (Number_Of_Engulfing_Bars - 1)) == Minimum_Signal_Bars
do GetValue(high, -leh - 1);
def LowEngulfingLow = fold lel = 0 to ((Minimum_Signal_Bars + Number_Of_Engulfing_Bars) - 1)
while GetValue(EngulfingLowTarget, -lel) == Minimum_Signal_Bars
do GetValue(low, -lel - 1);

plot HEHP = if EngulfingHighTarget == Minimum_Signal_Bars and HighEngulfingHigh > 0 then HighEngulfingHigh else double.nan;
HEHP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot HELP = if EngulfingHighTarget == Minimum_Signal_Bars and HighEngulfingLow > 0 then HighEngulfingLow else Double.NaN;
HELP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot LEHP = if EngulfingLowTarget == Minimum_Signal_Bars and LowEngulfingHigh > 0 then LowEngulfingHigh else double.nan;
LEHP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot LELP = if EngulfingLowTarget == Minimum_Signal_Bars and LowEngulfingLow > 0 then LowEngulfingLow else Double.NaN;
LELP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def HighRangeHigh = fold hrh = 0 to Minimum_Signal_Bars + 1
with inthrh = high
while !IsNaN(GetValue(HELP,hrh))
do if GetValue(high, hrh) > inthrh
then GetValue(high, hrh)
else inthrh;

def LowRangeHigh = fold lrh = 0 to Minimum_Signal_Bars + 1
with intlrh = high
while !IsNaN(GetValue(LEHP,lrh))
do if GetValue(high, lrh) > intlrh
then GetValue(high, lrh)
else intlrh;

def HighRangeHighTarget = fold hrht = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingHigh, -hrht-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(HighRangeHigh, -hrht);

def LowRangeHighTarget = fold lrht = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingLow, -lrht-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(LowRangeHigh, -lrht);

def HighRangeLow = fold hrl = 0 to Minimum_Signal_Bars + 1
with inthrl = low
while !IsNaN(GetValue(HELP,hrl))
do if GetValue(low, hrl) < inthrl
then GetValue(low, hrl)
else inthrl;

def LowRangeLow = fold lrl = 0 to Minimum_Signal_Bars + 1
with intlrl = low
while !IsNaN(GetValue(LEHP,lrl))
do if GetValue(low, lrl) < intlrl
then GetValue(low, lrl)
else intlrl;

def HighRangeLowTarget = fold hrlt = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingHigh, -hrlt-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(HighRangeLow, -hrlt);

def LowRangeLowTarget = fold lrlt = 0 to ((Number_Of_Engulfing_Bars + Minimum_Signal_Bars)-1)
while GetValue(EngulfingLow, -lrlt-(Number_Of_Engulfing_Bars-1)) <> Minimum_Signal_Bars
do GetValue(LowRangeLow, -lrlt);
 
plot HRHP = if !IsNaN(HELP) and high == HighRangeHighTarget then high else double.nan;
HRHP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
plot HRLP = if !IsNaN(HELP) and low == HighRangeLowTarget then low else double.nan;
HRLP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
plot LRHP = if !IsNaN(LEHP) and high == LowRangeHighTarget then high else double.nan;
LRHP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
plot LRLP = if !IsNaN(LEHP) and low == LowRangeLowTarget then high else double.nan;
LRLP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);

def HighRangeHighBN =  if IsNaN(HEHP[1]) and IsNaN(HEHP) then double.nan else if !IsNaN(HELP) and IsNaN(HighRangeHighBN[1]) and !IsNaN(HRHP) then Bar else HighRangeHighBN[1];
def HighRangeLowBN = if IsNaN(HEHP[1]) and IsNaN(HEHP) then double.nan else if !IsNaN(HELP) and IsNaN(HighRangeLowBN[1]) and !IsNaN(HRLP) then Bar else HighRangeLowBN[1];

def LowRangeHighBN = if IsNaN(LELP[1]) and IsNaN(LELP) then double.nan else if !IsNaN(LEHP) and IsNaN(LowRangeHighBN[1]) and !IsNaN(LRHP) then Bar else LowRangeHighBN[1];
def LowRangeLowBN = if IsNaN(LELP[1]) and IsNaN(LELP) then double.nan else if !IsNaN(LEHP) and IsNaN(LowRangeLowBN[1]) and !IsNaN(LRLP) then Bar else LowRangeLowBN[1];

def HighRangeHighLowFirst = if HighRangeHighBN < HighRangeLowBN then HighRangeHighBN else HighRangeLowBN;
def LowRangeHighLowFirst = if LowRangeHighBN < LowRangeLowBN then LowRangeHighBN else LowRangeLowBN;

def ThrustFactor = if EngulfingHigh == Minimum_Signal_Bars then HighEngulfingBN-HighRangeHighLowFirst else
if EngulfingLow == Minimum_Signal_Bars then LowEngulfingBN-LowRangeHighLowFirst else double.nan;

addchartBubble(EngulfingHigh == Minimum_Signal_Bars,high,"Engulfing Bars "+Number_Of_Engulfing_Bars+"\nBars Engulfed " +Minimum_Signal_Bars+"\nThrust "+ThrustFactor,if HighRangeHighLowFirst==HighRangeHighBN then color.GREEN else color.RED,yes);
addchartbubble(EngulfingLow == Minimum_Signal_Bars,low,"Engulfing Bars "+Number_Of_Engulfing_Bars+"\nBars Engulfed " +Minimum_Signal_Bars+"\nThrust "+ThrustFactor,if LowRangeHighLowFirst==LowRangeHighBN then color.GREEN else color.RED,no);
YES thank you! I am also doing a couple tweaks as I begin to assemble the logic of this pattern along with the 3 forms of Impedance (support & resistance) as you have worked on (Pivots [peaks & valleys] and the PDI [Price Density Index] spoken of elsewhere).
<p>
The Thrust Factor is actually a ratio and not a fixed number of bars. With one engulfing bar, the minimum Thrust Factor is 3 bars, which is also the key minimum ratio of 3:1. However, using 2 engulfing bars as in your example here, if they engulf 6 bars (minimum), the Thrust Factor is still 3 and to be used as such in later comparison with the strength of the pivots (measured in single bars) along with their depreciation factor as you have worked on.
<p>
Really and ideally we use TIME as a basis for all this. Theoretically, if a move taking 1:26 to engulf price action in a minimum 3x the time preceding it (at least 4:18), it would be a signal. It is not practical to try and achieve that level of precision with the tools we have to work with and market action that may not always be enough to provide good granularity.
<p>
The following is under construction and how I set it up to change only the input <ratio1> to make this work for minimum bar ratios of 2:6, 3:9, 4:12, 5:15, etc all on a 1-minute chart. The derivative value <ratio2> is the minimum number of bars engulfed by the trigger bar(s). With a single engulfing bar, the qualifier of close > open for a Long trade or close < open for a Short trade can be used, which is imperfect but as close as we can get in ThinkScript to ensure which end of the engulfed bar range was eclipsed first in order to determine trade direction.
<p>Using 2 (as in your example) or more trigger bars, the LAST bar of the trigger bars (however many there are) must be the one to break the high or low of the engulfed range of bars to trigger a potential trade in either direction, so you know which end of the engulfed range was eclipsed first. (I believe you have already taken this same logic to achieve this goal.) Otherwise, the number of bars it took to engulf said range (eg 5 engulfing 15) would be less and covered by a pair of factors with a lower <ratio1> value, as long as all relative factor pairs are examined concurrently.
<p>
Any questions just ask.

Code:
declare lower;

def bn = barnumber();
def nn = double.nan;
# (ignore those for now) #

input minratio = 3;
input ratio1 = 2;
def ratio2 = minratio * ratio1;
def trigbars = ratio1 - 1;

plot trigbarsbear = if highest(high, trigbars)[1] > highest(high, ratio2)[ratio1] and lowest(low, trigbars)[1] >= lowest(low, ratio2)[ratio1] and high < highest(high, trigbars)[1] and low < lowest(low, ratio2 + trigbars)[1] then -2 else 0;
trigbarsbear.setdefaultcolor(createcolor(255, 0, 0));

plot trigbarsbull = if lowest(low, trigbars)[1] < lowest(low, ratio2)[ratio1] and highest(high, trigbars)[1] <= highest(high, ratio2)[ratio1] and low > lowest(low, trigbars)[1] and high > highest(high, ratio2 + trigbars)[1] then 2 else 0;
trigbarsbull.setdefaultcolor(createcolor(0, 255, 0));

<p>
Also, factoring in volume would not be practical or effective, since it can vary so much throughout a trading session and therefore invalid as a relative measure. People are paid on price not volume. Volume spikes on trigger bars (engulfing bars) CAN corroborate a signal indicating the players are on board for an upcoming move. These with no nearby Impedance are what I call "dream trades" or "no-brainers" that go the right way fast and far. And we really seek only to ride the coattails of the market makers to riches once we see their markers and act accordingly.
<p>
These patterns don't show up as often on daily and weekly charts, since it is less efficient to trade longer term and the players who move the markets up and down within the framework of long-term fundamentals (which we should ignore) are working within the shorter time frames.
 
The Thrust Factor is actually a ratio and not a fixed number of bars.
I wrote it with a fixed amount so I could easily verify functionality while writing it. There is an input of minimum bars as well, to test the ratios.

Changing it to find any number of engulfing bars and the correct ratio of engulfed bars is one of the tweaks. Easily done now that the basic functionality is there.
 
I wrote it with a fixed amount so I could easily verify functionality while writing it. There is an input of minimum bars as well, to test the ratios.

Changing it to find any number of engulfing bars and the correct ratio of engulfed bars is one of the tweaks. Easily done now that the basic functionality is there.
Yes, then we're on the same page! Great great great. So now we can stitch together what I have come to call the Fake n Break pattern with the Impedance Factor for comparison. What I thought of doing is creating a Study Set in TOS with many ratios starting with 3:1 and going up in increments of 1 for the <ratio1> values as high as computing resources will allow using the TOS minimum 1-minute aggregate. This is for greatest efficiency in trade detection and precision in entry points. Using 20 x 1-minute bars that collectively mature every minute is much better than using fixed 20-minute bars. A lot can happen during a 20-minute bar that can influence a trade and whether or not to take it that 20 bars from a 1-minute aggregate will show. That was always a problem I saw when trading real-time, ie you're always working with an immature current bar that will skew indicators vs in historical analysis.
<p>
Did you ever post the code for the pivots and depreciation scale?
<p>
What we will have to do is call upon secondary aggregates for finding Impedance (support/resistance) in the forms of those pivots (peaks & valleys) farther back than a 1-minute chart will show that is a must for this system. I can't tell you how many trades during my life would have gone much better if I had been aware of longer-term Impedance (support/resistance) behind whatever chart I was working with! The Impedance Factor is the single most important factor in determining the likely stopping point of a move, however far back it is.
<p>
I have never placed much store in trend following. Trading with the "trade winds" is ideal, but good short-term trades can and do go contrary to a longer-term trend. Markets don't turn randomly; they turn for a reason at certain "comfort zones" in going from station to station.
<p>
I learned to trade after my first decade of winging it with every known indicator and/or combination thereof and then shaking my head to say all those things were just fancy ways of telling me what the market had already done and not what it is likely to do in the only place to make money -- the future!
<p>
So in 1992, I decided to wipe the slate clean and looked at a blank OHLC bar chart to ask myself, "Matt, what do you see?" And my eyes began to open. I looked at many charts on all time-frames, reverse-engineered turns, and figured out what is common to the ones that launch moves and why those moves stop where they do.
<p>
It's been a multi-decade saga of trial and error and eliminating what does not work. It's the willingness to take many small, sure gains over a larger, less certain gains that, win or lose, eat up your most valuable commodity -- TIME. Most traders swing for the fences when smallball beats a team of sluggers every day and twice on Sunday. In baseball terms, good pitching, defense, speed, and batting average win the World Series. It's no different in trading for a living.
 
Yes, then we're on the same page! Great great great. So now we can stitch together what I have come to call the Fake n Break pattern with the Impedance Factor for comparison. What I thought of doing is creating a Study Set in TOS with many ratios starting with 3:1 and going up in increments of 1 for the <ratio1> values as high as computing resources will allow using the TOS minimum 1-minute aggregate. This is for greatest efficiency in trade detection and precision in entry points. Using 20 x 1-minute bars that collectively mature every minute is much better than using fixed 20-minute bars. A lot can happen during a 20-minute bar that can influence a trade and whether or not to take it that 20 bars from a 1-minute aggregate will show. That was always a problem I saw when trading real-time, ie you're always working with an immature current bar that will skew indicators vs in historical analysis.
<p>
Did you ever post the code for the pivots and depreciation scale?
<p>
What we will have to do is call upon secondary aggregates for finding Impedance (support/resistance) in the forms of those pivots (peaks & valleys) farther back than a 1-minute chart will show that is a must for this system. I can't tell you how many trades during my life would have gone much better if I had been aware of longer-term Impedance (support/resistance) behind whatever chart I was working with! The Impedance Factor is the single most important factor in determining the likely stopping point of a move, however far back it is.
<p>
I have never placed much store in trend following. Trading with the "trade winds" is ideal, but good short-term trades can and do go contrary to a longer-term trend. Markets don't turn randomly; they turn for a reason at certain "comfort zones" in going from station to station.
<p>
I learned to trade after my first decade of winging it with every known indicator and/or combination thereof and then shaking my head to say all those things were just fancy ways of telling me what the market had already done and not what it is likely to do in the only place to make money -- the future!
<p>
So in 1992, I decided to wipe the slate clean and looked at a blank OHLC bar chart to ask myself, "Matt, what do you see?" And my eyes began to open. I looked at many charts on all time-frames, reverse-engineered turns, and figured out what is common to the ones that launch moves and why those moves stop where they do.
<p>
It's been a multi-decade saga of trial and error and eliminating what does not work. It's the willingness to take many small, sure gains over a larger, less certain gains that, win or lose, eat up your most valuable commodity -- TIME. Most traders swing for the fences when smallball beats a team of sluggers every day and twice on Sunday. In baseball terms, good pitching, defense, speed, and batting average win the World Series. It's no different in trading for a living.
Further qualifiers for the engulfed range of bars are as follows:
1. It must be big enough to be worth trading without commission and slippage eating up too much value, and I compare the price range to an EMA of <High - Low> over 987 bars, which is usually a good measure of "big enough." An absolute number could be used, though for every symbol it would be different and needing reference to a separate file for each symbol's minimum range.

2. You don't want any extremely long trigger bars, so I limit the extent of them. This way: For a Short setup, the high of the trigger bar can be no more than one engulfed price range above the range itself, and in the case of a Long setup, the low of the trigger can be no less than one engulfed price range below the range itself.

3. Also measure the distance from the high of the trigger bar to the low of the engulfed range for a Short setup and from the low of the trigger bar to the high of the engulfed range for a Long setup. Call this the SPP or Standard Profit Projection. This will later be used in the placement of stops and position reversal signals. More on this later.
 
@TNTrader5159 here is the study for the pivots with an input to choose higher aggregations.

While this study does NOT reference Zig Zag, It still has a repainting aspect to it for the last pivot as it is not confirmed until bars later.
It is NOT a standalone and should NOT be used as such.

Ruby:
input Show_Bubbles = no;
input Aggregation = AggregationPeriod.MIN;

def PivotHigh = high(period = Aggregation);
def PivotLow = low(period = Aggregation);
def PivotOpen = open(period = Aggregation);
def PivotClose = close(period = Aggregation);

#Current Close/Bar/Expansion Start#
def Bar = if !IsNaN(PivotClose) and BarNumber() > 0 then BarNumber() else Bar[1];
def VBar = HighestAll(Bar);
def FinalClose = fold c = 0 to VBar while !IsNaN(Bar) and !IsNaN(GetValue(PivotClose, -c)) do GetValue(PivotClose, -c);
def ExpansionStart = if IsNaN(PivotClose) and !IsNaN(PivotClose[1]) then FinalClose[1] else ExpansionStart[1];

#High/Low Pivot Initial Flags#
def HighPivotInitialFlag;
def LowPivotInitialFlag;
def HighClearCheck;
def LowClearCheck;
def InitialFlagCheck;

HighClearCheck = CompoundValue(1,if LowPivotInitialFlag[1] then PivotHigh[1] else if PivotLow > HighClearCheck[1] then 0 else HighClearCheck[1],0);
LowClearCheck = CompoundValue(1,if HighPivotInitialFlag[1] then PivotLow[1] else if PivotHigh < LowClearCheck[1] then 0 else LowClearCheck[1],0);
HighPivotInitialFlag = PivotHigh > PivotHigh[1] and PivotHigh >= PivotHigh[-1] and !HighClearCheck;
LowPivotInitialFlag = PivotLow < PivotLow[1] and PivotLow <= PivotLow[-1] and !LowClearCheck;
InitialFlagCheck = if HighPivotInitialFlag then 1 else if LowPivotInitialFlag then 0 else InitialFlagCheck[1];

#High/Low Pivot Secondary Flags#
def SecondaryHighPivotFlag;
def SecondaryLowPivotFlag;
def SecondayFlagCheck;

SecondaryHighPivotFlag = if HighPivotInitialFlag == 1 and !InitialFlagCheck[1] then fold hpf = 0 to VBar - Bar with inthpf = PivotHigh while GetValue(LowPivotInitialFlag, -hpf) == 0 or (GetValue(LowPivotInitialFlag, -hpf) == 1 and GetValue(HighPivotInitialFlag, -hpf) == 1) do if GetValue(PivotHigh, -hpf) > inthpf then GetValue(PivotHigh, -hpf) else inthpf else SecondaryHighPivotFlag[1];
SecondaryLowPivotFlag = if LowPivotInitialFlag == 1 and InitialFlagCheck[1] then fold lpf = 0 to VBar - Bar with intlpf = PivotLow while GetValue(HighPivotInitialFlag, -lpf) == 0 or (GetValue(LowPivotInitialFlag, -lpf) == 1 and GetValue(HighPivotInitialFlag, -lpf) == 1) do if GetValue(PivotLow, -lpf) < intlpf then GetValue(PivotLow, -lpf) else intlpf else SecondaryLowPivotFlag[1];
SecondayFlagCheck = if PivotHigh == SecondaryHighPivotFlag and HighPivotInitialFlag then 1 else if PivotLow == SecondaryLowPivotFlag and LowPivotInitialFlag then 0 else SecondayFlagCheck[1];

#High/Low Pivot Final Flag/Pivot Value#
def HighPivot;
def LowPivot;
def PivotValue;

HighPivot = PivotHigh == SecondaryHighPivotFlag and HighPivotInitialFlag and !SecondayFlagCheck[1];
LowPivot = PivotLow == SecondaryLowPivotFlag and LowPivotInitialFlag and SecondayFlagCheck[1];
PivotValue = if HighPivot then PivotHigh else if LowPivot then PivotLow else 0;

#Last Pivot Check#
def LastPivot = if HighPivot or LowPivot then fold lp = 0 to VBar - Bar with intlp while !IsNaN(GetValue(PivotClose, -lp)) do if GetValue(HighPivot, -lp) or GetValue(LowPivot, -lp) then intlp + 1 else intlp else 0;

#Count Forward and Backwards Bars to next opposite pivot#
def HighForwardCount = fold hfc = 0 to VBar - Bar with inthfc while GetValue(LowPivot, -hfc) == 0 do inthfc + 1;
def HighBackwardCount = fold hbc = 0 to Bar with inthbc while GetValue(LowPivot, hbc) == 0 do inthbc + 1;
def LowForwardCount = fold lfc = 0 to VBar - Bar with intlfc while GetValue(HighPivot, -lfc) == 0 do intlfc + 1;
def LowBackwardCount = fold lbc = 0 to Bar with intlbc while GetValue(HighPivot, lbc) == 0 do intlbc + 1;

#Initial PivotPoints Strength#
def HighPivotStrength = if HighForwardCount < 3 or HighBackwardCount < 3 then 0 else if HighForwardCount < HighBackwardCount then HighForwardCount else HighBackwardCount;
def LowPivotStrength = if LowForwardCount < 3 or LowBackwardCount < 3 then 0 else if LowForwardCount < LowBackwardCount then LowForwardCount else LowBackwardCount;

#Price Height#
def HighPivotForwardPriceHeight = if HighPivot then PivotHigh - fold hpfph = 0 to VBar - Bar with inthpfph = PivotLow while GetValue(PivotHigh, -hpfph) <= PivotValue do if GetValue(PivotLow, -hpfph) < inthpfph then GetValue(PivotLow, -hpfph) else inthpfph else 0;
def HighPivotBackwardPriceHeight = if HighPivot then PivotHigh - fold hpbph = 0 to Bar with inthpbph = PivotLow while GetValue(PivotHigh, hpbph) <= PivotValue do if GetValue(PivotLow, hpbph) < inthpbph then GetValue(PivotLow, hpbph) else inthpbph else 0;
def HighPivotPriceHeight = if HighPivotForwardPriceHeight < HighPivotBackwardPriceHeight then HighPivotForwardPriceHeight else HighPivotBackwardPriceHeight;

def LowPivotForwardPriceHeight = if LowPivot then (fold lpfph = 0 to VBar - Bar with intlpfph = PivotHigh while GetValue(PivotLow, -lpfph) >= PivotValue do if GetValue(PivotHigh, -lpfph) > intlpfph then GetValue(PivotHigh, -lpfph) else intlpfph) - PivotLow else 0;
def LowPivotBackwardPriceHeight = if LowPivot then (fold lpbph = 0 to Bar with intlpbph = PivotHigh while GetValue(PivotLow, lpbph) >= PivotValue do if GetValue(PivotHigh, lpbph) > intlpbph then GetValue(PivotHigh, lpbph) else intlpbph) - PivotLow else 0;
def LowPivotPriceHeight = if LowPivotForwardPriceHeight < LowPivotBackwardPriceHeight then LowPivotForwardPriceHeight else LowPivotBackwardPriceHeight;

#Count Bars until Crossed#
def HighPivotCross = if HighPivot then fold hpc = 0 to VBar - Bar with inthpc while GetValue(PivotHigh, -hpc - 1) <= PivotValue do if IsNaN(GetValue(PivotClose, -hpc - 2)) then 0 else inthpc + 1 else Double.NaN;
def LowPivotCross = if LowPivot then fold lpc = 0 to VBar - Bar with intlpc while GetValue(PivotLow, -lpc - 1) >= PivotValue do if IsNaN(GetValue(PivotClose, -lpc - 2)) then 0 else intlpc + 1 else Double.NaN;

#Decrease Pivot Strength After Cross#
def HighPivotResistanceStrength = if HighPivot then fold hprs = 0 to VBar - Bar with inthprs = HighPivotStrength / 2 while !IsNaN(GetValue(PivotClose, -hprs - 1)) and inthprs > 0 do if hprs > HighPivotCross and HighPivotCross and GetValue(PivotLow, -hprs) > PivotValue then inthprs - .5 else if GetValue(PivotHigh, -hprs) > PivotValue and GetValue(PivotLow, -hprs) < PivotValue then inthprs - (((GetValue(PivotHigh, -hprs) - PivotValue) / (GetValue(PivotHigh, -hprs) - GetValue(PivotLow, -hprs))) * .5) else inthprs else 0;
def FinalHighPivotResistanceStrength = if HighPivotResistanceStrength <= 0 then 0 else HighPivotResistanceStrength;

def HighPivotSupportStrength = if HighPivot then fold hpss = 0 to VBar - Bar with inthpss = HighPivotStrength / 2 while HighPivotResistanceStrength <= 0 and !IsNaN(GetValue(PivotClose, -hpss - 1)) and inthpss > 0 do if hpss > HighPivot and HighPivotCross and GetValue(PivotHigh, -hpss) < PivotValue then inthpss - .5 else if GetValue(PivotHigh, -hpss) > PivotValue and GetValue(PivotLow, -hpss) < PivotValue then inthpss - ((PivotValue - (GetValue(PivotLow, -hpss)) / (GetValue(PivotHigh, -hpss) - GetValue(PivotLow, -hpss))) * .5) else inthpss else 0;
def FinalHighPivotSupportStrength = if HighPivotSupportStrength <= 0 then 0 else HighPivotSupportStrength;

def LowPivotSupportStrength = if LowPivot then fold lpss = 0 to VBar - Bar with intlpss = LowPivotStrength / 2 while !IsNaN(GetValue(PivotClose, -lpss - 1)) and intlpss > 0 do if lpss > LowPivotCross and LowPivotCross and GetValue(PivotHigh, -lpss) < PivotValue then intlpss - .5 else if GetValue(PivotLow, -lpss) < PivotValue and GetValue(PivotHigh, -lpss) > PivotValue then intlpss - (((PivotValue - GetValue(PivotLow, -lpss)) / (GetValue(PivotHigh, -lpss) - GetValue(PivotLow, -lpss))) * .5) else intlpss else 0;
def FinalLowPivotSupportStrength = if LowPivotSupportStrength <= 0 then 0 else LowPivotSupportStrength;

def LowPivotResistanceStrength = if LowPivot then fold lprs = 0 to VBar - Bar with intlprs = LowPivotStrength / 2 while LowPivotSupportStrength <= 0 and !IsNaN(GetValue(PivotClose, -lprs - 1)) and intlprs > 0 do if lprs > LowPivotCross and LowPivotCross and GetValue(PivotLow, -lprs) > PivotValue then intlprs - .5 else if GetValue(PivotLow, -lprs) < PivotValue and GetValue(PivotHigh, -lprs) > PivotValue then intlprs - (((GetValue(PivotHigh, -lprs) - PivotValue) / (GetValue(PivotHigh, -lprs) - GetValue(PivotLow, -lprs))) * .5) else intlprs else 0;
def FinalLowPivotResistanceStrength = if LowPivotResistanceStrength <= 0 then 0 else LowPivotResistanceStrength;

def HighPivotTotalStrength = FinalHighPivotResistanceStrength + FinalHighPivotSupportStrength;
def LowPivotTotalStrength = FinalLowPivotResistanceStrength + FinalLowPivotSupportStrength;

plot Pivots = if HighPivot then PivotHigh else if LowPivot then PivotLow else Double.NaN;
Pivots.EnableApproximation();

AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "High Pivot\n" + PivotValue, Color.WHITE, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Low Pivot\n" + PivotValue, Color.WHITE, no);
AddChartBubble(HighPivot and !HighPivotCross and Show_Bubbles, PivotHigh, "Not Crossed", Color.WHITE, yes);
AddChartBubble(LowPivot and !LowPivotCross and Show_Bubbles, PivotLow, "Not Crossed", Color.WHITE, no);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Price Height " + HighPivotPriceHeight, Color.WHITE, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Price Height " + LowPivotPriceHeight, Color.WHITE, no);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Resistance Strength " + FinalHighPivotResistanceStrength, if HighPivotResistanceStrength <= 0 then Color.LIGHT_RED else if HighPivotResistanceStrength < HighPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, yes);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Support Strength " + FinalHighPivotSupportStrength, if HighPivotSupportStrength <= 0 then Color.LIGHT_RED else if HighPivotSupportStrength < HighPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Resistance Strength " + FinalLowPivotResistanceStrength, if LowPivotResistanceStrength <= 0 then Color.LIGHT_RED else if LowPivotResistanceStrength < LowPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, no);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Support Strength " + FinalLowPivotSupportStrength, if LowPivotSupportStrength <= 0 then Color.LIGHT_RED else if LowPivotSupportStrength < LowPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, no);
 
Last edited by a moderator:
@TNTrader5159 here is the study for the pivots with an input to choose higher aggregations.

While this study does NOT reference Zig Zag, It still has a repainting aspect to it for the last pivot as it is not confirmed until bars later.
It is NOT a standalone and should NOT be used as such.
Ruby:
input Show_Bubbles = no;
input Aggregation = AggregationPeriod.MIN;

def PivotHigh = high(period = Aggregation);
def PivotLow = low(period = Aggregation);
def PivotOpen = open(period = Aggregation);
def PivotClose = close(period = Aggregation);

#Current Close/Bar/Expansion Start#
def Bar = if !IsNaN(PivotClose) and BarNumber() > 0 then BarNumber() else Bar[1];
def VBar = HighestAll(Bar);
def FinalClose = fold c = 0 to VBar while !IsNaN(Bar) and !IsNaN(GetValue(PivotClose, -c)) do GetValue(PivotClose, -c);
def ExpansionStart = if IsNaN(PivotClose) and !IsNaN(PivotClose[1]) then FinalClose[1] else ExpansionStart[1];

#High/Low Pivot Initial Flags#
def HighPivotInitialFlag;
def LowPivotInitialFlag;
def HighClearCheck;
def LowClearCheck;
def InitialFlagCheck;

HighClearCheck = CompoundValue(1,if LowPivotInitialFlag[1] then PivotHigh[1] else if PivotLow > HighClearCheck[1] then 0 else HighClearCheck[1],0);
LowClearCheck = if HighPivotInitialFlag[1] then PivotLow[1] else if PivotHigh < LowClearCheck[1] then 0 else LowClearCheck[1];
HighPivotInitialFlag = PivotHigh > PivotHigh[1] and PivotHigh >= PivotHigh[-1] and !HighClearCheck;
LowPivotInitialFlag = PivotLow < PivotLow[1] and PivotLow <= PivotLow[-1] and !LowClearCheck;
InitialFlagCheck = if HighPivotInitialFlag then 1 else if LowPivotInitialFlag then 0 else InitialFlagCheck[1];

#High/Low Pivot Secondary Flags#
def SecondaryHighPivotFlag;
def SecondaryLowPivotFlag;
def SecondayFlagCheck;

SecondaryHighPivotFlag = if HighPivotInitialFlag == 1 and !InitialFlagCheck[1] then fold hpf = 0 to VBar - Bar with inthpf = PivotHigh while GetValue(LowPivotInitialFlag, -hpf) == 0 or (GetValue(LowPivotInitialFlag, -hpf) == 1 and GetValue(HighPivotInitialFlag, -hpf) == 1) do if GetValue(PivotHigh, -hpf) > inthpf then GetValue(PivotHigh, -hpf) else inthpf else SecondaryHighPivotFlag[1];
SecondaryLowPivotFlag = if LowPivotInitialFlag == 1 and InitialFlagCheck[1] then fold lpf = 0 to VBar - Bar with intlpf = PivotLow while GetValue(HighPivotInitialFlag, -lpf) == 0 or (GetValue(LowPivotInitialFlag, -lpf) == 1 and GetValue(HighPivotInitialFlag, -lpf) == 1) do if GetValue(PivotLow, -lpf) < intlpf then GetValue(PivotLow, -lpf) else intlpf else SecondaryLowPivotFlag[1];
SecondayFlagCheck = if PivotHigh == SecondaryHighPivotFlag and HighPivotInitialFlag then 1 else if PivotLow == SecondaryLowPivotFlag and LowPivotInitialFlag then 0 else SecondayFlagCheck[1];

#High/Low Pivot Final Flag/Pivot Value#
def HighPivot;
def LowPivot;
def PivotValue;

HighPivot = PivotHigh == SecondaryHighPivotFlag and HighPivotInitialFlag and !SecondayFlagCheck[1];
LowPivot = PivotLow == SecondaryLowPivotFlag and LowPivotInitialFlag and SecondayFlagCheck[1];
PivotValue = if HighPivot then PivotHigh else if LowPivot then PivotLow else 0;

#Last Pivot Check#
def LastPivot = if HighPivot or LowPivot then fold lp = 0 to VBar - Bar with intlp while !IsNaN(GetValue(PivotClose, -lp)) do if GetValue(HighPivot, -lp) or GetValue(LowPivot, -lp) then intlp + 1 else intlp else 0;

#Count Forward and Backwards Bars to next opposite pivot#
def HighForwardCount = fold hfc = 0 to VBar - Bar with inthfc while GetValue(LowPivot, -hfc) == 0 do inthfc + 1;
def HighBackwardCount = fold hbc = 0 to Bar with inthbc while GetValue(LowPivot, hbc) == 0 do inthbc + 1;
def LowForwardCount = fold lfc = 0 to VBar - Bar with intlfc while GetValue(HighPivot, -lfc) == 0 do intlfc + 1;
def LowBackwardCount = fold lbc = 0 to Bar with intlbc while GetValue(HighPivot, lbc) == 0 do intlbc + 1;

#Initial PivotPoints Strength#
def HighPivotStrength = if HighForwardCount < 3 or HighBackwardCount < 3 then 0 else if HighForwardCount < HighBackwardCount then HighForwardCount else HighBackwardCount;
def LowPivotStrength = if LowForwardCount < 3 or LowBackwardCount < 3 then 0 else if LowForwardCount < LowBackwardCount then LowForwardCount else LowBackwardCount;

#Price Height#
def HighPivotForwardPriceHeight = if HighPivot then PivotHigh - fold hpfph = 0 to VBar - Bar with inthpfph = PivotLow while GetValue(PivotHigh, -hpfph) <= PivotValue do if GetValue(PivotLow, -hpfph) < inthpfph then GetValue(PivotLow, -hpfph) else inthpfph else 0;
def HighPivotBackwardPriceHeight = if HighPivot then PivotHigh - fold hpbph = 0 to Bar with inthpbph = PivotLow while GetValue(PivotHigh, hpbph) <= PivotValue do if GetValue(PivotLow, hpbph) < inthpbph then GetValue(PivotLow, hpbph) else inthpbph else 0;
def HighPivotPriceHeight = if HighPivotForwardPriceHeight < HighPivotBackwardPriceHeight then HighPivotForwardPriceHeight else HighPivotBackwardPriceHeight;

def LowPivotForwardPriceHeight = if LowPivot then (fold lpfph = 0 to VBar - Bar with intlpfph = PivotHigh while GetValue(PivotLow, -lpfph) >= PivotValue do if GetValue(PivotHigh, -lpfph) > intlpfph then GetValue(PivotHigh, -lpfph) else intlpfph) - PivotLow else 0;
def LowPivotBackwardPriceHeight = if LowPivot then (fold lpbph = 0 to Bar with intlpbph = PivotHigh while GetValue(PivotLow, lpbph) >= PivotValue do if GetValue(PivotHigh, lpbph) > intlpbph then GetValue(PivotHigh, lpbph) else intlpbph) - PivotLow else 0;
def LowPivotPriceHeight = if LowPivotForwardPriceHeight < LowPivotBackwardPriceHeight then LowPivotForwardPriceHeight else LowPivotBackwardPriceHeight;

#Count Bars until Crossed#
def HighPivotCross = if HighPivot then fold hpc = 0 to VBar - Bar with inthpc while GetValue(PivotHigh, -hpc - 1) <= PivotValue do if IsNaN(GetValue(PivotClose, -hpc - 2)) then 0 else inthpc + 1 else Double.NaN;
def LowPivotCross = if LowPivot then fold lpc = 0 to VBar - Bar with intlpc while GetValue(PivotLow, -lpc - 1) >= PivotValue do if IsNaN(GetValue(PivotClose, -lpc - 2)) then 0 else intlpc + 1 else Double.NaN;

#Decrease Pivot Strength After Cross#
def HighPivotResistanceStrength = if HighPivot then fold hprs = 0 to VBar - Bar with inthprs = HighPivotStrength / 2 while !IsNaN(GetValue(PivotClose, -hprs - 1)) and inthprs > 0 do if hprs > HighPivotCross and HighPivotCross and GetValue(PivotLow, -hprs) > PivotValue then inthprs - .5 else if GetValue(PivotHigh, -hprs) > PivotValue and GetValue(PivotLow, -hprs) < PivotValue then inthprs - (((GetValue(PivotHigh, -hprs) - PivotValue) / (GetValue(PivotHigh, -hprs) - GetValue(PivotLow, -hprs))) * .5) else inthprs else 0;
def FinalHighPivotResistanceStrength = if HighPivotResistanceStrength <= 0 then 0 else HighPivotResistanceStrength;

def HighPivotSupportStrength = if HighPivot then fold hpss = 0 to VBar - Bar with inthpss = HighPivotStrength / 2 while HighPivotResistanceStrength <= 0 and !IsNaN(GetValue(PivotClose, -hpss - 1)) and inthpss > 0 do if hpss > HighPivot and HighPivotCross and GetValue(PivotHigh, -hpss) < PivotValue then inthpss - .5 else if GetValue(PivotHigh, -hpss) > PivotValue and GetValue(PivotLow, -hpss) < PivotValue then inthpss - ((PivotValue - (GetValue(PivotLow, -hpss)) / (GetValue(PivotHigh, -hpss) - GetValue(PivotLow, -hpss))) * .5) else inthpss else 0;
def FinalHighPivotSupportStrength = if HighPivotSupportStrength <= 0 then 0 else HighPivotSupportStrength;

def LowPivotSupportStrength = if LowPivot then fold lpss = 0 to VBar - Bar with intlpss = LowPivotStrength / 2 while !IsNaN(GetValue(PivotClose, -lpss - 1)) and intlpss > 0 do if lpss > LowPivotCross and LowPivotCross and GetValue(PivotHigh, -lpss) < PivotValue then intlpss - .5 else if GetValue(PivotLow, -lpss) < PivotValue and GetValue(PivotHigh, -lpss) > PivotValue then intlpss - (((PivotValue - GetValue(PivotLow, -lpss)) / (GetValue(PivotHigh, -lpss) - GetValue(PivotLow, -lpss))) * .5) else intlpss else 0;
def FinalLowPivotSupportStrength = if LowPivotSupportStrength <= 0 then 0 else LowPivotSupportStrength;

def LowPivotResistanceStrength = if LowPivot then fold lprs = 0 to VBar - Bar with intlprs = LowPivotStrength / 2 while LowPivotSupportStrength <= 0 and !IsNaN(GetValue(PivotClose, -lprs - 1)) and intlprs > 0 do if lprs > LowPivotCross and LowPivotCross and GetValue(PivotLow, -lprs) > PivotValue then intlprs - .5 else if GetValue(PivotLow, -lprs) < PivotValue and GetValue(PivotHigh, -lprs) > PivotValue then intlprs - (((GetValue(PivotHigh, -lprs) - PivotValue) / (GetValue(PivotHigh, -lprs) - GetValue(PivotLow, -lprs))) * .5) else intlprs else 0;
def FinalLowPivotResistanceStrength = if LowPivotResistanceStrength <= 0 then 0 else LowPivotResistanceStrength;

def HighPivotTotalStrength = FinalHighPivotResistanceStrength + FinalHighPivotSupportStrength;
def LowPivotTotalStrength = FinalLowPivotResistanceStrength + FinalLowPivotSupportStrength;

plot Pivots = if HighPivot then PivotHigh else if LowPivot then PivotLow else Double.NaN;
Pivots.EnableApproximation();

AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "High Pivot\n" + PivotValue, Color.WHITE, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Low Pivot\n" + PivotValue, Color.WHITE, no);
AddChartBubble(HighPivot and !HighPivotCross and Show_Bubbles, PivotHigh, "Not Crossed", Color.WHITE, yes);
AddChartBubble(LowPivot and !LowPivotCross and Show_Bubbles, PivotLow, "Not Crossed", Color.WHITE, no);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Price Height " + HighPivotPriceHeight, Color.WHITE, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Price Height " + LowPivotPriceHeight, Color.WHITE, no);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Resistance Strength " + FinalHighPivotResistanceStrength, if HighPivotResistanceStrength <= 0 then Color.LIGHT_RED else if HighPivotResistanceStrength < HighPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, yes);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Support Strength " + FinalHighPivotSupportStrength, if HighPivotSupportStrength <= 0 then Color.LIGHT_RED else if HighPivotSupportStrength < HighPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Resistance Strength " + FinalLowPivotResistanceStrength, if LowPivotResistanceStrength <= 0 then Color.LIGHT_RED else if LowPivotResistanceStrength < LowPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, no);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Support Strength " + FinalLowPivotSupportStrength, if LowPivotSupportStrength <= 0 then Color.LIGHT_RED else if LowPivotSupportStrength < LowPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, no);
I understand. Is this original or your adaptation of an original work? I have not gone over it in detail as yet.
 
Last edited by a moderator:
@TNTrader5159 here is the study for the pivots with an input to choose higher aggregations.

While this study does NOT reference Zig Zag, It still has a repainting aspect to it for the last pivot as it is not confirmed until bars later.
It is NOT a standalone and should NOT be used as such.
Ruby:
input Show_Bubbles = no;
input Aggregation = AggregationPeriod.MIN;

def PivotHigh = high(period = Aggregation);
def PivotLow = low(period = Aggregation);
def PivotOpen = open(period = Aggregation);
def PivotClose = close(period = Aggregation);

#Current Close/Bar/Expansion Start#
def Bar = if !IsNaN(PivotClose) and BarNumber() > 0 then BarNumber() else Bar[1];
def VBar = HighestAll(Bar);
def FinalClose = fold c = 0 to VBar while !IsNaN(Bar) and !IsNaN(GetValue(PivotClose, -c)) do GetValue(PivotClose, -c);
def ExpansionStart = if IsNaN(PivotClose) and !IsNaN(PivotClose[1]) then FinalClose[1] else ExpansionStart[1];

#High/Low Pivot Initial Flags#
def HighPivotInitialFlag;
def LowPivotInitialFlag;
def HighClearCheck;
def LowClearCheck;
def InitialFlagCheck;

HighClearCheck = CompoundValue(1,if LowPivotInitialFlag[1] then PivotHigh[1] else if PivotLow > HighClearCheck[1] then 0 else HighClearCheck[1],0);
LowClearCheck = CompoundValue(1,if HighPivotInitialFlag[1] then PivotLow[1] else if PivotHigh < LowClearCheck[1] then 0 else LowClearCheck[1],0);
HighPivotInitialFlag = PivotHigh > PivotHigh[1] and PivotHigh >= PivotHigh[-1] and !HighClearCheck;
LowPivotInitialFlag = PivotLow < PivotLow[1] and PivotLow <= PivotLow[-1] and !LowClearCheck;
InitialFlagCheck = if HighPivotInitialFlag then 1 else if LowPivotInitialFlag then 0 else InitialFlagCheck[1];

#High/Low Pivot Secondary Flags#
def SecondaryHighPivotFlag;
def SecondaryLowPivotFlag;
def SecondayFlagCheck;

SecondaryHighPivotFlag = if HighPivotInitialFlag == 1 and !InitialFlagCheck[1] then fold hpf = 0 to VBar - Bar with inthpf = PivotHigh while GetValue(LowPivotInitialFlag, -hpf) == 0 or (GetValue(LowPivotInitialFlag, -hpf) == 1 and GetValue(HighPivotInitialFlag, -hpf) == 1) do if GetValue(PivotHigh, -hpf) > inthpf then GetValue(PivotHigh, -hpf) else inthpf else SecondaryHighPivotFlag[1];
SecondaryLowPivotFlag = if LowPivotInitialFlag == 1 and InitialFlagCheck[1] then fold lpf = 0 to VBar - Bar with intlpf = PivotLow while GetValue(HighPivotInitialFlag, -lpf) == 0 or (GetValue(LowPivotInitialFlag, -lpf) == 1 and GetValue(HighPivotInitialFlag, -lpf) == 1) do if GetValue(PivotLow, -lpf) < intlpf then GetValue(PivotLow, -lpf) else intlpf else SecondaryLowPivotFlag[1];
SecondayFlagCheck = if PivotHigh == SecondaryHighPivotFlag and HighPivotInitialFlag then 1 else if PivotLow == SecondaryLowPivotFlag and LowPivotInitialFlag then 0 else SecondayFlagCheck[1];

#High/Low Pivot Final Flag/Pivot Value#
def HighPivot;
def LowPivot;
def PivotValue;

HighPivot = PivotHigh == SecondaryHighPivotFlag and HighPivotInitialFlag and !SecondayFlagCheck[1];
LowPivot = PivotLow == SecondaryLowPivotFlag and LowPivotInitialFlag and SecondayFlagCheck[1];
PivotValue = if HighPivot then PivotHigh else if LowPivot then PivotLow else 0;

#Last Pivot Check#
def LastPivot = if HighPivot or LowPivot then fold lp = 0 to VBar - Bar with intlp while !IsNaN(GetValue(PivotClose, -lp)) do if GetValue(HighPivot, -lp) or GetValue(LowPivot, -lp) then intlp + 1 else intlp else 0;

#Count Forward and Backwards Bars to next opposite pivot#
def HighForwardCount = fold hfc = 0 to VBar - Bar with inthfc while GetValue(LowPivot, -hfc) == 0 do inthfc + 1;
def HighBackwardCount = fold hbc = 0 to Bar with inthbc while GetValue(LowPivot, hbc) == 0 do inthbc + 1;
def LowForwardCount = fold lfc = 0 to VBar - Bar with intlfc while GetValue(HighPivot, -lfc) == 0 do intlfc + 1;
def LowBackwardCount = fold lbc = 0 to Bar with intlbc while GetValue(HighPivot, lbc) == 0 do intlbc + 1;

#Initial PivotPoints Strength#
def HighPivotStrength = if HighForwardCount < 3 or HighBackwardCount < 3 then 0 else if HighForwardCount < HighBackwardCount then HighForwardCount else HighBackwardCount;
def LowPivotStrength = if LowForwardCount < 3 or LowBackwardCount < 3 then 0 else if LowForwardCount < LowBackwardCount then LowForwardCount else LowBackwardCount;

#Price Height#
def HighPivotForwardPriceHeight = if HighPivot then PivotHigh - fold hpfph = 0 to VBar - Bar with inthpfph = PivotLow while GetValue(PivotHigh, -hpfph) <= PivotValue do if GetValue(PivotLow, -hpfph) < inthpfph then GetValue(PivotLow, -hpfph) else inthpfph else 0;
def HighPivotBackwardPriceHeight = if HighPivot then PivotHigh - fold hpbph = 0 to Bar with inthpbph = PivotLow while GetValue(PivotHigh, hpbph) <= PivotValue do if GetValue(PivotLow, hpbph) < inthpbph then GetValue(PivotLow, hpbph) else inthpbph else 0;
def HighPivotPriceHeight = if HighPivotForwardPriceHeight < HighPivotBackwardPriceHeight then HighPivotForwardPriceHeight else HighPivotBackwardPriceHeight;

def LowPivotForwardPriceHeight = if LowPivot then (fold lpfph = 0 to VBar - Bar with intlpfph = PivotHigh while GetValue(PivotLow, -lpfph) >= PivotValue do if GetValue(PivotHigh, -lpfph) > intlpfph then GetValue(PivotHigh, -lpfph) else intlpfph) - PivotLow else 0;
def LowPivotBackwardPriceHeight = if LowPivot then (fold lpbph = 0 to Bar with intlpbph = PivotHigh while GetValue(PivotLow, lpbph) >= PivotValue do if GetValue(PivotHigh, lpbph) > intlpbph then GetValue(PivotHigh, lpbph) else intlpbph) - PivotLow else 0;
def LowPivotPriceHeight = if LowPivotForwardPriceHeight < LowPivotBackwardPriceHeight then LowPivotForwardPriceHeight else LowPivotBackwardPriceHeight;

#Count Bars until Crossed#
def HighPivotCross = if HighPivot then fold hpc = 0 to VBar - Bar with inthpc while GetValue(PivotHigh, -hpc - 1) <= PivotValue do if IsNaN(GetValue(PivotClose, -hpc - 2)) then 0 else inthpc + 1 else Double.NaN;
def LowPivotCross = if LowPivot then fold lpc = 0 to VBar - Bar with intlpc while GetValue(PivotLow, -lpc - 1) >= PivotValue do if IsNaN(GetValue(PivotClose, -lpc - 2)) then 0 else intlpc + 1 else Double.NaN;

#Decrease Pivot Strength After Cross#
def HighPivotResistanceStrength = if HighPivot then fold hprs = 0 to VBar - Bar with inthprs = HighPivotStrength / 2 while !IsNaN(GetValue(PivotClose, -hprs - 1)) and inthprs > 0 do if hprs > HighPivotCross and HighPivotCross and GetValue(PivotLow, -hprs) > PivotValue then inthprs - .5 else if GetValue(PivotHigh, -hprs) > PivotValue and GetValue(PivotLow, -hprs) < PivotValue then inthprs - (((GetValue(PivotHigh, -hprs) - PivotValue) / (GetValue(PivotHigh, -hprs) - GetValue(PivotLow, -hprs))) * .5) else inthprs else 0;
def FinalHighPivotResistanceStrength = if HighPivotResistanceStrength <= 0 then 0 else HighPivotResistanceStrength;

def HighPivotSupportStrength = if HighPivot then fold hpss = 0 to VBar - Bar with inthpss = HighPivotStrength / 2 while HighPivotResistanceStrength <= 0 and !IsNaN(GetValue(PivotClose, -hpss - 1)) and inthpss > 0 do if hpss > HighPivot and HighPivotCross and GetValue(PivotHigh, -hpss) < PivotValue then inthpss - .5 else if GetValue(PivotHigh, -hpss) > PivotValue and GetValue(PivotLow, -hpss) < PivotValue then inthpss - ((PivotValue - (GetValue(PivotLow, -hpss)) / (GetValue(PivotHigh, -hpss) - GetValue(PivotLow, -hpss))) * .5) else inthpss else 0;
def FinalHighPivotSupportStrength = if HighPivotSupportStrength <= 0 then 0 else HighPivotSupportStrength;

def LowPivotSupportStrength = if LowPivot then fold lpss = 0 to VBar - Bar with intlpss = LowPivotStrength / 2 while !IsNaN(GetValue(PivotClose, -lpss - 1)) and intlpss > 0 do if lpss > LowPivotCross and LowPivotCross and GetValue(PivotHigh, -lpss) < PivotValue then intlpss - .5 else if GetValue(PivotLow, -lpss) < PivotValue and GetValue(PivotHigh, -lpss) > PivotValue then intlpss - (((PivotValue - GetValue(PivotLow, -lpss)) / (GetValue(PivotHigh, -lpss) - GetValue(PivotLow, -lpss))) * .5) else intlpss else 0;
def FinalLowPivotSupportStrength = if LowPivotSupportStrength <= 0 then 0 else LowPivotSupportStrength;

def LowPivotResistanceStrength = if LowPivot then fold lprs = 0 to VBar - Bar with intlprs = LowPivotStrength / 2 while LowPivotSupportStrength <= 0 and !IsNaN(GetValue(PivotClose, -lprs - 1)) and intlprs > 0 do if lprs > LowPivotCross and LowPivotCross and GetValue(PivotLow, -lprs) > PivotValue then intlprs - .5 else if GetValue(PivotLow, -lprs) < PivotValue and GetValue(PivotHigh, -lprs) > PivotValue then intlprs - (((GetValue(PivotHigh, -lprs) - PivotValue) / (GetValue(PivotHigh, -lprs) - GetValue(PivotLow, -lprs))) * .5) else intlprs else 0;
def FinalLowPivotResistanceStrength = if LowPivotResistanceStrength <= 0 then 0 else LowPivotResistanceStrength;

def HighPivotTotalStrength = FinalHighPivotResistanceStrength + FinalHighPivotSupportStrength;
def LowPivotTotalStrength = FinalLowPivotResistanceStrength + FinalLowPivotSupportStrength;

plot Pivots = if HighPivot then PivotHigh else if LowPivot then PivotLow else Double.NaN;
Pivots.EnableApproximation();

AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "High Pivot\n" + PivotValue, Color.WHITE, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Low Pivot\n" + PivotValue, Color.WHITE, no);
AddChartBubble(HighPivot and !HighPivotCross and Show_Bubbles, PivotHigh, "Not Crossed", Color.WHITE, yes);
AddChartBubble(LowPivot and !LowPivotCross and Show_Bubbles, PivotLow, "Not Crossed", Color.WHITE, no);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Price Height " + HighPivotPriceHeight, Color.WHITE, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Price Height " + LowPivotPriceHeight, Color.WHITE, no);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Resistance Strength " + FinalHighPivotResistanceStrength, if HighPivotResistanceStrength <= 0 then Color.LIGHT_RED else if HighPivotResistanceStrength < HighPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, yes);
AddChartBubble(HighPivot and Show_Bubbles, PivotHigh, "Support Strength " + FinalHighPivotSupportStrength, if HighPivotSupportStrength <= 0 then Color.LIGHT_RED else if HighPivotSupportStrength < HighPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, yes);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Resistance Strength " + FinalLowPivotResistanceStrength, if LowPivotResistanceStrength <= 0 then Color.LIGHT_RED else if LowPivotResistanceStrength < LowPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, no);
AddChartBubble(LowPivot and Show_Bubbles, PivotLow, "Support Strength " + FinalLowPivotSupportStrength, if LowPivotSupportStrength <= 0 then Color.LIGHT_RED else if LowPivotSupportStrength < LowPivotStrength / 2 then Color.YELLOW else Color.LIGHT_GREEN, no);
@Svanoy, Hi bro, may I check if this script does not support when the extension hour is on, right?
 
Last edited by a moderator:
@Intrinsic Knowledge
It does work with extension on.
Make sure the study's input aggregation is equal to or higher than your chart aggregation.
If your getting an error, check for a question mark icon in the upper left of the chart.
Click on it to see what the error is.

May be a 'to many iterations' error. If so, shorten the total amount of bars on the chart.
 
I understand. Is this original or your adaptation of an original work? I have not gone over it in detail as yet.
@TNTrader5159 It is an original work of mine.
Very nice work! I tried changing the minimum size for the pivots from 3 to 1 in your #Initial PivotPoints Strength# sector, yet it did not take those into account when plotting. Also if a pivot with bar strength of 3 or more gets eclipsed in height by a pivot that could be as little as one bar, that should be factored in as a height premium when it's time to compare it with the Thrust Factor of a pattern. I would say the minimum pivot bar value of 3 should be changed to 1 because of that possibility, even though it would make for a rather messy display if the connecting lines are drawn. If a pattern with a Thrust Factor of 3 is say 50 points in height and an impeding pivot with a bar strength of just 1 has a height of 150 (as can happen in volatile market conditions), that would multiply its bar strength by 3 (150 / 50) and stop a move launched by the pattern with the Thrust Factor of 3 that's 50 points in height. I will insert an image shortly as an example...
 
@TNTrader5159 the plots are defined by the rules stated earlier of, (in the example of a high pivot) a lower high on each side and at least one bar on each side that has a high that completely clears the low of the pivot bar. This results in the amount of bars between pivots being self defined by price action and subsequently be dynamic from pivot to pivot.
 
Last edited:
@TNTrader5159 the plots are defined by the rules stated earlier of, (in the example of a high pivot) a lower high on each side and at least one bar on each side that has a high that completely clears the low of the pivot bar. This results in the amount of bars between pivots being self defined by price action and subsequently be dynamic from pivot to pivot.
I'm unable to get images to post as per the instructions I've been given. The error message states, "Image cannot be loaded from the passed link."
<p>
In reply to your most recent post, I was not aware of the requirement for one or more bars on each side of, in this example, a high pivot to have a high completely clearing the low of the high pivot bar. I'll have to think on that. I'm thinking it won't be necessary to institute that rule but want to look more closely to make sure.
<p>
I see the pivots in flux are highlighted in yellow, the ones at full original strength are in green, and the ones gone off the board are in red, the theme of a traffic light. Nice touch.
<p>
I'm thinking you must be a Taurus to have a writing style so similar to my own. And I know myself well enough to admit I could be way off in that conjecture!
 
I'm unable to get images to post as per the instructions I've been given. The error message states, "Image cannot be loaded from the passed link."
Sounds like you do not have the correct instructions on how to copy & paste. It is not possible to get an error when one cuts & pastes.

There is nothing in the directions about clicking on "insert" or "link" or "load"
Please see the instructions:
https://usethinkscript.com/threads/how-to-insert-image-in-a-post-thread.277/page-4#post-109897
 
@TNTrader5159 the plots are defined by the rules stated earlier of, (in the example of a high pivot) a lower high on each side and at least one bar on each side that has a high that completely clears the low of the pivot bar. This results in the amount of bars between pivots being self defined by price action and subsequently be dynamic from pivot to pivot.
Can you now get the script to draw horizontal lines extending from the active pivot points to the present and remove the bubbles for those pivots that have been taken "off the board" in both directions with maybe a yellow painted bar or an x above/below them to indicate that?
<p>
Could those horizontal lines have a thickness or opacity that increases with strength?
<p>
Can a small text of the pivot price appear along each of those active pivot lines in lieu of the bubbles?
<p>
Are the bubbles and text inside them scalable either automatically or manually so as not to take up so much screen room when many bars are displayed on a chart?
<p>
Can the pivot bars could be colored say green for a low pivot and red for a high pivot?
<p>
Also, can you make drawing the "zig-zag" lines optional as an input? Thanks!
 
Can you now get the script to draw horizontal lines extending from the active pivot points to the present and remove the bubbles for those pivots that have been taken "off the board" in both directions with maybe a yellow painted bar or an x above/below them to indicate that?
<p>
Could those horizontal lines have a thickness or opacity that increases with strength?
<p>
Can a small text of the pivot price appear along each of those active pivot lines in lieu of the bubbles?
<p>
Are the bubbles and text inside them scalable either automatically or manually so as not to take up so much screen room when many bars are displayed on a chart?
<p>
Can the pivot bars could be colored say green for a low pivot and red for a high pivot?
<p>
Also, can you make drawing the "zig-zag" lines optional as an input? Thanks!
Here is the logic behind the Price Density Index (PDI):

Look back from the current price or any price through all bars on the chart for bars containing that price and call each one that does a match.

Starting at the first match, however many bars back it is, start a running total of matches divided by number of bars looked at then multiply that by the number of matches. The formula is (matches / total_bars) * matches.

EXAMPLES:

The first match would of course be (1 / 1) * 1 for a running PDI of 1.

If the next bar back is a match, you have a running total of 2. If it's not, you have (1 / 2) * 1 or 0.5 as your new running total score (PDI).

If the first 2 bars match and the next 3 do not, you have (2 / 5) * 2 or 0.8 as a running total PDI.

If the first 7 bars match and the next 3 do not, you have (7 / 10) * 7 = 4.9 as the PDI.

After all calculations are made in looking back one bar at a time, starting with the first match, back to the beginning of all loaded bars, take the highest reading of all those as the final PDI for that price level.

That number is then compared with the Thrust Factor of a pattern, taking readings at every price level within favorable movement of a triggered trade. Barring another exit signal from a pivot or stop (more on those later), exit the trade at the first PDI bigger than the Thrust Factor (looking downward in a Short trade or upward in a Long trade) with an MIT (Market if Touched) order at that level.

These readings would all be defined and kept invisible except for the one that would stop a trade, and that would be depicted by a horizontal line at that level and some text to indicate the strength and price and perhaps the projected gross profit amount from the theoretical POE (Point of Entry) at that level.

If a trade were underway, it could calculate projected profit from the actual entry point, though I don't think TOS facilitates anything this automated. Am I wrong? I would hope so, as TD needs to move up to full automation capability. Otherwise I have a TradeStation account ready and waiting and someone who will convert the ThinkScript to EasyLanguage. I like ThinkScript better, but what do I know?!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
385 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