Supported Indicators

Heikin Ashi

Introduction

This indicator computes the Heikin-Ashi bar (HA) The Heikin-Ashi bar is calculated using the following formulas: HA_Close[0] = (Open[0] + High[0] + Low[0] + Close[0]) / 4 HA_Open[0] = (HA_Open[1] + HA_Close[1]) / 2 HA_High[0] = MAX(High[0], HA_Open[0], HA_Close[0]) HA_Low[0] = MIN(Low[0], HA_Open[0], HA_Close[0])

Create Manual Indicators

You can manually create a HeikinAshi indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the HeikinAshi constructor.

HeikinAshi()1/2

            HeikinAshi QuantConnect.Indicators.HeikinAshi (
     string  name
   )
        

Initializes a new instance of the HeikinAshi class using the specified name.

HeikinAshi()2/2

            HeikinAshi QuantConnect.Indicators.HeikinAshi (
   )
        

Initializes a new instance of the HeikinAshi class.

Update Manual Indicators

You can update the indicator automatically or manually.

Automatic Update

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.


private HeikinAshi _heikinashi;

// In Initialize()
_heikinashi = new HeikinAshi(name);
_heikinashi.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _heikinashi, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_heikinashi.IsReady)
{
    var indicatorValue = _heikinashi.Current.Value;
}
    
# In Initialize()
self.heikinashi = HeikinAshi(name)
self.heikinashi.Updated += self.IndicatorUpdateMethod

self.RegisterIndicator(symbol, self.heikinashi, Resolution.Daily)

# In IndicatorUpdateMethod()
if self.heikinashi.IsReady:
    indicator_value = self.heikinashi.Current.Value

To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.

Manual Update

Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update method with a TradeBar, QuoteBar, or an IndicatorDataPoint. The indicator will only be ready after you prime it with enough data.

    
private HeikinAshi _heikinashi;
private Symbol symbol;

// In Initialize()
_heikinashi = new HeikinAshi();
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.QuoteBars.ContainsKey(_symbol))
{
    _heikinashi.Update(data.QuoteBars[symbol]);
}
if (_heikinashi.IsReady)
{
    var indicatorValue = _heikinashi.Current.Value;
}
    
# In Initialize()
self.heikinashi = HeikinAshi()
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.QuoteBars.ContainsKey(self.symbol):
    self.heikinashi.Update(data.QuoteBars[self.symbol])
if self.heikinashi.IsReady:
    indicator_value = self.heikinashi.Current.Value

Create Automatic Indicators

The HeikinAshi method creates an HeikinAshi indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.

The following reference table describes the HeikinAshi method:

HeikinAshi()1/1

            HeikinAshi QuantConnect.Algorithm.QCAlgorithm.HeikinAshi (
    Symbol                            symbol,
    *Nullable<Resolution>       resolution,
    *Func<IBaseData, TradeBar>  selector
   )
        

Creates a new Heikin-Ashi indicator.


If you don't provide a resolution, it defaults to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.

For more information about the selector argument, see Alternative Price Fields.

Get Indicator Values

To get the value of the indicator, use its Current.Value attribute.

private HeikinAshi _heikinashi;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_heikinashi = HeikinAshi(symbol);

// In OnData()
if (_heikinashi.IsReady)
{
    var open = _heikinashi.Open.Current.Value;
    var high = _heikinashi.High.Current.Value;
    var low = _heikinashi.Low.Current.Value;
    var close = _heikinashi.Close.Current.Value;
    var volume = _heikinashi.Volume.Current.Value;
    var current = _heikinashi.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.heikinashi = self.HeikinAshi(symbol)

# In OnData()
if self.heikinashi.IsReady:
    open = self.heikinashi.Open.Current.Value
    high = self.heikinashi.High.Current.Value
    low = self.heikinashi.Low.Current.Value
    close = self.heikinashi.Close.Current.Value
    volume = self.heikinashi.Volume.Current.Value
    current = self.heikinashi.Current.Value

Visualization

To plot indicator values, in the OnData event handler, call the Plot method.

private HeikinAshi _heikinashi;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_heikinashi = HeikinAshi(symbol);

// In OnData()
if (_heikinashi.IsReady)
{
    Plot("My Indicators", "open", _heikinashi.Open);
    Plot("My Indicators", "high", _heikinashi.High);
    Plot("My Indicators", "low", _heikinashi.Low);
    Plot("My Indicators", "close", _heikinashi.Close);
    Plot("My Indicators", "volume", _heikinashi.Volume);
    Plot("My Indicators", "heikinashi", _heikinashi.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.heikinashi = self.HeikinAshi(symbol)

# In OnData()
if self.heikinashi.IsReady:
    self.Plot("My Indicators", "open", self.heikinashi.Open)
    self.Plot("My Indicators", "high", self.heikinashi.High)
    self.Plot("My Indicators", "low", self.heikinashi.Low)
    self.Plot("My Indicators", "close", self.heikinashi.Close)
    self.Plot("My Indicators", "volume", self.heikinashi.Volume)
    self.Plot("My Indicators", "heikinashi", self.heikinashi.Current)

The following image shows the plot values in a matplotlib plot. To load algorithm plot data into the Research Environment, see Charts.

For more information about plotting indicators, see Plotting Indicators.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: