Supported Indicators
Klinger Volume Oscillator
Introduction
The Klinger Volume Oscillator (KVO) is a technical indicator that analyzes the relationship between price movement and trading volume to assess the strength of market trends and identify potential trend reversals. As a volume-based oscillator, it measures the force behind price movements by incorporating volume data adjusted for price trends and specific conditions. Traders use the KVO to analyze its behavior relative to price action, looking for patterns such as divergences or crossovers that can provide insights into market trends and potential turning points.
To view the implementation of this indicator, see the LEAN GitHub repository.
Using KVO Indicator
To create an automatic indicator for KlingerVolumeOscillator, call the KVOkvo helper method from the QCAlgorithm class. The KVOkvo method creates a KlingerVolumeOscillator 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 KlingerVolumeOscillatorAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private KlingerVolumeOscillator _kvo;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_kvo = KVO(_symbol, 5, 10, 13);
}
public override void OnData(Slice data)
{
if (_kvo.IsReady)
{
// The current value of _kvo is represented by itself (_kvo)
// or _kvo.Current.Value
Plot("KlingerVolumeOscillator", "kvo", _kvo);
// Plot all properties of abands
Plot("KlingerVolumeOscillator", "signal", _kvo.Signal);
}
}
} class KlingerVolumeOscillatorAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._kvo = self.kvo(self._symbol, 5, 10, 13)
def on_data(self, slice: Slice) -> None:
if self._kvo.is_ready:
# The current value of self._kvo is represented by self._kvo.current.value
self.plot("KlingerVolumeOscillator", "kvo", self._kvo.current.value)
# Plot all attributes of self._kvo
self.plot("KlingerVolumeOscillator", "signal", self._kvo.signal.current.value)For more information about this method, see the QCAlgorithm classQCAlgorithm class.
You can manually create a KlingerVolumeOscillator 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 KlingerVolumeOscillatorAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private KlingerVolumeOscillator _klingervolumeoscillator;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_klingervolumeoscillator = new KlingerVolumeOscillator(5, 10, 13);
}
public override void OnData(Slice data)
{
if (data.Bars.TryGetValue(_symbol, out var bar))
_klingervolumeoscillator.Update(bar);
if (_klingervolumeoscillator.IsReady)
{
// The current value of _klingervolumeoscillator is represented by itself (_klingervolumeoscillator)
// or _klingervolumeoscillator.Current.Value
Plot("KlingerVolumeOscillator", "klingervolumeoscillator", _klingervolumeoscillator);
// Plot all properties of abands
Plot("KlingerVolumeOscillator", "signal", _klingervolumeoscillator.Signal);
}
}
} class KlingerVolumeOscillatorAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._klingervolumeoscillator = KlingerVolumeOscillator(5, 10, 13)
def on_data(self, slice: Slice) -> None:
bar = slice.bars.get(self._symbol)
if bar:
self._klingervolumeoscillator.update(bar)
if self._klingervolumeoscillator.is_ready:
# The current value of self._klingervolumeoscillator is represented by self._klingervolumeoscillator.current.value
self.plot("KlingerVolumeOscillator", "klingervolumeoscillator", self._klingervolumeoscillator.current.value)
# Plot all attributes of self._klingervolumeoscillator
self.plot("KlingerVolumeOscillator", "signal", self._klingervolumeoscillator.signal.current.value)For more information about this indicator, see its referencereference.
Indicator History
To get the historical data of the KlingerVolumeOscillator 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 KlingerVolumeOscillatorAlgorithm : QCAlgorithm
{
private Symbol _symbol;
private KlingerVolumeOscillator _kvo;
public override void Initialize()
{
_symbol = AddEquity("SPY", Resolution.Daily).Symbol;
_kvo = KVO(_symbol, 5, 10, 13);
var indicatorHistory = IndicatorHistory(_kvo, _symbol, 100, Resolution.Minute);
var timeSpanIndicatorHistory = IndicatorHistory(_kvo, _symbol, TimeSpan.FromDays(10), Resolution.Minute);
var timePeriodIndicatorHistory = IndicatorHistory(_kvo, _symbol, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);
// Access all attributes of indicatorHistory
var signal = indicatorHistory.Select(x => ((dynamic)x).Signal).ToList();
}
} class KlingerVolumeOscillatorAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
self._kvo = self.kvo(self._symbol, 5, 10, 13)
indicator_history = self.indicator_history(self._kvo, self._symbol, 100, Resolution.MINUTE)
timedelta_indicator_history = self.indicator_history(self._kvo, self._symbol, timedelta(days=10), Resolution.MINUTE)
time_period_indicator_history = self.indicator_history(self._kvo, 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
signal = indicator_history_df["signal"]