Indicator · Pine Script v6 · Own pane

Hyperbolic Tangent (TANH)

by mihakralj

This indicator applies the hyperbolic tangent to a chosen source series and plots the result in a separate pane.

View on GitHub

GitHub stars47on the repository
Pine versionv6current
Lines of code42
Settings2inputs
LicenceMIT
Last update8 months ago28 Feb 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

42 lines of Pine Script v6 from indicators/numerics/tanh.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

tanh.pine
// The MIT License (MIT)
// © mihakralj
//@version=6
indicator("Hyperbolic Tangent (TANH)", "TANH", overlay=false, precision=6)

//@function Applies the hyperbolic tangent (tanh) function to a source series.
// Formula: S(x) = tanh(k * (x - x0))
// where tanh(y) = (exp(y) - exp(-y)) / (exp(y) + exp(-y))
// Maps any real-valued input to the range (-1, 1).
//@param src The source series.
//@param k The steepness factor. Higher k means a steeper curve around x0.
//@param x0 The x-value of the inflection point (where the output is 0).
//@returns The tanh transformed series, values between -1 and 1.
tanh(series float src, simple float k, float x0) =>
    y = k * (src - x0)
    exp_y = math.exp(y)
    exp_neg_y = math.exp(-y)
    numerator = exp_y - exp_neg_y
    denominator = exp_y + exp_neg_y
    result = float(na)
    if denominator == 0.0
        if numerator > 0
            result := 1.0
        else if numerator < 0
            result := -1.0
        else
            result := 0.0
    else
        result := numerator / denominator
    result

// ---------- Main loop ----------

// Inputs
i_source = input.source(close, "Source")
i_steepness_k = input.float(0.5, "Steepness (k)", minval = 0.1, step = 0.1)

// Calculation
tanhValue = tanh(i_source, i_steepness_k, ta.sma(i_source,200))

// Plot
plot(tanhValue, "Tanh", color=color.yellow, linewidth=2)

Overview

Hyperbolic Tangent (TANH) centers the transform on a 200-bar simple moving average of that source, multiplies the deviation by a steepness factor, and maps the output into the open range from negative one to one. A higher steepness setting makes the curve rise more sharply around that average. A zero denominator is clamped to the nearest bound. It does not generate entries, exits, or risk rules.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Moving averages, Mean reversion

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescriptpinescript-indicatorstechnical-analysistradingview-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourceclosei_source
Steepness (k)float0.5i_steepness_k
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

114 stars

Calculates normalized reversal metrics across up to ten Forex currency pairs using user-selected moving average methods, including HarmonicMA, EMA, SMA, or WMA. The indicator identifies overbought, oversold, and mean-crossing conditions using a configurable th

Indicator v4 Screeners & dashboardsMean reversion
Updated 1 year ago · None stated GitHub repository of Multi-Pair Trend Reversal Widget

This indicator builds a channel from a Hull moving average of the source and an ATR scaled by a band multiplier, then normalizes price inside that channel into a 0 to 100 oscillator. It smooths the result with a weighted moving average and plots the line in a

Indicator v6 Mean reversionVolatility & bands
Updated 3 months ago · None stated GitHub repository of Radiant Mean Reversion Channels [Pineify]

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

Kalman Percentile Bands

by NQ-stats-MX
15 stars

Kalman Percentile Bands plots a volatility-adaptive Kalman mean along with three empirical percentile bands on each side of the price chart. It calculates a local-level Kalman filter as the fair value mean, normalizes price deviations by an EWMA of volatility,

Indicator v6 Mean reversionVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of Kalman Percentile Bands

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers