Files
QuanTAlib/lib/numerics/normalize/normalize.pine
T
Miha Kralj 24e86d762a Add documentation links for various volatility indicators and channels
- 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.
2026-02-18 11:55:48 -08:00

38 lines
1.4 KiB
Plaintext

// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Min-Max Normalization (NORMALIZE)", "NORMALIZE", overlay=false, precision=6)
//@function Normalizes a source series to the fixed range [0, 1] using Min-Max scaling over a lookback period.
//@param src The source series to normalize.
//@param len The lookback period to determine min and max values. Must be >= 1.
//@returns The normalized series (scaled to [0, 1]).
normalize(series float src, simple int len) =>
float min_val_in_period = src
float max_val_in_period = src
for i = 1 to len - 1
current_val = src[i]
if na(current_val)
continue
if current_val < min_val_in_period
min_val_in_period := current_val
if current_val > max_val_in_period
max_val_in_period := current_val
range_val = max_val_in_period - min_val_in_period
normalized_value = 0.0
if range_val != 0.0 and not na(range_val)
normalized_value := (src - min_val_in_period) / range_val
normalized_value
// ---------- Main loop ----------
// Inputs
i_source = input.source(close, "Source")
i_length = input.int(200, "Lookback Length", minval=1, tooltip="Lookback period for finding min/max. Must be >= 1.")
// Calculation
normalizedValue = normalize(i_source, i_length)
// Plot
plot(normalizedValue, "Normalized Value [0,1]", color=color.yellow, linewidth=2)