0bps

Strategy vault / Trend following

VWAP EMA RSI Trend Following Strategy

This strategy combines VWAP, EMA and RSI for trend bias and follows trends using a trailing stop approach. It aims to ride trends with adaptive exits. Strategy Logic: 1. Calculate VWAP as fair value benchmark. 2…

Author
ChaoZhang
Complexity
Starter · 46 lines
Parameters
6
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

This strategy combines VWAP, EMA and RSI for trend bias and follows trends using a trailing stop approach. It aims to ride trends with adaptive exits.

Strategy Logic:

  1. Calculate VWAP as fair value benchmark.

  2. Compute 15-period EMA as intermediate-term trend indicator.

  3. Use RSI to identify overbought levels, RSI above threshold signals bullishness.

  4. Enter long when close exceeds VWAP and EMA, and RSI overbought.

  5. Set trailing stop loss line certain percentage below entry point.

  6. Take fixed profit at set point level to lock in gains.

Advantages:

  1. VWAP, EMA and RSI improve entry accuracy from multiple aspects.

  2. Trailing stop moves dynamically to protect profits.

  3. Fixed profit-taking provides certainty in exiting.

Risks:

  1. RSI and EMA prone to false signals during ranges.

  2. Stop loss calibration requires prudence, too wide or too narrow problematic.

  3. No limit on single trade loss size.

In summary, this strategy combines multiple indicators and uses a trailing stop for trend following. It performs well in sustained trends but requires optimization and risk controls.

Parameters

NameDefaultWhat it controls
v_input_int_115EMA Length
v_input_int_214RSI Length
v_input_int_345RSI Overbought Level
v_input_float_10.5Stop Loss %
v_input_float_23.5Take Profit %
v_input_float_3trueTrailing Stop %

Source Pine Script

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

//@version=5
strategy("VWAP+15EMA with RSI", overlay=true)

// Inputs
ema_length = input.int(15, title="EMA Length")
rsi_length = input.int(14, title="RSI Length")
rsi_overbought = input.int(45, title="RSI Overbought Level")
stop_loss_pct = input.float(0.5, title="Stop Loss %")
take_profit_pct = input.float(3.5, title="Take Profit %")
trailing_stop_pct = input.float(1, title="Trailing Stop %")

// Calculate Indicators
vwap = ta.vwap(hlc3)
ema = ta.ema(close, ema_length)
rsi = ta.rsi(close, rsi_length)

// Entry Condition
long_entry = close > vwap and close > ema and rsi > rsi_overbought

// Exit Conditions
stop_loss = strategy.position_avg_price * (1 - stop_loss_pct / 100)
take_profit = strategy.position_avg_price * (1 + take_profit_pct / 100)
trailing_stop = strategy.position_avg_price * (1 - trailing_stop_pct / 100)

// Submit Orders
if long_entry and strategy.position_size == 0
    strategy.entry("Long", strategy.long)

if strategy.position_size > 0
    strategy.exit("Stop Loss /Profit", "Long", profit = take_profit, stop=stop_loss, trail_offset = trailing_stop)


// Plot Indicators
plot(vwap, title="VWAP", color=color.blue)
plot(ema, title="EMA", color=color.orange)
plot(rsi, title="RSI", color=color.purple)
hline(rsi_overbought, title="RSI Overbought", color=color.red)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-13. 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/VWAP-EMA-RSI-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