Supported Indicators

Vortex

Introduction

This indicator represents the Vortex Indicator, which identifies the start and continuation of market trends. It includes components that capture positive (upward) and negative (downward) trend movements. This indicator compares the ranges within the current period to previous periods to calculate upward and downward movement trends.

To view the implementation of this indicator, see the LEAN GitHub repository.

Using VTX Indicator

To create an automatic indicator for Vortex, call the VTXvtx helper method from the QCAlgorithm class. The VTXvtx method creates a Vortex 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 VortexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Vortex _vtx;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _vtx = VTX(_symbol, 14);
    }

    public override void OnData(Slice data)
    {

        if (_vtx.IsReady)
        {
            // The current value of _vtx is represented by itself (_vtx)
            // or _vtx.Current.Value
            Plot("Vortex", "vtx", _vtx);
            // Plot all properties of abands
            Plot("Vortex", "plusvortex", _vtx.PlusVortex);
            Plot("Vortex", "minusvortex", _vtx.MinusVortex);
        }
    }
}
class VortexAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._vtx = self.vtx(self._symbol, 14)

    def on_data(self, slice: Slice) -> None:

        if self._vtx.is_ready:
            # The current value of self._vtx is represented by self._vtx.current.value
            self.plot("Vortex", "vtx", self._vtx.current.value)
            # Plot all attributes of self._vtx
            self.plot("Vortex", "plus_vortex", self._vtx.plus_vortex.current.value)
            self.plot("Vortex", "minus_vortex", self._vtx.minus_vortex.current.value)

For more information about this method, see the QCAlgorithm classQCAlgorithm class.

You can manually create a Vortex 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 VortexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Vortex _vortex;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _vortex = new Vortex(14);
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
            _vortex.Update(bar);

        if (_vortex.IsReady)
        {
            // The current value of _vortex is represented by itself (_vortex)
            // or _vortex.Current.Value
            Plot("Vortex", "vortex", _vortex);
            // Plot all properties of abands
            Plot("Vortex", "plusvortex", _vortex.PlusVortex);
            Plot("Vortex", "minusvortex", _vortex.MinusVortex);
        }
    }
}
class VortexAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._vortex = Vortex(14)

    def on_data(self, slice: Slice) -> None:
        bar = slice.bars.get(self._symbol)
        if bar:
            self._vortex.update(bar)

        if self._vortex.is_ready:
            # The current value of self._vortex is represented by self._vortex.current.value
            self.plot("Vortex", "vortex", self._vortex.current.value)
            # Plot all attributes of self._vortex
            self.plot("Vortex", "plus_vortex", self._vortex.plus_vortex.current.value)
            self.plot("Vortex", "minus_vortex", self._vortex.minus_vortex.current.value)

For more information about this indicator, see its referencereference.

Visualization

The following plot shows values for some of the Vortex indicator properties:

Vortex line plot.

Indicator History

To get the historical data of the Vortex 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 VortexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Vortex _vtx;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _vtx = VTX(_symbol, 14);

        var indicatorHistory = IndicatorHistory(_vtx, _symbol, 100, Resolution.Minute);
        var timeSpanIndicatorHistory = IndicatorHistory(_vtx, _symbol, TimeSpan.FromDays(10), Resolution.Minute);
        var timePeriodIndicatorHistory = IndicatorHistory(_vtx, _symbol, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);

        // Access all attributes of indicatorHistory
        var plusVortex = indicatorHistory.Select(x => ((dynamic)x).PlusVortex).ToList();
        var minusVortex = indicatorHistory.Select(x => ((dynamic)x).MinusVortex).ToList();
    }
}
class VortexAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._vtx = self.vtx(self._symbol, 14)

        indicator_history = self.indicator_history(self._vtx, self._symbol, 100, Resolution.MINUTE)
        timedelta_indicator_history = self.indicator_history(self._vtx, self._symbol, timedelta(days=10), Resolution.MINUTE)
        time_period_indicator_history = self.indicator_history(self._vtx, 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
        plus_vortex = indicator_history_df["plusvortex"]
        minus_vortex = indicator_history_df["minusvortex"]

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: