0bps

Strategy vault / Trend following

The Vortex Oscillator Trend Following Strategy

The Vortex Oscillator trend following strategy is a trend tracking strategy based on the Vortex Indicator. It uses moving averages of multiple timeframes to construct the Vortex Indicator to identify potential price…

Author
ChaoZhang
Complexity
Intermediate · 106 lines
Parameters
15
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

The Vortex Oscillator trend following strategy is a trend tracking strategy based on the Vortex Indicator. It uses moving averages of multiple timeframes to construct the Vortex Indicator to identify potential price trends, and combines with a shorter-period moving average as an auxiliary judgment to achieve low-risk trend tracking operations.

Strategy Principle

The core indicator of this strategy is the Vortex Indicator. The Vortex Indicator consists of short-term, medium-term and long-term moving averages of multiple timeframes. Specifically, the strategy uses moving averages of 6 days, 27 days, 72 days and 234 days. The short-term moving average reflects the latest trend of prices, while the long-term moving average reflects the long-term trend. The core logic of the indicator is that when the short-term moving average crosses above the long-term moving average, it indicates that the upside momentum is strengthening and it's time to buy. When the short-term moving average crosses below the long-term moving average, it indicates that the upside momentum is weakening and we should sell.

The significant advantage of the Vortex Indicator is that it accurately judges trends and effectively filters out market noise. However, its reaction is not sensitive enough to capture turning points in a timely manner. Therefore, the strategy incorporates a more sensitive 6-day moving average to construct an auxiliary judgment indicator. Buy when both the Vortex Indicator and the auxiliary indicator cross above the zero line, and sell when both indicators cross below the zero line. This forms a multi-confirmation logic where the Vortex Indicator determines the trend direction and strength while the auxiliary indicator determines specific entry and exit points, which filters out false signals while improving the sensitivity of operations.

Advantage Analysis

The biggest advantage of this strategy is the accuracy of judgment and sensitivity of operations. The combination of the Vortex Indicator and auxiliary indicators achieves an organic unity of trend judgment and determination of specific entry/exit points while avoiding interference with each other. The multi-confirmation mechanism can effectively filter out market noise and avoid wrong trades. At the same time, the addition of the auxiliary indicator also ensures the sensitivity of the strategy's operations.

Compared with single indicator strategies, the advantage of this strategy is that it combines multiple indicators to achieve stronger capabilities in identifying and responding to market changes. Under an unchanged major trend, the strategy can achieve steady profits. When major trends change, the strategy can also respond quickly to reduce losses.

Risk Analysis

The main risks of this strategy come from improper parameter settings of indicators and the impact of extreme events. The parameters of moving averages need to balance sensitivity and noise interference resistance. Improper parameter settings will lead to abnormal strategy behavior. In addition, major events could also cause extreme price volatility that disables indicators, resulting in wrong trades.

To mitigate these risks, parameters should be optimized and backtested to stabilize indicator performance. Also, pay close attention to market impacts from major events, pause strategies when necessary to avoid mistakes during abnormal volatility periods. As prices trend down, gradually reducing positions is also an effective capital preservation measure.

Optimization Directions

The strategy can be optimized in the following aspects:

  1. Optimize moving average parameters to improve indicator's noise resistance and operation sensitivity. Try different parameter combinations for lengths to select smooth yet sensitive indicators.

  2. Add stop loss mechanisms. Set stop loss points when prices break key support levels in unfavorable directions to avoid further losses.

  3. Incorporate other indicator judgments to increase strategy stability, e.g. only taking signals when trading volumes amplify.

  4. Use different parameter sets based on different market stages. For example, more aggressive parameters during bull markets, and more stable settings in bear markets.

Conclusion

The Vortex Oscillator Trend Following Strategy successfully combines trend judgment and execution through the Vortex Indicator determining price trend direction/strength and a sensitive short-term moving average pinpointing specific entry/exit timing. By optimizing parameters, adding stop losses, and introducing state mechanisms, the strategy has the potential to further enhance its risk resistance capabilities and achieve superior backtesting metrics and live performance.

Parameters

NameDefaultWhat it controls
v_input_12017Backtest Start Year
v_input_2trueBacktest Start Month
v_input_32Backtest Start Day
v_input_42048Backtest Stop Year
v_input_57Backtest Stop Month
v_input_630Backtest Stop Day
v_input_7trueColor Background?
v_input_86short_input
v_input_927long_input
v_input_1072longer_input
v_input_11234longest_input
v_input_123hist_fractal
v_input_132longhist_fractal
v_input_144longesthist_fractal
v_input_156Micro EMA Length

Source Pine Script

/*backtest
start: 2022-11-30 00:00:00
end: 2023-12-06 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
//swap strategy line for study line to enable backtesting
strategy(title="Vortex Ocillator" )
//study(title = "Vortex Oscillator", precision = 6)

// Component Code Start
// Example usage:
// if testPeriod()
//   strategy.entry("LE", strategy.long)
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(2, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2048, "Backtest Stop Year")
testStopMonth = input(7, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)

testPeriod() => true
// Component Code Stop

//vortex histogram
short_input = input(6, minval = 1)
long_input = input(27, minval = 1)
longer_input = input(72, minval = 1)
longest_input = input(234, minval = 1)

short = sma(close, short_input)
long = sma(close, long_input)
longer = sma(close, longer_input)
longest = sma(close, longest_input)

hist = short - long
longhist = short - longer
longesthist = short - longest

hist_fractal = input(3, minval = 0)
longhist_fractal = input(2, minval = 0)
longesthist_fractal = input(4, minval = 0)

vortexhist = avg((hist / hist_fractal), (longhist / longhist_fractal), (longesthist / longesthist_fractal))

crossover_calc = vortexhist > 0 and vortexhist[1] < 0
crossunder_calc = vortexhist < 0 and vortexhist[1] > 0

crossover2 = crossover(vortexhist, 0)
crossunder2 = crossunder(vortexhist, 0)

hist_color = hist > 0? fuchsia : purple
longhist_color = longhist > 0? olive : orange
longesthist_color = longesthist > 0? teal : blue
vortexhist_color = vortexhist >= 0? green : red

plot(longesthist, "Longest Ocillator", style = histogram, color = longesthist_color, transp = 5)
plot(longhist, "Longer Ocillator", style = histogram, color = longhist_color, transp = 30)
plot(hist, "Short Ocillator", style = histogram, color = hist_color, transp = 30)
plot(vortexhist, "Vortex Ocillator", style = columns, color = vortexhist_color, transp = 40)
plotshape(crossover_calc,title = "Crossover",location = location.bottom, style = shape.triangleup, size = size.small, color = green)
plotshape(crossunder_calc,title = "Crossunder",location = location.bottom, style = shape.triangledown, size = size.small, color = red)

//micro
micro_ema_length = input(6,"Micro EMA Length")
micro = ema(vortexhist, micro_ema_length)
plot(micro, title = "micro", linewidth = 1, color = white)
microup = crossover(vortexhist, micro)
microdown = crossunder(vortexhist, micro)

//new micro signals
xmicroup = microup and vortexhist >=0 or crossover_calc
xmicrodown = microdown and vortexhist >=0 or crossunder_calc
plotshape(xmicroup, title = "Micro up", style = shape.circle, color = olive, location = location.bottom, size = size.tiny)
plotshape(xmicrodown, title = "Micro down", style = shape.circle, color = fuchsia, location = location.bottom, size = size.tiny)

//optional strategy options for backtesting, comment out the alertcondition rows and swap the top study row for the strategy row to compile as strategy
if testPeriod()
    strategy.entry("buy", true, 1, when = xmicroup, limit = low)
if testPeriod()
    strategy.close("buy", when = xmicrodown)

   

//if (xmicroup)
    //strategy.entry("My Long Entry Id", strategy.long)
//if (xmicroup)
    //strategy.exit("My Short Exit Id", "My Short Entry Id")
//if (xmicrodown)
    //strategy.exit("My Long Exit Id", "My Long Entry Id")

  


Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-07. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/The-Vortex-Oscillator-Trend-Following-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open