Indicator · Pine Script v6 · On the chart

HA Candles

by teshmi9z-beep· code credited to teshmi9z

An overlay that redraws the chart using an alternative candle type.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code70
Settings2inputs
LicenceMIT
Last updateyesterday28 Oct 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

70 lines of Pine Script v6 from src/indicators/custom/haCandles.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

haCandles.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © teshmi9z

//@version=6
indicator("HA", overlay=true)
customBuyColor = color.new(#00FFFF, 0)
customSellColor = color.new(#FF0000, 0)
var string candleGroup = 'Candlestick Settings'
candleType = input.string('Linear Regression', 'Candle Type', options = ['Candlesticks', 'Heikin Ashi', 'Linear Regression'], group = candleGroup, tooltip = 'Choose the type of candles to display. This does not impact signal calculations.')
lrcLength = input.int(6, 'Linear Regression Length', minval = 1, group = candleGroup, tooltip = 'Length for Linear Regression calculations. Lower values are more responsive but noisier.')

// Heikin Ashi
calculateHA() =>
    var haOpen = 0.0
    var haHigh = 0.0
    var haLow = 0.0
    var haClose = 0.0

    newHaClose = (open + high + low + close) / 4
    newHaOpen = na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
    newHaHigh = math.max(high, math.max(newHaOpen, newHaClose))
    newHaLow = math.min(low, math.min(newHaOpen, newHaClose))

    haClose := newHaClose
    haOpen := newHaOpen
    haHigh := newHaHigh
    haLow := newHaLow

    [newHaOpen, newHaHigh, newHaLow, newHaClose]

[oHA, hHA, lHA, cHA] = calculateHA()

var float displayOpen = na
var float displayHigh = na
var float displayLow = na
var float displayClose = na

if candleType == 'Candlesticks'
    displayOpen := open
    displayHigh := high
    displayLow := low
    displayClose := close
else if candleType == 'Heikin Ashi'
    displayOpen := oHA
    displayHigh := hHA
    displayLow := lHA
    displayClose := cHA
else if candleType == 'Linear Regression'
    displayOpen := ta.linreg(open, lrcLength, 0)
    displayHigh := ta.linreg(high, lrcLength, 0)
    displayLow := ta.linreg(low, lrcLength, 0)
    displayClose := ta.linreg(close, lrcLength, 0)

// Determine coloring
isBullishCandle = displayClose > displayOpen
isBearishCandle = displayClose < displayOpen
// ===========================================================================================================
// CANDLE PLOTTING
// ===========================================================================================================

candleColor = isBullishCandle ? customBuyColor : customSellColor

plotcandle(candleType != 'Candlesticks' ? displayOpen : na,
           candleType != 'Candlesticks' ? displayHigh : na,
           candleType != 'Candlesticks' ? displayLow : na,
           candleType != 'Candlesticks' ? displayClose : na,
           title = 'Alternative Candles',
           color = candleType != 'Candlesticks' ? candleColor : na,
           wickcolor = candleType != 'Candlesticks' ? candleColor : na,
           bordercolor = candleType != 'Candlesticks' ? candleColor : na)

Overview

The user can choose normal candlesticks, Heikin Ashi candles, or candles built from linear regression of open, high, low and close over an adjustable length. Alternative candles are coloured cyan when the close is above the open and red when below. The choice changes only how candles are displayed and does not drive any signals. Shorter regression lengths react faster but look noisier.

Details

Published by

teshmi9z-beep on GitHub

Code credit

teshmi9z, as written in the script's header

Draws

On the price chart

Category

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
Candle TypestringLinear RegressioncandleType
Linear Regression Lengthint6lrcLength
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

947 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 11 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers