Vortex Cross with Moving Average strategy in Pine Script
A cross of the two Vortex lines, confirmed by the price against a smoothed moving average.
Vortex Indicator · SMA · long and short · by DraftVenture · Mozilla Public License 2.0
What is its backtest worth?
A parameter sweep finds the best setting of the Vortex Cross with Moving Average strategy. PineTester tells you if it holds up: whether the best result was only picked after the fact, what it makes with fees, what you could have known at the time (a walk-forward on data the pick did not see) and how deep it fell along the way. On the free start, your first own backtest gets the full evaluation; its trade list and result file come with the full report or a plan.
Creates a draft on Binance BTC/USDT 4h over about six and a half years with 0.1% commission per order and 2 ticks slippage; you start it yourself. A backtest uses credits; new accounts receive free credits.
The rules
- Enters long when VI+ crosses above VI− and the close is above the smoothed moving average; short when VI+ crosses below VI− and the close is below it.
- Has no separate exit: each opposite signal turns the position around.
What to watch for
- Always in the market once it started; the trade count and the fees decide much of the result.
- The Vortex lines cross often in sideways markets – look at the years without a clear trend.
How PineTester judges a backtest, with its sources: how we judge results.
The Pine Script code
The author's code with its licence notice (Mozilla Public License 2.0), with one change marked in the code: the same test conditions for every library strategy in its strategy() line – the whole account per trade (split over the entries where it adds to a position), 0.1% commission per order and 2 ticks slippage; the trading rules are unchanged. Pine Script v5; PineTester converts it to v6 automatically, so results can differ slightly from TradingView.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DraftVenture
// Modified by PineTester (2026-11-14): the same test conditions for every library strategy in strategy(): 100% of equity per entry,
// 0.1% commission per order, 2 ticks slippage, initial capital 10,000. The trading rules are unchanged.
//@version=5
strategy("Vortex + Moving Average Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)
//Vortex settings
period_ = input.int(14, title="Vortex Length", minval=2)
VMP = math.sum( math.abs( high - low[1]), period_ )
VMM = math.sum( math.abs( low - high[1]), period_ )
STR = math.sum( ta.atr(1), period_ )
VIP = VMP / STR
VIM = VMM / STR
plot(VIP, title="VI +", color=color.white)
plot(VIM, title="VI -", color=color.white)
len = input.int(9, minval=1, title="MA Length")
src = input(close, title="Source")
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out = ta.sma(src, len)
plot(out, color=color.blue, title="MA", offset=offset)
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing")
smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing")
smoothingLine = ma(out, smoothingLength, typeMA)
plot(smoothingLine, title="Smoothing Line", color=#f37f20, offset=offset, display=display.none)
// Determine long and short conditions
longCondition = ta.crossover(VIP, VIM) and close > smoothingLine
shortCondition = ta.crossunder(VIP, VIM) and close < smoothingLine
crossCondition = ta.crossunder(VIP, VIM) or ta.crossunder(VIM, VIP)
// Strategy entry and exit logic
if longCondition
strategy.entry("Long", strategy.long)
if shortCondition
strategy.entry("Short", strategy.short)
bgcolor(crossCondition ? color.new(color.white, 80) : na)
// Strategy by KP
Related strategies
- Donchian Breakout + MA – A Donchian channel breakout in the direction of two moving averages, closed when the averages cross back.
- Gann HiLo Activator – Flips between long and short when the close leaves the moving averages of the highs and the lows.
- Flying Dragon Trend – The price against a Hull moving average shifted a few bars to the right decides the side of the trade.
- Darvas Box – A break out of the Darvas box in the direction of a slow weighted average, with the other side of the box as stop.
Open-source script by DraftVenture, shown under the Mozilla Public License 2.0. Not a recommendation; neither the author nor TradingView endorses PineTester. Backtests are hypothetical results on past data, not a forecast.