mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-04 20:17:43 +00:00
24e86d762a
- Updated BBWN, BBWP, CCV, CV, CVI, EWMA, GKV, HLV, HV, Jvolty, JVOLTYN, MASSI, NATR, RSV, RV, RVI, TR, UI, VOV, VR, YZV indicators with documentation links. - Added documentation links for Aberration, Acceleration Bands, Andrews' Pitchfork, Adaptive Price Zone, ATR Bands, Bollinger Bands, Center of Gravity, Donchian Channels, Decay Min-Max Channel, Detrended Synthetic Price, EACP, EBSW, HOMOD, Jurik Volatility Bands, Keltner Channel, MA Envelope, Min-Max Channel, Price Channel, Regression Channels, Standard Deviation Channel, Stoller Average Range Channel, Super Trend Bands, Ultimate Bands, Ultimate Channel, VWAP Bands, and VWAP with Standard Deviation Bands.
45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
// The MIT License (MIT)
|
|
// © mihakralj
|
|
//@version=6
|
|
indicator("Lowest Value (LOWEST)", "LOWEST", overlay=true)
|
|
|
|
//@function Lowest value over a specified period using a monotonic deque.
|
|
//@param src {series float} Source series.
|
|
//@param len {int} Lookback length. `len` > 0.
|
|
//@returns {series float} Lowest value of `src` for `len` bars back. Returns the lowest value seen so far during initial bars.
|
|
lowest(series float src, int len) =>
|
|
if len <= 0
|
|
runtime.error("Length must be greater than 0")
|
|
var deque = array.new_int(0)
|
|
var src_buffer = array.new_float(len, na)
|
|
var int current_index = 0
|
|
float current_val = nz(src)
|
|
array.set(src_buffer, current_index, current_val)
|
|
while array.size(deque) > 0 and array.get(deque, 0) <= bar_index - len
|
|
array.shift(deque)
|
|
while array.size(deque) > 0
|
|
int last_index_in_deque = array.get(deque, array.size(deque) - 1)
|
|
int buffer_lookup_index = last_index_in_deque % len
|
|
if array.get(src_buffer, buffer_lookup_index) >= current_val
|
|
array.pop(deque)
|
|
else
|
|
break
|
|
array.push(deque, bar_index)
|
|
int lowest_index = array.get(deque, 0)
|
|
int lowest_buffer_index = lowest_index % len
|
|
float result = array.get(src_buffer, lowest_buffer_index)
|
|
current_index := (current_index + 1) % len
|
|
result
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
// Inputs
|
|
i_period = input.int(14, "Period", minval=1) // Default period 14
|
|
i_source = input.source(close, "Source")
|
|
|
|
// Calculation
|
|
lowest_value = lowest(i_source, i_period)
|
|
|
|
// Plot
|
|
plot(lowest_value, "Lowest", color=color.yellow, linewidth=2)
|