0bps

Strategy vault / Trend following

Multi Period Trend Following and Volume Analysis Adaptive Risk Strategy

This strategy is a comprehensive trading system that combines multi-period trend following, volume analysis, and dynamic risk management. It integrates multiple technical indicators including Exponential Moving…

Author
ianzeng123
Complexity
Starter · 86 lines
Parameters
0
Backtest bar
1d · swing
Tested on
DOGE/USDT · spot

IMG IMG

Overview

This strategy is a comprehensive trading system that combines multi-period trend following, volume analysis, and dynamic risk management. It integrates multiple technical indicators including Exponential Moving Average (EMA), Average Directional Index (ADX), Relative Strength Index (RSI), and Volume Weighted Average Price (VWAP) to construct an adaptive trading framework. The strategy emphasizes market pattern recognition across different time periods and optimizes entry timing through volume characteristics.

Strategy Principles

The strategy employs a layered architecture design with the following core components:

  1. Trend Identification System: Uses a combination of EMA and ADX to determine market trend direction and strength, with ADX above 25 indicating a trending market.
  2. Multi-Period Analysis: Achieves more accurate market positioning by comparing current timeframe with 4-hour chart technical indicators.
  3. Dynamic Volatility Adjustment: Uses ATR indicator to adaptively adjust stop-loss positions and target prices.
  4. Volume Analysis: Screens for low volatility entry opportunities by comparing current volume with average volume.
  5. Risk Control: Implements a percentage risk model based on account equity to limit risk exposure per trade.

Strategy Advantages

  1. Multi-dimensional Verification: Improves signal reliability through cross-validation of technical indicators across multiple time periods.
  2. Precise Risk Control: Dynamic stop-loss setting based on ATR adapts to market volatility.
  3. Comprehensive Position Management: Achieves precise position control through percentage risk model based on account equity.
  4. Flexible Profit Targets: Sets multiple profit targets combining VWAP and Fibonacci extension levels.
  5. Low-Risk Entry: Reduces trading costs by screening for low volatility environments through volume analysis.

Strategy Risks

  1. Trend Reversal Risk: False breakouts may trigger stop-losses in strong trend markets.
  2. Parameter Optimization Risk: Multiple technical indicator parameters require periodic optimization, risking overfitting.
  3. Liquidity Risk: May face increased slippage in low liquidity environments.
  4. Systemic Risk: Stop-loss positions may be insufficient to control risk during extreme market volatility.

Strategy Optimization Directions

  1. Introduce Machine Learning: Optimize parameter adaptive capability through deep learning.
  2. Add Market Sentiment Indicators: Integrate options market volatility indicators to enhance market prediction capability.
  3. Improve Volume Analysis: Introduce more volume pattern recognition algorithms.
  4. Optimize Stop-Loss Mechanism: Develop dynamic stop-loss system based on market microstructure.
  5. Enhance Risk Control: Introduce correlation analysis to optimize portfolio risk management.

Summary

The strategy achieves comprehensive analysis of market trends, volatility, and volume through multi-layered technical indicator combinations. Its core advantage lies in combining multi-period analysis with strict risk control, maintaining stable performance across different market environments. Future improvements can further enhance strategy adaptability and robustness through advanced technologies like machine learning.

Source Pine Script

/*backtest
start: 2024-03-07 18:40:00
end: 2025-02-17 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/

//@version=6
strategy("Optimized strategy framework", overlay=true)

// Input Parameters
ema_length = input.int(20, title="EMAtimeframe")
adx_length = input.int(14, title="ADXtimeframe")
rsi_length = input.int(21, title="RSItimeframe")
atr_length = input.int(14, title="ATRtimeframe")
volume_length = input.int(20, title="Volume average period")
fibonacci_level = 1.618  // Fibonacci extension levels161.8%

// Calculate technical indicators
ema = ta.ema(close, ema_length)

// Useta.dmi()to obtain+DI, -DI and ADX
[dm_plus, dm_minus, adx] = ta.dmi(adx_length, adx_length)

// CalculationRSIandATR
rsi = ta.rsi(close, rsi_length)
atr = ta.atr(atr_length)
vwap = ta.vwap(close)
avg_volume = ta.sma(volume, volume_length)

// Define Trend
bull_trend = close > ema and adx > 25
bear_trend = close < ema and adx > 25
range_market = adx < 25

// VWAPLayered Positioning
upper_bound = vwap + 1.5 * atr
lower_bound = vwap - 1.5 * atr

// Calculation4Hourly chart signals
four_hour_ema = request.security(syminfo.tickerid, "240", ta.ema(close, ema_length))
four_hour_vwap = request.security(syminfo.tickerid, "240", ta.vwap(close))
four_hour_rsi = request.security(syminfo.tickerid, "240", ta.rsi(close, rsi_length))
four_hour_volume = request.security(syminfo.tickerid, "240", ta.sma(volume, volume_length))

// Long position entry condition
long_condition = bull_trend and (close[1] < four_hour_ema or close[1] < four_hour_vwap) and rsi[1] < 45 and rsi[0] > 40 and volume < avg_volume * 0.7

// Short position entry condition
short_condition = bear_trend and (close[1] > four_hour_ema or close[1] > four_hour_vwap) and rsi[1] > 55 and rsi[0] < 60 and volume < avg_volume * 0.8

// Calculate stop loss and take profit
long_stop = close - 1.5 * atr
short_stop = close + 1.5 * atr
long_target = vwap + atr  // First goal,VWAP+1×ATR
short_target = vwap - atr // First goal,VWAP-1×ATR
fibonacci_target = close + (fibonacci_level * (high - low))  // Fibonacci 161.8% target

// Calculate position size (position control))
risk_per_trade = 0.01  // single trade risk is the account net value of1%
account_balance = strategy.equity
position_size = (account_balance * risk_per_trade) / (1.5 * atr)

// Plot buy and sell signals
plotshape(series=long_condition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.triangleup, text="BUY")
plotshape(series=short_condition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.triangledown, text="SELL")

// Execution Strategy
if (long_condition)
    strategy.entry("Long", strategy.long, qty=position_size)

if (short_condition)
    strategy.entry("Short", strategy.short, qty=position_size)

strategy.exit("Take Profit/Stop Loss", "Long", stop=long_stop, limit=long_target)
strategy.exit("Take Profit/Stop Loss", "Long", stop=long_stop, limit=fibonacci_target)

strategy.exit("Take Profit/Stop Loss", "Short", stop=short_stop, limit=short_target)
strategy.exit("Take Profit/Stop Loss", "Short", stop=short_stop, limit=fibonacci_target)

// DrawVWAPAnd overbought/oversold zones
plot(vwap, title="VWAP", color=color.blue)
plot(upper_bound, title="overbought area", color=color.red, linewidth=2, style=plot.style_line)
plot(lower_bound, title="oversold area", color=color.green, linewidth=2, style=plot.style_line)

Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-19. 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/Multi-Period-Trend-Following-and-Volume-Analysis-Adaptive-Risk-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