allow x quantity of false conditions to exist in a series of true's
find a quantity of previous bars where,
the current close price,
crosses over a consecutive sequence of previous bars,
(current close < a prev high and current close > a prev low)
and is allowed to miss x bars.
every bar has a quantity in a bubble, of how many previous bars.
for verifying, can choose an offset, from the last bar
draws a blue dot above that bar, and a purple vertical line is before it.
the yellow bubble under the bar, shows 8, 8 bars before this one that meet the conditions
follow the lime line, and count the bars that cross it , and count 3 more bars that don't cross it.
i started with this, a conversion of the pine function , valuewhen()
https://usethinkscript.com/threads/...tos-script-not-pine-studies.11424/#post-99310
find a quantity of previous bars where,
the current close price,
crosses over a consecutive sequence of previous bars,
(current close < a prev high and current close > a prev low)
and is allowed to miss x bars.
Ruby:
# prev_price_crossings_x_skips_01
# allow x quantity of false conditions to exist in a series of true's
# find a quantity of previous bars where,
# the current close price,
# crosses over a consecutive sequence of previous bars,
# (current close < a prev high and current close > a prev low)
# and is allowed to miss x bars.
#-------------------------------
def bn = BarNumber();
def na = Double.NaN;
input allowed_misses = 3;
AddLabel(1, "allowed non crossings " + allowed_misses, Color.YELLOW);
def maxnum = 200;
def n = allowed_misses;
def prev_cnt = fold j = 0 to maxnum
with p
while p <= n
do p + ( if p == n then j - (n+1) else
# if a condition is false then +1 , a miss
if (close <= getvalue(high, j) and close >= getvalue(low, j))
then 0 else 1 );
#------------------------------------
#------------------------------------
# test stuff
#------------------------------------
# draw a horz line at some close level, to visually look for prev bar crossings
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
input show_line_at_last_close = yes;
input last_bar_offset = 5;
def barsBack = 1000;
def x = !IsNaN(close[-last_bar_offset]) and IsNaN(close[-(1+last_bar_offset)]);
#def c = if !IsNaN(close[-last_offset]) and IsNaN(close[-(1+last_offset)])
def c = if x
then close
else c[1];
plot line = if show_line_at_last_close and isNaN(close[-barsBack])
then c[-barsBack]
else Double.NaN;
line.SetLineWeight(1);
line.SetDefaultColor(Color.LIME);
line.SetStyle(Curve.MEDIUM_DASH);
plot y = if show_line_at_last_close and x then high*1.0004 else na;
y.SetPaintingStrategy(PaintingStrategy.POINTS);
y.SetDefaultColor(Color.cyan);
y.setlineweight(3);
y.hidebubble();
input test3_vertical_lines = yes;
addverticalline(test3_vertical_lines and x, "-", color.magenta);
#------------------------------------
# bubble with quantity of prev bars, that have true conditions, but only up to x false bars
def min_qty = 2;
input test2 = yes;
addchartbubble(test2 and (prev_cnt >= min_qty), low*0.999,
#bn + "\n" +
prev_cnt + "\n"
, Color.YELLOW, no);
#------------------------------------
#
#
every bar has a quantity in a bubble, of how many previous bars.
for verifying, can choose an offset, from the last bar
draws a blue dot above that bar, and a purple vertical line is before it.
the yellow bubble under the bar, shows 8, 8 bars before this one that meet the conditions
follow the lime line, and count the bars that cross it , and count 3 more bars that don't cross it.
i started with this, a conversion of the pine function , valuewhen()
https://usethinkscript.com/threads/...tos-script-not-pine-studies.11424/#post-99310
Last edited: