VSTOP and RSI Trading Strategy
This strategy combines the VSTOP and RSI indicators to go long when RSI is overbought and go short when RSI is oversold, while using VSTOP to determine the trend direction and cut losses in time when the trend reverses.
Overview
This strategy combines the VSTOP and RSI indicators to go long when RSI is overbought and go short when RSI is oversold, while using VSTOP to determine the trend direction and cut losses in time when the trend reverses.
Strategy Logic
Calculate the RSI indicator value and set overbought and oversold lines. Go long when RSI is above the overbought line and go short when RSI is below the oversold line.
Calculate the VSTOP, which is a stop loss line based on price fluctuation range. The calculation steps are as follows:
Calculate the ATR indicator and set the ATR coefficient mult
Record the max price and min price
According to the uptrend state is_uptrend, calculate the current stop loss line: stop = is_uptrend ? max - mult * ATR : min + mult * ATR
Update the stop loss line: vstop1 = is_uptrend ? max(vstop_prev, stop) : min(vstop_prev, stop)
When trend reversal happens, reset the stop loss line vstop
When RSI is oversold, if price crosses above VSTOP, go short; when RSI is overbought, go long.
Advantage Analysis
Combining trend indicator and overbought/oversold indicator helps capture reversal opportunities in trending markets.
Using VSTOP to set stop loss effectively controls risks.
Flexible RSI parameter settings can be optimized for different products.
VSTOP systematically trails stop loss without manual intervention.
Risks and Solutions
If ATR parameter is set too large or too small, the stop loss line would be meaningless. Different ATR parameters can be tested or combined with ATR average.
In range-bound markets, RSI may trigger frequent trading signals, increasing trading frequency and slippage cost. RSI parameters can be adjusted or extra filters added to reduce invalid signals.
Failed reversal is the main risk of this strategy. Traders need to watch larger timeframe trend direction to avoid counter trend trading. Long-term moving averages can be used to determine the trend.
Optimization Directions
Consider combining other indicators to filter out invalid signals, e.g. volume, Donchian Channel etc.
Optimize parameters based on backtest results to find the optimal parameter combination.
Research how to dynamically adjust the ATR coefficient for adaptation in different market environments.
Explore shutting down the strategy during high-risk periods.
Conclusion
This strategy integrates trend judgment and overbought/oversold levels to capture reversal opportunities in trending markets. VSTOP provides systematic stop loss management for risk control. The strategy can be further enhanced through parameter optimization and combining other indicators. Traders need to watch out for failed reversals, the main risk.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2 | RSI Period |
| v_input_2 | 30 | Oversold Level |
| v_input_3 | 70 | Overbought Level |
| v_input_4 | 2 | Vstop Length |
| v_input_5 | 2 | Vstop Mult |
Source Pine Script
/*backtest
start: 2022-10-02 00:00:00
end: 2023-10-08 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("Vstop and RSI", overlay=true)
//RSI Section
length = input(2, "RSI Period")
overSold = input(30, "Oversold Level")
overBought = input(70, "Overbought Level")
price = close
vrsi = rsi (price, length)
//VSTOP Section
vlength = input(2, "Vstop Length")
mult = input(2, "Vstop Mult")
atr_ = atr(vlength)
max1=0.0
min1=0.0
is_uptrend_prev = false
stop=0.0
vstop_prev=0.0
vstop1=0.0
is_uptrend=false
is_trend_changed=false
max_ = 0.0
min_ = 0.0
vstop=0.0
max1 := max(nz(max_[1]), close)
min1 := min(nz(min_[1]), close)
is_uptrend_prev := nz(is_uptrend[1], true)
stop := is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
vstop_prev := nz(vstop[1])
vstop1 := is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend := close - vstop1 >= 0
is_trend_changed := is_uptrend != is_uptrend_prev
max_ := is_trend_changed ? close : max1
min_ := is_trend_changed ? close : min1
vstop := is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
if vrsi > overBought
strategy.entry("Buy", strategy.long, comment="Buy")
if vrsi < overSold and vstop > price
strategy.entry("Sell", strategy.short, comment="Sell")Published by ChaoZhang on the FMZ strategy square · last modified 2023-10-09. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/VSTOP-and-RSI-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Multi Indicator Trend Breakout Strategy with Dynamic Stop LossPine Script · Breakout · 1d
- Enhanced Dynamic Channel Breakout Trend Following Trading SystemPine Script · Breakout · 1d
- Trend Tracking Strategy Based on Momentum BreakoutPine Script · Breakout · 1m
- Breakout Strategy Based on Turtle TradingPine Script · Breakout · 1d
- Donchian Channel Breakout StrategyPine Script · Breakout · 4h
- Donchian Channel Trend Following StrategyPine Script · Breakout · 1h