mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 22:08:05 +00:00
Remove multiple Pine Script indicators: SSFDSP, STARCHANNEL, STBANDS, STC, UBANDS, UCHANNEL, VWAPBANDS, and VWAPSD. These indicators were deleted to streamline the library and remove unused or redundant code.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
|
||||
//@version=6
|
||||
indicator("MEDF - Moving Median Filter", "MEDF", overlay=true)
|
||||
|
||||
// ── Functions ──────────────────────────────────────────────────────────
|
||||
// @function Calculates the Moving Median Filter over a sliding window.
|
||||
// A nonlinear filter that outputs the median of the last N values.
|
||||
// Robust to impulse noise and outliers while preserving edges/steps
|
||||
// better than any linear filter (SMA, EMA, etc.).
|
||||
// Uses circular buffer + insertion sort for O(N log N) per bar.
|
||||
// @param source Series to filter
|
||||
// @param period Window size (must be > 0)
|
||||
// @returns Median-filtered value, valid from bar 1
|
||||
export medf(series float source, simple int period) =>
|
||||
if period <= 0
|
||||
runtime.error("Period must be greater than 0")
|
||||
|
||||
float src = nz(source)
|
||||
|
||||
var array<float> buffer = array.new_float(period, 0.0)
|
||||
var int head = 0
|
||||
var int count = 0
|
||||
|
||||
array.set(buffer, head, src)
|
||||
head := (head + 1) % period
|
||||
if count < period
|
||||
count += 1
|
||||
|
||||
var array<float> sorted = array.new_float(0)
|
||||
array.clear(sorted)
|
||||
for i = 0 to count - 1
|
||||
array.push(sorted, array.get(buffer, i))
|
||||
array.sort(sorted)
|
||||
|
||||
int n = array.size(sorted)
|
||||
float result = 0.0
|
||||
if n % 2 == 1
|
||||
result := array.get(sorted, n / 2)
|
||||
else
|
||||
float mid1 = array.get(sorted, n / 2 - 1)
|
||||
float mid2 = array.get(sorted, n / 2)
|
||||
result := (mid1 + mid2) / 2.0
|
||||
result
|
||||
|
||||
// ── Inputs ─────────────────────────────────────────────────────────────
|
||||
int i_period = input.int(5, "Period", minval=1)
|
||||
string i_source = input.source(close, "Source")
|
||||
|
||||
// ── Calculation ────────────────────────────────────────────────────────
|
||||
float value = medf(i_source, i_period)
|
||||
|
||||
// ── Plot ───────────────────────────────────────────────────────────────
|
||||
plot(value, "MEDF", color.yellow, 2)
|
||||
Reference in New Issue
Block a user