Supported Indicators
Ichimoku Kinko Hyo
Introduction
This indicator computes the Ichimoku Kinko Hyo indicator. It consists of the following main indicators: Tenkan-sen: (Highest High + Lowest Low) / 2 for the specific period (normally 9) Kijun-sen: (Highest High + Lowest Low) / 2 for the specific period (normally 26) Senkou A Span: (Tenkan-sen + Kijun-sen )/ 2 from a specific number of periods ago (normally 26) Senkou B Span: (Highest High + Lowest Low) / 2 for the specific period (normally 52), from a specific number of periods ago (normally 26)
To view the implementation of this indicator, see the LEAN GitHub repository.
Using ICHIMOKU Indicator
To create an automatic indicator for IchimokuKinkoHyo, call the ICHIMOKUichimoku helper method from the QCAlgorithm class. The ICHIMOKUichimoku method creates a IchimokuKinkoHyo object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.
public class IchimokuKinkoHyoAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private IchimokuKinkoHyo _ichimoku;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_ichimoku = ICHIMOKU(_symbol, 9, 26, 17, 52, 26, 26);
}
public override void OnData(Slice data)
{
if (_ichimoku.IsReady)
{
// The current value of _ichimoku is represented by itself (_ichimoku)
// or _ichimoku.Current.Value
Plot("IchimokuKinkoHyo", "ichimoku", _ichimoku);
// Plot all properties of abands
Plot("IchimokuKinkoHyo", "tenkan", _ichimoku.Tenkan);
Plot("IchimokuKinkoHyo", "kijun", _ichimoku.Kijun);
Plot("IchimokuKinkoHyo", "senkoua", _ichimoku.SenkouA);
Plot("IchimokuKinkoHyo", "senkoub", _ichimoku.SenkouB);
Plot("IchimokuKinkoHyo", "chikou", _ichimoku.Chikou);
Plot("IchimokuKinkoHyo", "tenkanmaximum", _ichimoku.TenkanMaximum);
Plot("IchimokuKinkoHyo", "tenkanminimum", _ichimoku.TenkanMinimum);
Plot("IchimokuKinkoHyo", "kijunmaximum", _ichimoku.KijunMaximum);
Plot("IchimokuKinkoHyo", "kijunminimum", _ichimoku.KijunMinimum);
Plot("IchimokuKinkoHyo", "senkoubmaximum", _ichimoku.SenkouBMaximum);
Plot("IchimokuKinkoHyo", "senkoubminimum", _ichimoku.SenkouBMinimum);
Plot("IchimokuKinkoHyo", "delayedtenkansenkoua", _ichimoku.DelayedTenkanSenkouA);
Plot("IchimokuKinkoHyo", "delayedkijunsenkoua", _ichimoku.DelayedKijunSenkouA);
Plot("IchimokuKinkoHyo", "delayedmaximumsenkoub", _ichimoku.DelayedMaximumSenkouB);
Plot("IchimokuKinkoHyo", "delayedminimumsenkoub", _ichimoku.DelayedMinimumSenkouB);
}
}
} class IchimokuKinkoHyoAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._ichimoku = self.ichimoku(self._symbol, 9, 26, 17, 52, 26, 26)
def on_data(self, slice: Slice) -> None:
if self._ichimoku.is_ready:
# The current value of self._ichimoku is represented by self._ichimoku.current.value
self.plot("IchimokuKinkoHyo", "ichimoku", self._ichimoku.current.value)
# Plot all attributes of self._ichimoku
self.plot("IchimokuKinkoHyo", "tenkan", self._ichimoku.tenkan.current.value)
self.plot("IchimokuKinkoHyo", "kijun", self._ichimoku.kijun.current.value)
self.plot("IchimokuKinkoHyo", "senkou_a", self._ichimoku.senkou_a.current.value)
self.plot("IchimokuKinkoHyo", "senkou_b", self._ichimoku.senkou_b.current.value)
self.plot("IchimokuKinkoHyo", "chikou", self._ichimoku.chikou.current.value)
self.plot("IchimokuKinkoHyo", "tenkan_maximum", self._ichimoku.tenkan_maximum.current.value)
self.plot("IchimokuKinkoHyo", "tenkan_minimum", self._ichimoku.tenkan_minimum.current.value)
self.plot("IchimokuKinkoHyo", "kijun_maximum", self._ichimoku.kijun_maximum.current.value)
self.plot("IchimokuKinkoHyo", "kijun_minimum", self._ichimoku.kijun_minimum.current.value)
self.plot("IchimokuKinkoHyo", "senkou_b_maximum", self._ichimoku.senkou_b_maximum.current.value)
self.plot("IchimokuKinkoHyo", "senkou_b_minimum", self._ichimoku.senkou_b_minimum.current.value)
self.plot("IchimokuKinkoHyo", "delayed_tenkan_senkou_a", self._ichimoku.delayed_tenkan_senkou_a.current.value)
self.plot("IchimokuKinkoHyo", "delayed_kijun_senkou_a", self._ichimoku.delayed_kijun_senkou_a.current.value)
self.plot("IchimokuKinkoHyo", "delayed_maximum_senkou_b", self._ichimoku.delayed_maximum_senkou_b.current.value)
self.plot("IchimokuKinkoHyo", "delayed_minimum_senkou_b", self._ichimoku.delayed_minimum_senkou_b.current.value)For more information about this method, see the QCAlgorithm classQCAlgorithm class.
You can manually create a IchimokuKinkoHyo indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.
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 Updateupdate method. The indicator will only be ready after you prime it with enough data.
public class IchimokuKinkoHyoAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private IchimokuKinkoHyo _ichimokukinkohyo;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_ichimokukinkohyo = new IchimokuKinkoHyo(9, 26, 17, 52, 26, 26);
}
public override void OnData(Slice data)
{
if (data.Bars.TryGetValue(_symbol, out var bar))
_ichimokukinkohyo.Update(bar);
if (_ichimokukinkohyo.IsReady)
{
// The current value of _ichimokukinkohyo is represented by itself (_ichimokukinkohyo)
// or _ichimokukinkohyo.Current.Value
Plot("IchimokuKinkoHyo", "ichimokukinkohyo", _ichimokukinkohyo);
// Plot all properties of abands
Plot("IchimokuKinkoHyo", "tenkan", _ichimokukinkohyo.Tenkan);
Plot("IchimokuKinkoHyo", "kijun", _ichimokukinkohyo.Kijun);
Plot("IchimokuKinkoHyo", "senkoua", _ichimokukinkohyo.SenkouA);
Plot("IchimokuKinkoHyo", "senkoub", _ichimokukinkohyo.SenkouB);
Plot("IchimokuKinkoHyo", "chikou", _ichimokukinkohyo.Chikou);
Plot("IchimokuKinkoHyo", "tenkanmaximum", _ichimokukinkohyo.TenkanMaximum);
Plot("IchimokuKinkoHyo", "tenkanminimum", _ichimokukinkohyo.TenkanMinimum);
Plot("IchimokuKinkoHyo", "kijunmaximum", _ichimokukinkohyo.KijunMaximum);
Plot("IchimokuKinkoHyo", "kijunminimum", _ichimokukinkohyo.KijunMinimum);
Plot("IchimokuKinkoHyo", "senkoubmaximum", _ichimokukinkohyo.SenkouBMaximum);
Plot("IchimokuKinkoHyo", "senkoubminimum", _ichimokukinkohyo.SenkouBMinimum);
Plot("IchimokuKinkoHyo", "delayedtenkansenkoua", _ichimokukinkohyo.DelayedTenkanSenkouA);
Plot("IchimokuKinkoHyo", "delayedkijunsenkoua", _ichimokukinkohyo.DelayedKijunSenkouA);
Plot("IchimokuKinkoHyo", "delayedmaximumsenkoub", _ichimokukinkohyo.DelayedMaximumSenkouB);
Plot("IchimokuKinkoHyo", "delayedminimumsenkoub", _ichimokukinkohyo.DelayedMinimumSenkouB);
}
}
} class IchimokuKinkoHyoAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._ichimokukinkohyo = IchimokuKinkoHyo(9, 26, 17, 52, 26, 26)
def on_data(self, slice: Slice) -> None:
bar = slice.bars.get(self._symbol)
if bar:
self._ichimokukinkohyo.update(bar)
if self._ichimokukinkohyo.is_ready:
# The current value of self._ichimokukinkohyo is represented by self._ichimokukinkohyo.current.value
self.plot("IchimokuKinkoHyo", "ichimokukinkohyo", self._ichimokukinkohyo.current.value)
# Plot all attributes of self._ichimokukinkohyo
self.plot("IchimokuKinkoHyo", "tenkan", self._ichimokukinkohyo.tenkan.current.value)
self.plot("IchimokuKinkoHyo", "kijun", self._ichimokukinkohyo.kijun.current.value)
self.plot("IchimokuKinkoHyo", "senkou_a", self._ichimokukinkohyo.senkou_a.current.value)
self.plot("IchimokuKinkoHyo", "senkou_b", self._ichimokukinkohyo.senkou_b.current.value)
self.plot("IchimokuKinkoHyo", "chikou", self._ichimokukinkohyo.chikou.current.value)
self.plot("IchimokuKinkoHyo", "tenkan_maximum", self._ichimokukinkohyo.tenkan_maximum.current.value)
self.plot("IchimokuKinkoHyo", "tenkan_minimum", self._ichimokukinkohyo.tenkan_minimum.current.value)
self.plot("IchimokuKinkoHyo", "kijun_maximum", self._ichimokukinkohyo.kijun_maximum.current.value)
self.plot("IchimokuKinkoHyo", "kijun_minimum", self._ichimokukinkohyo.kijun_minimum.current.value)
self.plot("IchimokuKinkoHyo", "senkou_b_maximum", self._ichimokukinkohyo.senkou_b_maximum.current.value)
self.plot("IchimokuKinkoHyo", "senkou_b_minimum", self._ichimokukinkohyo.senkou_b_minimum.current.value)
self.plot("IchimokuKinkoHyo", "delayed_tenkan_senkou_a", self._ichimokukinkohyo.delayed_tenkan_senkou_a.current.value)
self.plot("IchimokuKinkoHyo", "delayed_kijun_senkou_a", self._ichimokukinkohyo.delayed_kijun_senkou_a.current.value)
self.plot("IchimokuKinkoHyo", "delayed_maximum_senkou_b", self._ichimokukinkohyo.delayed_maximum_senkou_b.current.value)
self.plot("IchimokuKinkoHyo", "delayed_minimum_senkou_b", self._ichimokukinkohyo.delayed_minimum_senkou_b.current.value)For more information about this indicator, see its referencereference.
Indicator History
To get the historical data of the IchimokuKinkoHyo indicator, call the IndicatorHistoryself.indicator_history method. This method resets your indicator, makes a history request, and updates the indicator with the historical data. Just like with regular history requests, the IndicatorHistoryindicator_history method supports time periods based on a trailing number of bars, a trailing period of time, or a defined period of time. If you don't provide a resolution argument, it defaults to match the resolution of the security subscription.
public class IchimokuKinkoHyoAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private IchimokuKinkoHyo _ichimoku;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_ichimoku = ICHIMOKU(_symbol, 9, 26, 17, 52, 26, 26);
var indicatorHistory = IndicatorHistory(_ichimoku, _symbol, 100, Resolution.Minute);
var timeSpanIndicatorHistory = IndicatorHistory(_ichimoku, _symbol, TimeSpan.FromDays(10), Resolution.Minute);
var timePeriodIndicatorHistory = IndicatorHistory(_ichimoku, _symbol, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);
// Access all attributes of indicatorHistory
var tenkan = indicatorHistory.Select(x => ((dynamic)x).Tenkan).ToList();
var kijun = indicatorHistory.Select(x => ((dynamic)x).Kijun).ToList();
var senkouA = indicatorHistory.Select(x => ((dynamic)x).SenkouA).ToList();
var senkouB = indicatorHistory.Select(x => ((dynamic)x).SenkouB).ToList();
var chikou = indicatorHistory.Select(x => ((dynamic)x).Chikou).ToList();
var tenkanMaximum = indicatorHistory.Select(x => ((dynamic)x).TenkanMaximum).ToList();
var tenkanMinimum = indicatorHistory.Select(x => ((dynamic)x).TenkanMinimum).ToList();
var kijunMaximum = indicatorHistory.Select(x => ((dynamic)x).KijunMaximum).ToList();
var kijunMinimum = indicatorHistory.Select(x => ((dynamic)x).KijunMinimum).ToList();
var senkouBMaximum = indicatorHistory.Select(x => ((dynamic)x).SenkouBMaximum).ToList();
var senkouBMinimum = indicatorHistory.Select(x => ((dynamic)x).SenkouBMinimum).ToList();
var delayedTenkanSenkouA = indicatorHistory.Select(x => ((dynamic)x).DelayedTenkanSenkouA).ToList();
var delayedKijunSenkouA = indicatorHistory.Select(x => ((dynamic)x).DelayedKijunSenkouA).ToList();
var delayedMaximumSenkouB = indicatorHistory.Select(x => ((dynamic)x).DelayedMaximumSenkouB).ToList();
var delayedMinimumSenkouB = indicatorHistory.Select(x => ((dynamic)x).DelayedMinimumSenkouB).ToList();
}
} class IchimokuKinkoHyoAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._ichimoku = self.ichimoku(self._symbol, 9, 26, 17, 52, 26, 26)
indicator_history = self.indicator_history(self._ichimoku, self._symbol, 100, Resolution.MINUTE)
timedelta_indicator_history = self.indicator_history(self._ichimoku, self._symbol, timedelta(days=10), Resolution.MINUTE)
time_period_indicator_history = self.indicator_history(self._ichimoku, self._symbol, datetime(2024, 7, 1), datetime(2024, 7, 5), Resolution.MINUTE)
# Access all attributes of indicator_history
indicator_history_df = indicator_history.data_frame
tenkan = indicator_history_df["tenkan"]
kijun = indicator_history_df["kijun"]
senkou_a = indicator_history_df["senkoua"]
senkou_b = indicator_history_df["senkoub"]
chikou = indicator_history_df["chikou"]
tenkan_maximum = indicator_history_df["tenkanmaximum"]
tenkan_minimum = indicator_history_df["tenkanminimum"]
kijun_maximum = indicator_history_df["kijunmaximum"]
kijun_minimum = indicator_history_df["kijunminimum"]
senkou_b_maximum = indicator_history_df["senkoubmaximum"]
senkou_b_minimum = indicator_history_df["senkoubminimum"]
delayed_tenkan_senkou_a = indicator_history_df["delayedtenkansenkoua"]
delayed_kijun_senkou_a = indicator_history_df["delayedkijunsenkoua"]
delayed_maximum_senkou_b = indicator_history_df["delayedmaximumsenkoub"]
delayed_minimum_senkou_b = indicator_history_df["delayedminimumsenkoub"]