Supported Indicators
Wave Trend Oscillator
Introduction
The WaveTrend Oscillator (WTO) is a momentum indicator that highlights overbought and oversold conditions by measuring how far the typical price has deviated from a smoothed moving average, normalized by an exponentially smoothed mean absolute deviation. The oscillator's main line (WT1) is an EMA of this normalized channel index, and the signal line (WT2) is an SMA of WT1; crossovers between the two lines are commonly used as entry and exit signals. Formula: HLC3 = (High + Low + Close) / 3 ESA = EMA(HLC3, channelPeriod) D = EMA(|HLC3 - ESA|, channelPeriod) CI = (HLC3 - ESA) / (0.015 * D) WT1 = EMA(CI, averagePeriod) (the indicator's Current.Value) WT2 = SMA(WT1, signalPeriod) (exposed via
To view the implementation of this indicator, see the LEAN GitHub repository.
Using WTO Indicator
To create an automatic indicator for WaveTrendOscillator, call the WTOwto helper method from the QCAlgorithm class. The WTOwto method creates a WaveTrendOscillator 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 WaveTrendOscillatorAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private WaveTrendOscillator _wto;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_wto = WTO(_symbol, 10, 21, 4);
}
public override void OnData(Slice data)
{
if (_wto.IsReady)
{
// The current value of _wto is represented by itself (_wto)
// or _wto.Current.Value
Plot("WaveTrendOscillator", "wto", _wto);
// Plot all properties of abands
Plot("WaveTrendOscillator", "channelaverage", _wto.ChannelAverage);
Plot("WaveTrendOscillator", "channeldeviation", _wto.ChannelDeviation);
Plot("WaveTrendOscillator", "channelindexaverage", _wto.ChannelIndexAverage);
Plot("WaveTrendOscillator", "signal", _wto.Signal);
}
}
} class WaveTrendOscillatorAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._wto = self.wto(self._symbol, 10, 21, 4)
def on_data(self, slice: Slice) -> None:
if self._wto.is_ready:
# The current value of self._wto is represented by self._wto.current.value
self.plot("WaveTrendOscillator", "wto", self._wto.current.value)
# Plot all attributes of self._wto
self.plot("WaveTrendOscillator", "channel_average", self._wto.channel_average.current.value)
self.plot("WaveTrendOscillator", "channel_deviation", self._wto.channel_deviation.current.value)
self.plot("WaveTrendOscillator", "channel_index_average", self._wto.channel_index_average.current.value)
self.plot("WaveTrendOscillator", "signal", self._wto.signal.current.value)For more information about this method, see the QCAlgorithm classQCAlgorithm class.
You can manually create a WaveTrendOscillator 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 WaveTrendOscillatorAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private WaveTrendOscillator _wavetrendoscillator;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_wavetrendoscillator = new WaveTrendOscillator(10, 21, 4);
}
public override void OnData(Slice data)
{
if (data.Bars.TryGetValue(_symbol, out var bar))
_wavetrendoscillator.Update(bar);
if (_wavetrendoscillator.IsReady)
{
// The current value of _wavetrendoscillator is represented by itself (_wavetrendoscillator)
// or _wavetrendoscillator.Current.Value
Plot("WaveTrendOscillator", "wavetrendoscillator", _wavetrendoscillator);
// Plot all properties of abands
Plot("WaveTrendOscillator", "channelaverage", _wavetrendoscillator.ChannelAverage);
Plot("WaveTrendOscillator", "channeldeviation", _wavetrendoscillator.ChannelDeviation);
Plot("WaveTrendOscillator", "channelindexaverage", _wavetrendoscillator.ChannelIndexAverage);
Plot("WaveTrendOscillator", "signal", _wavetrendoscillator.Signal);
}
}
} class WaveTrendOscillatorAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._wavetrendoscillator = WaveTrendOscillator(10, 21, 4)
def on_data(self, slice: Slice) -> None:
bar = slice.bars.get(self._symbol)
if bar:
self._wavetrendoscillator.update(bar)
if self._wavetrendoscillator.is_ready:
# The current value of self._wavetrendoscillator is represented by self._wavetrendoscillator.current.value
self.plot("WaveTrendOscillator", "wavetrendoscillator", self._wavetrendoscillator.current.value)
# Plot all attributes of self._wavetrendoscillator
self.plot("WaveTrendOscillator", "channel_average", self._wavetrendoscillator.channel_average.current.value)
self.plot("WaveTrendOscillator", "channel_deviation", self._wavetrendoscillator.channel_deviation.current.value)
self.plot("WaveTrendOscillator", "channel_index_average", self._wavetrendoscillator.channel_index_average.current.value)
self.plot("WaveTrendOscillator", "signal", self._wavetrendoscillator.signal.current.value)For more information about this indicator, see its referencereference.
Indicator History
To get the historical data of the WaveTrendOscillator 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 WaveTrendOscillatorAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private WaveTrendOscillator _wto;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_wto = WTO(_symbol, 10, 21, 4);
var indicatorHistory = IndicatorHistory(_wto, _symbol, 100, Resolution.Minute);
var timeSpanIndicatorHistory = IndicatorHistory(_wto, _symbol, TimeSpan.FromDays(10), Resolution.Minute);
var timePeriodIndicatorHistory = IndicatorHistory(_wto, _symbol, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);
// Access all attributes of indicatorHistory
var channelAverage = indicatorHistory.Select(x => ((dynamic)x).ChannelAverage).ToList();
var channelDeviation = indicatorHistory.Select(x => ((dynamic)x).ChannelDeviation).ToList();
var channelIndexAverage = indicatorHistory.Select(x => ((dynamic)x).ChannelIndexAverage).ToList();
var signal = indicatorHistory.Select(x => ((dynamic)x).Signal).ToList();
}
} class WaveTrendOscillatorAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._wto = self.wto(self._symbol, 10, 21, 4)
indicator_history = self.indicator_history(self._wto, self._symbol, 100, Resolution.MINUTE)
timedelta_indicator_history = self.indicator_history(self._wto, self._symbol, timedelta(days=10), Resolution.MINUTE)
time_period_indicator_history = self.indicator_history(self._wto, 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
channel_average = indicator_history_df["channelaverage"]
channel_deviation = indicator_history_df["channeldeviation"]
channel_index_average = indicator_history_df["channelindexaverage"]
signal = indicator_history_df["signal"]