We collect cookies to improve your browsing experience. By using our site, you agree to ourPrivacy Policy andTerms of Service.

Summary:
Hello chiefs. On the docket this time are 3 strategies involving the Vortex indicator, which is a trend-following technical indicator that measures buying and selling pressure using two oscillating lines: the Positive Vortex (VI+) and Negative Vortex (VI−). When VI+ crosses above VI− it suggests bullish momentum, while a crossover below indicates bearish momentum. Traders use the indicator to identify trend direction, potential reversals, and the strength of emerging market moves.
As usual we have settled on the Nasdaq 100 index (QQQ) for our backtest, with 10 years worth of daily OHLC bars downloaded from Yahoo Finance into a dataframe named df, and the backtest itself is run using the backtesting.py library. We will show you how to calculate the indicator, apply it to price, generate trading signals, then run a full backtest and output the results.
The completed codebook along with our backtesting template can be downloaded via our GitHub profile, but for more detailed coding instruction you can refer to the video on our YouTube channel which shows you how to construct it from start to finish. Please note that the article strategy is for infotainment purposes only and should not be construed as financial advice.
Calculating The Vortex Indicator
The Vortex Indicator is constructed by measuring the distance between the current high and previous low (positive movement) and the current low and previous high (negative movement) for each bar. These values are added together over a chosen rolling lookback period and normalised by the sum of the True Range over the same rolling period, producing the Positive Vortex (VI+) and Negative Vortex (VI−) lines.
The code is as follows:
def VORTEX(data, n): pos_vm = abs(data['High'] - data['Low'].shift(1)) neg_vm = abs(data['Low'] - data['High'].shift(1)) pos_vm_sum = pos_vm.rolling(n).sum() neg_vm_sum = neg_vm.rolling(n).sum() meth1 = (data['High'] - data['Low']) meth2 = abs(data['High'] - data['Close'].shift(1)) meth3 = abs(data['Low'] - data['Close'].shift(1)) tr = abs(np.maximum(np.maximum(meth1, meth2), meth3)) tr_sum = tr.rolling(n).sum() vibull = pos_vm_sum / tr_sum vibear = neg_vm_sum / tr_sum return vibull, vibear df['VIBULL'], df['VIBEAR'] = VORTEX(df, 14)Conventional wisdom says that traders should buy when the VI+ line crosses above the VI- line, and sell when it crosses back below, so we have tested that strategy, going long at the open following a buy signal, then closing that long position when a sell signal came.
To generate buy and sell signals within our code book, we ran a loop over our dataset looking for yesterday's VI+ line to be below yesterday's VI- line, and today's VI+ line to be back above (buy signal), and yesterday's VI+ line to be above yesterday's VI- line, and today's VI+ line to be below (sell signal). Code as follows:
def signal(data): signal = [0] * len(df) for i in range(2,len(df)): if (data['VIBULL'].iloc[i-1] < data['VIBEAR'].iloc[i-1]) &\ (data['VIBULL'].iloc[i] > data['VIBEAR'].iloc[i]): signal[i] = 1 elif (data['VIBULL'].iloc[i-1] > data['VIBEAR'].iloc[i-1]) &\ (data['VIBULL'].iloc[i] < data['VIBEAR'].iloc[i]): signal[i] = 2 else: signal[i] = 0 df["signal"] = signal signal(df)With our buy and sell signals now contained within our dataset, we generated a price chart for QQQ with the Vortex indicator below, and buy signals rendered as white dots, with sell signals marked by yellow dots. Chart as follows:

We then ran a backtest on QQQ (daily timeframe) over 10 years, utilising a 2% stop loss and a hefty 12% profit target on our long positions, equating to a mighty 6:1 risk to reward ratio. We sold our long positions when either the stop/profit targets were hit or we received a sell signal, but we never flipped short. The results were respectable, generating a 281% overall return, with a low maximum drawdown figure. Full strategy stats are as follows:

We were feeling fairly underwhelmed by the results, so decided to play with the Vortex indicator lines a little, first by calculating the spread between the VI+ and VI- lines, then calculating the 9-period spread momentum. In the code along video you can see what these 2 different lines looked like on the chart, but for now you'll have to use your imagination.
Finally we settled on creating a smoothed version of that VI+ / VI- spread momentum calculation, applying an 8-period rolling average to it that produced a much smoother and more useful indicator line. The calculation code is as follows:
df['spread'] = (df['VIBULL'] - df['VIBEAR'])df['spread_mom'] = (df['spread'] - df['spread'].shift(9))df['smooth_mom'] = df['spread_mom'].rolling(8).mean()So with our customised indicator calculation in place, we then amended our signal calculation, with buy signals coming when our new smoothed momentum line turned higher while below the zero line, and our sell signals being generated when the smoothed momentum line crossed below zero. Code as follows:
def signal(data): signal = [0] * len(df) for i in range(2,len(df)): if (data['smooth_mom'].iloc[i] > data['smooth_mom'].iloc[i-1]) &\ (data['smooth_mom'].iloc[i-1] < data['smooth_mom'].iloc[i-2]) &\ (data['smooth_mom'].iloc[i] < 0): signal[i] = 1 elif (data['smooth_mom'].iloc[i-1] > 0) and (data['smooth_mom'].iloc[i] < 0): signal[i] = 2 else: signal[i] = 0 df["signal"] = signal signal(df)With our new indicator calculation and signal generation logic in place, we re-rendered our chart to show the difference in the indicator and where the new signals came. This methodology has you buying closer to the low rand more frequently, but our sell signals were still a little haphazard. Chart as follows:

We then ran another backtest, again on QQQ (daily timeframe) over 10 years, this time utilising no profit target on the long side and closing out long trades only when a sell signal. We opted not to short the market on sell signals. Our new long only strategy saw the results improve, generating a 410% overall return with a 67% win rate. Full strategy stats are as follows:

How to Exploit This Indicator
To make the most of this strategy, we wanted to pick out points where the smoothed momentum line was at a relative extreme. To do that we created Bolinger Bands based on our smoothed momentum line and overlaid the upper and lower bands onto our indicator. The code to generate this is as follows:
def BANDS(data, n1, n2, n3): sv = data['smooth_mom'] std = sv.rolling(n1).std() mid = sv.rolling(n1).mean() up = mid + std * n2 lo = mid - std * n3 return up, lo
df['upper'], df['lower'] = BANDS(df, 20, 2, 2)This generated a 3 line indicator, with our smoothed momentum line now rendered in white, the upper band in red, and the lower band in green. Our next strategy variation would be to buy when yesterday's smoothed momentum line was below the lower band, and today's smoothed momentum line was back above. A sell signal came when yesterday's smoothed momentum line was above the upper band, and today's was back below.
The results in terms of accurate buy and sell signals was very good, but there just wasn't enough of them to validate a strategy, so for an additional buy signal we included the prior methodology of buying when the smoothed momentum line turns up from below zero. The strategy calculation code is below:
def signal(data): signal = [0] * len(df) for i in range(2,len(df)): if (data['smooth_mom'].iloc[i-1] < data['lower'].iloc[i-1]) &\ (data['smooth_mom'].iloc[i] > data['lower'].iloc[i]): signal[i] = 1 elif (data['smooth_mom'].iloc[i-1] > data['upper'].iloc[i-1]) &\ (data['smooth_mom'].iloc[i] < data['upper'].iloc[i]): signal[i] = 2 elif (data['smooth_mom'].iloc[i] > data['smooth_mom'].iloc[i-1]) &\ (data['smooth_mom'].iloc[i-1] < data['smooth_mom'].iloc[i-2]) &\ (data['smooth_mom'].iloc[i] < 0): signal[i] = 3 else: signal[i] = 0 df["signal"] = signal signal(df)The recreated chart with smoothed momentum bands indicator is rendered below. The white dot buy signals and the gold dot sell signals came from using the bands strategy; the blue dot buy signals came from our smoothed momentum line turning up:

We then ran our final backtest, with white buy signals being sold only when a sell signal occurred; blue buy signals having a 2% profit target and no stop loss; and this time flipping short on every sell signal with a 2% stop and 10% profit target. Over 85 trades the strategy returned 745%, with an excellent maximum drawdown figure of just -23%, and a 64% win rate. Stats are as follows:

A profit and loss graph is included below showing that it performed well over the 2021-2022 bear market period. However, while in general it has done well, we don't really have enough trades to be confident in it, and you may want to backtest over a longer period of time.

As always, further parameter optimisation, regime filtering, or volatility targeting may improve performance. This article strategy is presented for educational purposes only and should not be considered financial advice. For a detailed run through of the codebook, please watch the video below.
Looking for algorithmic trading signals? Bubble Analytics provides real-time trade notifications generated by systematically tested strategies, complete with detailed performance statistics, trade histories and risk metrics. Explore our live trading signals and start your free 30-day trial today. ->
01-Dec-2026

30-Nov-2026

21-Nov-2026

14-Nov-2026

07-Nov-2026

04-Nov-2026

02-Nov-2026

01-Nov-2026

28-Oct-2026

24-Oct-2026

17-Oct-2026

14-Oct-2026

10-Oct-2026

07-Oct-2026

03-Oct-2026

01-Oct-2026

30-Sept-2026

01-Sept-2026

21-Jun-2026

14-Jun-2026

08-Jun-2026

01-Jun-2026

24-May-2026

17-May-2026

10-May-2026

03-May-2026

26-Apr-2026