feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
2026-03-09 13:45:46 -07:00
|
|
|
// Licensed under the Apache License, Version 2.0
|
2026-01-31 14:05:53 -08:00
|
|
|
// © mihakralj
|
|
|
|
|
//@version=6
|
|
|
|
|
indicator("Median Absolute Error", "MdAE", overlay=false)
|
|
|
|
|
|
|
|
|
|
//@function Calculates Median Absolute Error
|
|
|
|
|
//@param actual Series of actual values
|
|
|
|
|
//@param predicted Series of predicted/forecast values
|
|
|
|
|
//@param length Rolling window for median calculation
|
|
|
|
|
//@returns MdAE value
|
|
|
|
|
mdae(series float actual, series float predicted, simple int length) =>
|
|
|
|
|
// Compute absolute error for current bar
|
|
|
|
|
float absError = math.abs(nz(actual, 0.0) - nz(predicted, 0.0))
|
|
|
|
|
|
|
|
|
|
// Use ta.median for rolling median of absolute errors
|
|
|
|
|
float result = ta.median(absError, length)
|
|
|
|
|
result
|
|
|
|
|
|
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
i_length = input.int(14, "Length", minval=1)
|
|
|
|
|
i_actual = input.source(close, "Actual")
|
|
|
|
|
i_predicted = input.source(open, "Predicted")
|
|
|
|
|
|
|
|
|
|
// Calculation
|
|
|
|
|
mdae_value = mdae(i_actual, i_predicted, i_length)
|
|
|
|
|
|
|
|
|
|
// Plot
|
|
|
|
|
plot(mdae_value, "MdAE", color=color.yellow, linewidth=2)
|
2026-02-18 11:55:48 -08:00
|
|
|
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
|