Let's say we want a function that returns true or false if a data type from pine is monotonic increase. How could this be done?
Let's say we want a function that returns true or false if a data type from pine is monotonic increase. How could this be done?
//@version=5
indicator("monotonic increase function", overlay = false)
n = input.int(5)
f_is_mon_inc(float[] _set) =>
bool _is_mon_inc = true
_size = array.size(_set)
if _size > 1
_maxval = array.max(_set)
_minval = array.min(_set)
_firstval = array.get(_set, _size - 1)
_lastval = array.get(_set, 0)
if _firstval == _minval and _lastval == _maxval
for i = _size - 2 to 0
_val_i = array.get(_set, i)
_val_prev = array.get(_set, i + 1)
if _val_i < _val_prev
_is_mon_inc := false
break
else
_is_mon_inc := false
_is_mon_inc
var float[] set = array.new_float()
array.unshift(set, close)
if array.size(set) > n
array.pop(set)
is_mon_inc = f_is_mon_inc(set)
plot(is_mon_inc ? 1 : 0)