'Normalize over specific period in Pine
I've managed to get a normalisation function working. Unfortunately on some tickers the plot is changed to a too small scale thus smoothing it out too much.
It seems to be normalizing over the historic min and max. I'd like to only normalize over the values for the last year or 6 months.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
study("Stoch(R) RSI(O) Mom(G)")
// ————— When the scale of the signal to rescale is unknown (unbounded).
// Min/Max of signal to rescale is determined by its historical low/high.
normalize(_src, _min, _max) =>
// Normalizes series with unknown min/max using historical min/max.
// _src : series to rescale.
// _min, _min: min/max values of rescaled series.
var _historicMin = 10e10
var _historicMax = -10e10
_historicMin := min(nz(_src, _historicMin), _historicMin)
_historicMax := max(nz(_src, _historicMax), _historicMax)
_min + (_max - _min) * (_src - _historicMin) / max(_historicMax - _historicMin, 10e-10)
//RSI
RSI = rsi(close, 14)
plot(RSI, "RSI", color.red)
//Stoch
stoch = stoch(close, high, low, 14)
plot(stoch,"Stochastic", color.orange)
//Normalized Momentum
mom = mom(close, 10)
mom_norm = normalize(mom, 0, 100)
plot(mom_norm, "Momentum", color.green)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
