PINE LIBRARY

MRScoringLibrary

142
Library "MRScoringLibrary"
Mean-reversion graduated scoring: z-score any indicator into -3 to +3 integer scale.

mrScore(src, lookback, alreadyZ, invert)
  Converts any continuous indicator value into a graduated
mean-reversion score from -3 (deep overbought) to +3 (deep oversold).
  Parameters:
    src (float): Raw indicator value (or z-score if alreadyZ=true)
    lookback (int): Rolling lookback for z-score calc (ignored if alreadyZ=true)
    alreadyZ (bool): True if src is already a z-score — skips internal z-scoring
    invert (bool): True if HIGH indicator value = oversold (flips mapping)
  Returns: Integer score: +3 to -3

zScore(src, lookback)
  Returns the raw z-score without mapping to graduated scale.
Useful for plotting or custom threshold logic.
  Parameters:
    src (float): Raw indicator value
    lookback (int): Rolling lookback period
  Returns: Float z-score

mrScoreCustom(src, lookback, alreadyZ, invert, sd1, sd2, sd3)
  Same as mrScore but with configurable SD band edges.
For indicators where standard 1/2/3 SD bands don't fit well
(e.g., an indicator only becomes useful at 1.5 SD).
  Parameters:
    src (float): Raw indicator value (or z-score if alreadyZ=true)
    lookback (int): Rolling lookback for z-score calc
    alreadyZ (bool): True if src is already a z-score
    invert (bool): True if HIGH value = oversold
    sd1 (float): Inner band threshold (default would be 1.0)
    sd2 (float): Middle band threshold (default would be 2.0)
    sd3 (float): Outer band threshold (default would be 3.0)
  Returns: Integer score: +3 to -3

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.