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-18 19:02:03 -08:00
|
|
|
// © mihakralj
|
|
|
|
|
//@version=6
|
|
|
|
|
indicator("Percentage Change (CHANGE)", "CHANGE", overlay=false, format=format.percent)
|
|
|
|
|
|
|
|
|
|
//@function Calculates the percentage change of a source series over a specified length using the history referencing operator for efficiency.
|
|
|
|
|
//@param source The source series (e.g. close price).
|
|
|
|
|
//@param length The lookback period (number of bars). Must be > 0.
|
|
|
|
|
//@returns float The percentage change over the specified length. Returns `na` if the historical value is `na` or zero.
|
|
|
|
|
//@optimized Uses direct history access `source[length]` instead of array manipulation.
|
|
|
|
|
change(float source, int length) =>
|
|
|
|
|
if length <= 0
|
|
|
|
|
runtime.error("Length must be greater than 0")
|
|
|
|
|
float oldValue = source[length]
|
|
|
|
|
if na(oldValue) or oldValue == 0
|
|
|
|
|
na
|
|
|
|
|
else
|
|
|
|
|
(source / oldValue - 1) // Already a percentage, Pine handles plotting format
|
|
|
|
|
|
|
|
|
|
// ---------- Main loop ----------
|
|
|
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
i_source = input.source(close, "Source")
|
|
|
|
|
i_length = input.int(1, "Length", minval = 1)
|
|
|
|
|
|
|
|
|
|
// Calculation
|
|
|
|
|
result = change(i_source, i_length)
|
|
|
|
|
|
|
|
|
|
// Plot
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
plot(result, "Change %", color=color.yellow, linewidth=2)
|