Indicator · Pine Script v5 · On the chart

Heikin Ashi with MACD Signals

by g-moe· code credited to goodgains

This indicator plots buy and sell labels on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code122
Settings3inputs
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

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

heikin-ashi-macd-signals.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 with MACD Signals", overlay = true)

// @keywords: dual-macd-filter, stochastic-crossover, buy-sell-labels, heikin-ashi-trend, trend-strength-percent, momentum-macd-table, volatility-rvi, volume-pressure, shares-float-display, dashboard-table, rsi-deviation, multi-macd-alignment, oversold-entry, overbought-entry, overlay-signals, ema-smoothed-ha, sentiment-panel, financial-float, long-short-badge, signal-state-machine

// MACD's
[macdLine1, signalLine1, histLine1] = ta.macd(close, 13, 144, 9)
[macdLine2, signalLine2, histLine2] = ta.macd(close, 13, 21, 9)

macd1_side = histLine1 > 0 ? 1 : -1
macd2_side = histLine2 > 0 ? 1 : -1

// STOCH
stoch_k = ta.sma(ta.stoch(close, high, low, 7), 3)
stoch_d = ta.sma(stoch_k, 3)

stoch_buy_crossover = stoch_k < 20 and ta.crossover(stoch_k,stoch_d)
stoch_sell_crossunder = stoch_k > 80 and ta.crossunder(stoch_k,stoch_d)


// CREATE BUY SELL SIGNALS
var last_signal = 0 
long_entry = stoch_buy_crossover and macd1_side == 1 and macd2_side == -1 
short_entry = stoch_sell_crossunder and macd1_side == -1 and macd2_side == 1 

last_signal := long_entry ? 1 : short_entry ? -1 : last_signal[1]

buy_color = input.color(#007d05, title='Buy', inline='1', group='Color Settings')
sell_color = input.color(#c30616, title='Sell', inline='1', group='Color Settings')
plotshape(long_entry, style=shape.labelup, editable=false, text= "BUY", textcolor=color.white, location= location.belowbar, color=color.new(buy_color, 30), size=size.tiny)
plotshape(short_entry, style=shape.labeldown, editable=false, text='SELL', textcolor=color.white, location=location.abovebar, color=color.new(sell_color, 30), size=size.tiny)






// TABLE

// trend
ema_length = 20
o = ta.ema(open, ema_length)
c = ta.ema(close, ema_length)
h = ta.ema(high, ema_length)
l = ta.ema(low, ema_length)
ha_t = ticker.heikinashi(syminfo.tickerid)
[ha_o, ha_h, ha_l, ha_c] = request.security(ha_t, timeframe.period, [ta.ema(open, ema_length), ta.ema(high, ema_length), ta.ema(low, ema_length), ta.ema(close, ema_length)])

ha_o_smooth = ta.ema(ha_o, ema_length)
ha_c_smooth = ta.ema(ha_c, ema_length)
ha_h_smooth = ta.ema(ha_h, ema_length)
ha_l_smooth = ta.ema(ha_l, ema_length)
dif_oc = ha_c_smooth - ha_o_smooth
dif_hl = ha_h_smooth - ha_l_smooth
variable_oc_percent = dif_oc * 100 / dif_hl

// trend strength %
strength_pct = variable_oc_percent * 2 >= 100 ? 100 : variable_oc_percent * 2 <= -100 ? -100 : variable_oc_percent * 2

// momentum
[macdLine3, signalLine3, histLine3] = ta.macd(close, 20, 50, 10)

// volatility
rvi = ta.rsi(ta.stdev(close, 30),14) / 100

// volume
volume_bars = 20
float volume_up = 0
float volume_down = 0
if barstate.islast
    for i = 0 to volume_bars-1
        if (close[i]>open[i])
            volume_up:=volume_up+volume[i]
        else
            volume_down:=volume_down+volume[i]

total_up_down_vol=volume_up-volume_down
// plot(one_side ? math.abs(total_up_down_vol) : total_up_down_vol  ,color=total_up_down_vol>0 ? color.green : color.red, style=plot.style_columns)



// ema

// shares float
var float f = na
var int f_length = na
var string f_tablestring = na
f := math.round(request.financial(syminfo.tickerid, "FLOAT_SHARES_OUTSTANDING", "FY",ignore_invalid_symbol=true),0)
if barstate.islast
    f_length := str.length(str.tostring(f))
    f_tablestring := f_length >= 10 ? str.tostring(math.round(f*0.000000001,2)) + ' B' : f_length >= 7 ? str.tostring(math.round(f*0.000001,2)) + ' M' : str.tostring(math.round(f,2)) + ' K'





show_table = input.bool(true, title = 'Show Table', group = 'Table Settings', inline = '1')


if barstate.islast and show_table

    var table t = table.new(position.middle_right , 3, 10, frame_color=color.new(#434651, 0), frame_width=3, border_color=color.new(#434651,0), border_width=3)

    // column 1
    table.cell(t, 0, 0, text = '📈 Trend', width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_left)
    table.cell(t, 0, 1, text = '💪 Trend Strength', width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_left)
    table.cell(t, 0, 2, text = '⌚ Momentum', width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_left)
    table.cell(t, 0, 3, text = '⚡ Volatility', width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_left)
    table.cell(t, 0, 4, text = '📊 Volume', width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_left)
    table.cell(t, 0, 5, text = '📝 Shares Float', width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_left)

    // column 2
    table.cell(t, 1, 0, text = variable_oc_percent > 0 ? 'Long' : 'Short', width=0, bgcolor=variable_oc_percent > 0 ? buy_color : sell_color, text_color=color.white, text_size=size.normal, text_halign=text.align_center)
    table.cell(t, 1, 1, text = str.tostring(math.abs(strength_pct),format.percent), width=0, bgcolor=variable_oc_percent > 0 and math.abs(strength_pct) > 55 ? buy_color : variable_oc_percent < 0 and math.abs(strength_pct) > 55 ? sell_color : color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_center)
    table.cell(t, 1, 2, text = histLine3 > 0 ? 'Bullish' : 'Bearish', width=0, bgcolor= histLine3 > 0 ? buy_color : sell_color, text_color= color.white, text_size=size.normal, text_halign=text.align_center)
    table.cell(t, 1, 3, text = rvi > rvi[3] ? 'Increasing' : 'Decreasing', width=0, bgcolor=histLine3 > 0 ? buy_color : sell_color, text_color=color.white, text_size=size.normal, text_halign=text.align_center)
    table.cell(t, 1, 4, text = total_up_down_vol > 0 ? 'Bullish' : 'Bearish', width=0, bgcolor=total_up_down_vol > 0 ? buy_color : sell_color, text_color=color.white, text_size=size.normal, text_halign=text.align_center)
    table.cell(t, 1, 5, text = f_tablestring, width=0, bgcolor=color.gray, text_color=color.white, text_size=size.normal, text_halign=text.align_center)

Overview

A buy appears when a short stochastic crosses up from below 20 while a slow MACD histogram is positive and a faster MACD histogram is negative. A sell uses the opposite stochastic and MACD alignment. Color inputs change the label colors. An optional table shows EMA-smoothed Heikin Ashi trend strength, a third MACD, relative volatility, recent up versus down volume, and reported shares float. It does not place orders or set stops.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Candlestick patterns, Volatility & bands, Screeners & dashboards

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
Buycolor#007d05buy_color
Sellcolor#c30616sell_color
Show Tablebooltrueshow_table
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

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup
330 stars

This multi-symbol indicator evaluates a combined trading condition across up to 40 user-defined symbols. It processes MACD bullish crossovers, RSI thresholds, Bollinger Band boundaries, and DMI/ADX trend filters using security calls. When buy or sell criteria

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of Multi MACD + BB + RSI [Alorse]

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

8zz反指標v2

by hansai-art
121 stars

The 8zz Contrarian Indicator plots reverse sentiment trading signals directly on the price chart based on tracked retail post activity. It generates bullish signals during retail panic and bearish signals during market euphoria. The indicator features adjustab

Indicator v6 Moving averagesOscillators & momentum
Updated 3 months ago · None stated GitHub repository of 8zz反指標v2

This indicator displays a customizable dashboard table on the price chart. It combines Market Action Pulse state, McClellan breadth z-score, VIX Mood Ring status, and Risk Assessment Model hazard score. Users select symbols such as NASDAQ:QQQE or VIX, toggle c

Indicator v6 Screeners & dashboardsOscillators & momentum Repaints

Commodity Heat Reversal plots score-based mean-reversion reversal markers on the price chart for commodity futures, aimed at the four-hour timeframe. It builds separate long and short heat scores from ATR distance to a mean moving average, ATR expansion, RSI e

Indicator v6 Mean reversionVolatility & bands
Updated yesterday · MIT GitHub repository of Commodity Heat Reversal [WavesUnchained]

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