lastguru

NormalizedOscillators

lastguru 已更新   
Library "NormalizedOscillators"
Collection of some common Oscillators. All are zero-mean and normalized to fit in the -1..1 range. Some are modified, so that the internal smoothing function could be configurable (for example, to enable Hann Windowing, that John F. Ehlers uses frequently). Some are modified for other reasons (see comments in the code), but never without a reason. This collection is neither encyclopaedic, nor reference, however I try to find the most correct implementation. Suggestions are welcome.

rsi2(upper, lower) RSI - second step
  Parameters:
    upper: Upwards momentum
    lower: Downwards momentum
  Returns: Oscillator value
Modified by Ehlers from Wilder's implementation to have a zero mean (oscillator from -1 to +1)
Originally: 100.0 - (100.0 / (1.0 + upper / lower))
Ignoring the 100 scale factor, we get: upper / (upper + lower)
Multiplying by two and subtracting 1, we get: (2 * upper) / (upper + lower) - 1 = (upper - lower) / (upper + lower)

rms(src, len) Root mean square (RMS)
  Parameters:
    src: Source series
    len: Lookback period
Based on by John F. Ehlers implementation

ift(src) Inverse Fisher Transform
  Parameters:
    src: Source series
  Returns: Normalized series
Based on by John F. Ehlers implementation
The input values have been multiplied by 2 (was "2*src", now "4*src") to force expansion - not compression
The inputs may be further modified, if needed

stoch(src, len) Stochastic
  Parameters:
    src: Source series
    len: Lookback period
  Returns: Oscillator series

ssstoch(src, len) Super Smooth Stochastic (part of MESA Stochastic) by John F. Ehlers
  Parameters:
    src: Source series
    len: Lookback period
  Returns: Oscillator series
Introduced in the January 2014 issue of Stocks and Commodities
This is not an implementation of MESA Stochastic, as it is based on Highpass filter not present in the function (but you can construct it)
This implementation is scaled by 0.95, so that Super Smoother does not exceed 1/-1
I do not know, if this the right way to fix this issue, but it works for now

netKendall(src, len) Noise Elimination Technology by John F. Ehlers
  Parameters:
    src: Source series
    len: Lookback period
  Returns: Oscillator series
Introduced in the December 2020 issue of Stocks and Commodities
Uses simplified Kendall correlation algorithm
Implementation by @QuantTherapy:
rsi(src, len, smooth) RSI
  Parameters:
    src: Source series
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series

vrsi(src, len, smooth) Volume-scaled RSI
  Parameters:
    src: Source series
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
This is my own version of RSI. It scales price movements by the proportion of RMS of volume

mrsi(src, len, smooth) Momentum RSI
  Parameters:
    src: Source series
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
Inspired by RocketRSI by John F. Ehlers (Stocks and Commodities, May 2018)

rrsi(src, len, smooth) Rocket RSI
  Parameters:
    src: Source series
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
Inspired by RocketRSI by John F. Ehlers (Stocks and Commodities, May 2018)
Does not include Fisher Transform of the original implementation, as the output must be normalized
Does not include momentum smoothing length configuration, so always assumes half the lookback length

mfi(src, len, smooth) Money Flow Index
  Parameters:
    src: Source series
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series

lrsi(src, in_gamma, len) Laguerre RSI by John F. Ehlers
  Parameters:
    src: Source series
    in_gamma: Damping factor (default is -1 to generate from len)
    len: Lookback period (alternatively, if gamma is not set)
  Returns: Oscillator series
The original implementation is with gamma. As it is impossible to collect gamma in my system, where the only user input is length,
an alternative calculation is included, where gamma is set by dividing len by 30. Maybe different calculation would be better?

fe(len) Choppiness Index or Fractal Energy
  Parameters:
    len: Lookback period
  Returns: Oscillator series
The Choppiness Index (CHOP) was created by E. W. Dreiss
This indicator is sometimes called Fractal Energy

er(src, len) Efficiency ratio
  Parameters:
    src: Source series
    len: Lookback period
  Returns: Oscillator series
Based on Kaufman Adaptive Moving Average calculation
This is the correct Efficiency ratio calculation, and most other implementations are wrong:
the number of bar differences is 1 less than the length, otherwise we are adding the change outside of the measured range!
For reference, see Stocks and Commodities June 1995

dmi(len, smooth) Directional Movement Index
  Parameters:
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
Based on the original Tradingview algorithm
Modified with inspiration from John F. Ehlers DMH (but not implementing the DMH algorithm!)
Only ADX is returned
Rescaled to fit -1 to +1
Unlike most oscillators, there is no src parameter as DMI works directly with high and low values

fdmi(len, smooth) Fast Directional Movement Index
  Parameters:
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
Same as DMI, but without secondary smoothing. Can be smoothed later. Instead, +DM and -DM smoothing can be configured

doOsc(type, src, len, smooth) Execute a particular Oscillator from the list
  Parameters:
    type: Oscillator type to use
    src: Source series
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
Chande Momentum Oscillator (CMO) is RSI without smoothing. No idea, why some authors use different calculations
LRSI with Fractal Energy is a combo oscillator that uses Fractal Energy to tune LRSI gamma, as seen here: www.prorealcode.com/...mma-fractals-energy/

doPostfilter(type, src, len) Execute a particular Oscillator Postfilter from the list
  Parameters:
    type: Oscillator type to use
    src: Source series
    len: Lookback period
  Returns: Oscillator series
發布通知:
v2 - Added:
momentum(src, len) Momentum
  Parameters:
    src: Source series
    len: Lookback period
  Returns: Oscillator series
Derivative of the oscillator series with IFT normalization to force the -1..1 range
發布通知:
v3 Added:
avx(len, smooth) Average Vortex Index (AVX)
  Parameters:
    len: Lookback period
    smooth: Internal smoothing algorithm
  Returns: Oscillator series
Based on the Vortex Indicator. I then apply ADX calculation on the VI+ and VI- lines.
Only AVX is returned
Rescaled to fit -1 to +1
Unlike most oscillators, there is no src parameter as AVX works directly with high and low values
發布通知:
v4 Added "Fast Default" internal smoothing algorithm: same as Default, but with half the length
發布通知:
v5 Added:
hurst(src, len) Hurst Exponent
  Parameters:
    src: Source series
    len: Lookback period
  Returns: Oscillator series
Until I can write my own, I use the @nolantait library: Which in turn is based on the excellent @balipour implementation: As with all other indicators, this is also rescaled to fit -1 to +1
發布通知:
v6 Added:
fd(len) Simple Fractal Dimension
  Parameters:
    len: Reference lookback length
  Returns: Oscillator series
Based on FRAMA by John F. Ehlers
This function implements just the first part of FRAMA: calculating Fractal Dimension
It is then transformed to Hurst Exponent (HE = 2 - FD) and normalized to fit -1 to +1
發布通知:
v7 Added:
fve(len) Finite Volume Element (FVE)
  Parameters:
    len: Lookback period
  Returns: Oscillator series
Based on FVE with Volatility adjustment by Markos Katsanos (Stocks and Commodities, September 2003)
發布通知:
v8 Added:
vfi(len) Volume Flow Indicator (VFI)
  Parameters:
    len: Lookback period
  Returns: Oscillator series
Based on VFI by Markos Katsanos (Stocks and Commodities, June 2004)
mkatsanos.com/volume...-flow-vfi-indicator/
As with all other indicators, this is also rescaled to fit -1 to +1
發布通知:
v9 Added:
rvi(len) Relative Vigor Index by John F. Ehlers
  Parameters:
    len: Lookback period
  Returns: Oscillator series
Introduced in the January 2002 issue of Stocks and Commodities
Similar to A/D Oscillator

Tips in TradingView Coins are appreciated
Pine腳本庫

本著真正的TradingView精神,作者將此Pine代碼以開源腳本庫發布,以便我們社群的其他Pine程式設計師可以重用它。向作者致敬!您可以私下或在其他開源出版物中使用此庫,但在出版物中重用此代碼受網站規則約束。

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。

想使用這個腳本庫嗎?

複製以下行並將其黏貼到您的腳本中。