TradingView indicator guide

Heikin-Ashi Oscillator on TradingView: synthetic values and signals

A Heikin-Ashi oscillator turns synthetic candle values into a separate-pane series. This page defines the body oscillator as HA close minus HA open, without additional smoothing or normalization. Positive values mean the HA body closes above its synthetic open; negative values mean the opposite. Community scripts using the same name can calculate something different. The worked example and Pine Script below specify the formula, starting value and closed-bar signal rules so you can reproduce this particular version.

See the decision guide

Identify the oscillator before comparing signals

The name does not specify one universal formula. TraderHalai describes a public Heikin Ashi Oscillator that compares HA close with the regular candle close and offers smoothing. That differs from the HA body difference defined here. Check the author, source, subtraction direction and smoothing settings before comparing two histograms.

  • The close-gap column below is a mathematical comparison, not a claim to reproduce every setting of TraderHalai's script.
  • D is measured in price units and is unbounded. It has no built-in RSI-style overbought or oversold levels. Adding a percentage scale, ATR divisor or smoother defines another version.
DefinitionCalculation on this pageMeaning of zero
HA body oscillator DHA close − HA openThe synthetic body has no height.
Close-gap comparison GHA close − standard closeThe four-price average equals the actual close.
Standard candle bodyStandard close − standard openThe market bar closes where it opened.

Calculate the recursive open from standard prices

Let O, H, L and C denote the standard market bar. For every bar, HA close = (O + H + L + C) / 4. After the first bar, HA open = (previous HA open + previous HA close) / 2. Our explicit seed is HA open on the first loaded bar = (O + C) / 2. Then D = HA close − HA open. No volume input or additional moving average is used.

  • The previous values in the open recurrence are HA values, not the preceding standard open and close. Replacing them with standard prices changes the calculation.
  • Only HA open and close are needed for this oscillator. Synthetic high and low are not required to calculate D.
  • If two calculations use identical subsequent OHLC but their HA open seeds differ by e, their HA open difference after k updates is e / 2^k. Their oscillator differences have the opposite sign. An initial difference of 8 becomes 0.0078125 after ten updates.
  • Loading more history can change the first bar and seed. The effect decays but can still change a near-zero crossing. This explicit seed is a reproducibility convention, not a guarantee of exact equality with the beginning of TradingView's HA feed.

Reproduce five hypothetical bars

These prices are an arithmetic fixture, not market data or a backtest. Start at A and retain full precision between rows. The first seed is (100 + 102) / 2 = 101; the first HA close is (100 + 104 + 98 + 102) / 4 = 101.

  • At C, HA open = (101 + 104.5) / 2 = 102.75. The oscillator is positive at 3 even though the standard candle falls from 107 to 104. A positive HA body does not mean the current market candle rose.
  • At D, D crosses below zero: 100.5 − 104.25 = −3.75. G is positive at 3.5 on that same bar. Swapping the two definitions reverses the apparent direction.
  • At E, the standard candle rises from 97 to 98 but D becomes more negative. Its HA open, 102.375, is even above the real high of 99. A simulated fill at that synthetic open would use a price outside this bar's traded range.
Bar / standard O, H, L, CHA openHA closeD: HA bodyG: close gap
A / 100, 104, 98, 1021011010−1
B / 102, 108, 101, 107101104.53.5−2.5
C / 107, 109, 103, 104102.75105.7531.75
D / 104, 105, 96, 97104.25100.5−3.753.5
E / 97, 99, 95, 98102.37597.25−5.125−0.75

Inspect the body oscillator in Pine Script v6

Add this indicator to a standard candle chart. It rejects non-standard chart types so synthetic OHLC cannot accidentally be averaged a second time. The histogram shows completed bars; the Data Window exposes the two HA values and the standard close at the same timestamps. There are no strategy orders.

  • The above-zero event requires current D > 0 and previous D ≤ 0. The below-zero event requires current D < 0 and previous D ≥ 0. A current zero is neither event; A has no preceding observation, and B crosses above zero from A's equality.
  • Calculations and crossing checks run on every update. Confirmation gates only plots and alert conditions. High, low and close can change intrabar, so a developing crossing can disappear before the close.
  • After checking the values, create a TradingView alert for the desired condition and select Once Per Bar Close. The script declares alert conditions; adding it to a chart does not create a running alert.
An explicit-seed calculation example. Syntax validation does not verify trading returns or equivalence with a differently seeded community indicator.pine
//@version=6
indicator("HA body oscillator audit", overlay = false, precision = 6)
if not chart.is_standard
    runtime.error("Use a standard chart so OHLC are market prices.")
haClose = (open + high + low + close) / 4.0
var float haOpen = na
haOpen := barstate.isfirst ? (open + close) / 2.0 : (haOpen[1] + haClose[1]) / 2.0
bodyDelta = haClose - haOpen
crossUp = ta.crossover(bodyDelta, 0.0)
crossDown = ta.crossunder(bodyDelta, 0.0)
bodyColor = bodyDelta > 0 ? color.teal : bodyDelta < 0 ? color.red : color.gray
plot(barstate.isconfirmed ? bodyDelta : na, "HA close minus HA open", color = bodyColor, style = plot.style_columns)
hline(0, "Zero", color = color.gray)
plot(barstate.isconfirmed ? haOpen : na, "Seeded HA open", display = display.data_window)
plot(barstate.isconfirmed ? haClose : na, "HA close", display = display.data_window)
plot(barstate.isconfirmed ? close : na, "Standard close", display = display.data_window)
alertcondition(barstate.isconfirmed and crossUp, "HA body crosses above zero", "Confirmed HA body crossed above zero.")
alertcondition(barstate.isconfirmed and crossDown, "HA body crosses below zero", "Confirmed HA body crossed below zero.")

Separate HA signals from standard-price backtests

For a strategy built from this calculation, keep the chart on standard candles and calculate the HA signal inside the script. The broker emulator then uses standard chart prices for fills. If a different strategy runs on an HA chart, enable Fill orders on standard OHLC in its properties, or its fill_orders_on_standard_ohlc setting. That setting changes simulated fills; it does not turn synthetic signal inputs into market prices.

  • With default strategy calculation and order processing, a market order created at the bar close normally fills at the next bar's open. A below-zero signal on D therefore does not imply an entry at HA close 100.5; in this fixture the next standard open is E's 97 before costs.
  • Standard OHLC improves the fill basis but remains a simulation. Historical bars do not fully describe intrabar paths, available liquidity or live execution latency.
  • This indicator provides no position sizing, stop or target. Any strategy conversion needs explicit rules and independent testing; no return is implied by the five-bar fixture.
Test detailRequired decisionFailure if omitted
Input candlesUse standard OHLC once, then calculate HA.A second HA transformation changes every later signal.
Fill sourceUse standard prices, including when displaying HA candles.E's synthetic open exceeds its real high.
Execution timeRecord when the signal confirms and when an order can fill.A historical synthetic close is treated as an available entry.
Costs and exitsSpecify position sizing, exits, commission and slippage.An indicator crossing is mistaken for a complete strategy result.

Verify values before adding alert rules with Pineify

Ask the Pine Script AI Coding Agent to draft or explain this public calculation using the exact seed, chart timeframe and confirmation rule. Include the five-bar fixture and request separate HA open, HA close and standard close outputs. Review the source, request a syntax check, then compare the values in TradingView before extending alerts or strategy rules.

  • Compare the same symbol, feed, session, timeframe and completed timestamps. Begin with HA close, then diagnose HA open history and seed differences, and only then compare zero crossings.
  • For a comparison with TradingView's own HA candles, use its documented ticker.heikinashi data feed with the same session. Near the beginning of loaded history, account for the seed difference instead of silently changing the formula to force a match.
  • Test constant OHLC with a matching seed: D must stay zero. If a nonmatching seed is supplied, D should converge toward zero by halving each bar. Neither test establishes profitable signals.
  • The coding request covers the disclosed body formula. It does not require copying a protected indicator or assuming a community script's private rules.
Where Pineify fits

Pine Script AI Coding Agent

Draft or inspect a Heikin-Ashi body calculation with an explicit seed, diagnostic values and confirmed-bar alert conditions.

Draft an HA body oscillator

Frequently asked questions

Educational information, not investment advice. The OHLC sequence is hypothetical and is not a performance backtest. Synthetic values, zero crossings and syntax validation do not guarantee executable prices or trading returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.