mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 05:28:05 +00:00
pine files
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// The MIT License (MIT)
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Mean Arctangent Absolute Percentage Error", "MAAPE", overlay=false, format=format.percent)
|
||||
|
||||
//@function Calculates Mean Arctangent Absolute Percentage Error
|
||||
//@doc Uses arctangent to bound error between 0 and π/2, robust to outliers.
|
||||
//@doc Handles zero actual values gracefully (approaches π/2).
|
||||
//@param actual Series of actual values
|
||||
//@param predicted Series of predicted/forecast values
|
||||
//@param length Rolling window for averaging
|
||||
//@returns MAAPE value (0 to ~1.5708)
|
||||
maape(series float actual, series float predicted, simple int length) =>
|
||||
float epsilon = 1e-10
|
||||
|
||||
// Compute arctangent percentage error for current bar
|
||||
float absActual = math.abs(nz(actual, 0.0))
|
||||
float absError = math.abs(nz(actual, 0.0) - nz(predicted, 0.0))
|
||||
float atanError = absActual > epsilon ? math.atan(absError / absActual) : math.pi / 2.0
|
||||
|
||||
// Rolling mean of arctangent errors
|
||||
float result = ta.sma(atanError, 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
|
||||
maape_value = maape(i_actual, i_predicted, i_length)
|
||||
|
||||
// Plot
|
||||
plot(maape_value, "MAAPE", color=color.yellow, linewidth=2)
|
||||
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
|
||||
hline(math.pi / 2.0, "Max (π/2)", color=color.red, linestyle=hline.style_dotted)
|
||||
Reference in New Issue
Block a user