Indicator · Pine Script v5 · Own pane

Heikin Ashi

by g-moe· code credited to goodgains

This indicator combines a standard relative strength index (RSI) with a Heikin Ashi moving average trend visualization in a separate pane.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code52
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

52 lines of Pine Script v5 from Tradingview/heikin-ashi.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

heikin-ashi.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Heikin Ashi", overlay = false, format=format.price, precision=2, timeframe="", timeframe_gaps=true)

// @keywords: rsi, rsi-moving-average, overbought-oversold, heikin-ashi, ha-moving-average, background-fill, oscillator-pane, wma-smoothing, candle-smoothing, trend-background, rsi-bands, fifty-line, rsi-circles, ha-calculation, averaged-price, trend-state, ha-open-close, secondary-pane, smoothed-candles, rsi-overlay

//RSI
ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI Settings")
maLengthInput = input.int(14, title="MA Length", group="RSI Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)

plot(rsi, "RSI", color=color.blue, style = plot.style_circles, join = true, linewidth = 2)
plot(rsiMA, "RSI-based MA", color=color.new(color.yellow,50))
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")

// HA

len = input.int(25, minval=1, maxval=500, title="Length", group="Heikin Ashi Moving Average", tooltip="Set moving average length.")

haClose = (open + high + low + close) / 4
haOpen = float(na)
haOpen := na(haOpen[1]) ? (open + close) / 2 : (nz(haOpen[1]) + nz(haClose[1])) / 2
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))

col_ = haClose>haOpen?color.green:color.red

///////////////////////////////////////////////////////////////////////////////// Heikin Ashi Moving Average
avg = math.avg(haOpen,haHigh,haLow,haClose)
HA_movingAverage = ta.wma(avg, len)
col = HA_movingAverage>HA_movingAverage[1]? color.new(color.green,80) : color.new(color.red,80)
bgcolor(col)

Overview

Heikin Ashi calculates the RSI along with a customizable moving average overlay supporting SMA, EMA, SMMA, WMA, and VWMA types. Additionally, it computes Heikin Ashi open, high, low, and close values, applies a weighted moving average to the average price, and colors the chart background based on whether the smoothed Heikin Ashi value is rising or falling. Settings allow adjustment of RSI and moving average lengths.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages, Trend

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.

Settings

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

SettingTypeDefaultVariable
RSI Lengthint14rsiLengthInput
SourcesourceclosersiSourceInput
MA TypestringSMAmaTypeInput
MA Lengthint14maLengthInput
Lengthint25len
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

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Elder Impulse System

by mihakralj
99 stars

Elder Impulse System plots a column series in a separate pane. It compares a 13-period exponential moving average with its previous value and a MACD histogram with its previous value. A rising EMA and rising histogram print 1, a falling EMA and falling histogr

Indicator v5 TrendOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Elder Impulse System
47 stars

This indicator calculates the Williams Gator Oscillator derived from Bill Williams Alligator lines and plots dual histograms in a separate pane. The upper histogram displays the absolute difference between the Jaw and Teeth moving averages, while the lower his

Indicator v6 Oscillators & momentumMoving averages
Updated 8 months ago · MIT GitHub repository of Williams Gator Oscillator

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