e.g if n = 0 bars the function is only true when the condition is true on the current bar but not the bar immediately previous n + 1. If instead the function input is n > 0 bars, for the function to return true the condition must become true somewhere m within n history of bars, but false for m + 1, and any bar after m within n history forming a series of unbroken true conditions the function will also return true.
In this crude example where n = 4 for bars[3,2,1] the function would return true but if n = 2 no bars would be true because the condition first became true outside of n at bar[3]:
Code: Select all
bars: 76543210
cond: 00001110
Code: Select all
bars: 76543210
cond: 00001111
Code: Select all
f_confirmCond(_n) =>
for _i = 0 to _n
_i == _n ? cond[_i] and not cond[_i+1] : cond[_i]
f_confirmCond(_n) =>
for _i = 0 to _n
if (not cond[_i])
false
else
if (_i == _n)
cond[_i] and not cond[_i + 1]
else
cond[_i]
f_confirmCond(_n) =>
if (not cond[0])
false
else
for _i = 0 to _n
if (_i == _n and (cond[_i] and not cond[_i + 1]))
for _i = 0 to _n
true
f_confirmCond(_n) =>
_confirmCond = true
_j = 0
_found = false
for _i = _n to 0
if (_found == false and cond[_i] and not cond[_i+1])
_found := true
_confirmCond := _confirmCond and cond[_i] and (_found == false? not cond[_i+1] : true)