Strategy vault / DCA & fixed investment
Multi Level Dynamic Cost Averaging Swing Trading Strategy Based on RSI and ATR
This strategy is a multi-level dynamic cost averaging (DCA) trading system that combines the Relative Strength Index (RSI) and Average True Range (ATR). It primarily identifies oversold market conditions for staged…

Overview
This strategy is a multi-level dynamic cost averaging (DCA) trading system that combines the Relative Strength Index (RSI) and Average True Range (ATR). It primarily identifies oversold market conditions for staged position building while using ATR to dynamically adjust take-profit levels for swing trading profits. The strategy features risk diversification, cost optimization, and stable returns.
Strategy Principles
The strategy operates on 4-hour or daily timeframes, with core logic including:
- Entry signals based on RSI below 30 indicating oversold conditions, allowing up to 4 staged entries
- Position sizing based on $200 total risk amount, calculating holdings dynamically using 2x ATR
- Position management using dynamic average cost tracking, calculating real-time average price after multiple entries
- Take-profit set at 3x ATR above average price, adapting to market volatility
- Real-time display of average price and take-profit levels through marker lines for visual tracking
Strategy Advantages
- Precise Risk Control - Achieves exact control of single trade risk through preset risk amount and ATR adjustment
- Flexible Position Building - Staged entry mechanism reduces cost while fully capturing opportunities
- Intelligent Take-Profit - Dynamic take-profit based on ATR ensures profits while adapting to market volatility
- Strong Visualization - Real-time display of average price and take-profit lines provides intuitive trading reference
- Good Adaptability - Strategy parameters can be flexibly adjusted for different market characteristics
Strategy Risks
- Continuous Oversold Risk - Sustained market decline may lead to excessive entries Solution: Strictly enforce maximum entry limit, set stop-loss when necessary
- Take-Profit Setting Risk - Excessive take-profit multiplier may miss profit opportunities Solution: Dynamically adjust ATR multiplier based on market characteristics
- Capital Management Risk - Staged entries may occupy excessive capital Solution: Set reasonable risk limits and position sizes
Strategy Optimization Directions
- Entry Signal Optimization
- Add trend judgment indicators to avoid early entries in strong downtrends
- Incorporate volume indicators to improve oversold judgment reliability
- Take-Profit Mechanism Improvement
- Introduce trailing stop mechanism for better profit locking
- Consider staged profit-taking for increased flexibility
- Risk Control Enhancement
- Add overall drawdown control
- Optimize capital allocation algorithm
Summary
The strategy achieves a trading system balancing risk control and stable returns through the combination of RSI and ATR indicators. The staged entry mechanism provides cost optimization possibilities, while the dynamic take-profit design ensures reasonable profit realization. Although some potential risks exist, the strategy's overall performance will be further improved through appropriate parameter settings and implementation of optimization directions.
Source Pine Script
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"DOGE_USDT"}]
*/
//@version=6
strategy("DCA-Based Swing Strategy (Risk $200) with Signals", overlay=true)
// === Main Indicators ===
// RSI for identifying oversold conditions
rsi = ta.rsi(close, 14)
// ATR for volatility estimation
atr = ta.atr(14)
// === Strategy Parameters ===
// Risk management
riskPerTrade = 200 // Total risk ($200)
atrRisk = 2 * atr // Risk in dollars per buy (2 ATR)
positionSize = riskPerTrade / atrRisk // Position size (shares)
// DCA Parameters
maxEntries = 4 // Maximum of 4 buys
takeProfitATR = 3 // Take profit: 3 ATR
// === Position Management ===
var float avgEntryPrice = na // Average entry price
var int entryCount = 0 // Number of buys
var line takeProfitLine = na // Take profit line
var line avgPriceLine = na // Average entry price line
// === Buy and Sell Conditions ===
buyCondition = rsi < 30 and entryCount < maxEntries // Buy when oversold
if (buyCondition)
strategy.entry("DCA Buy", strategy.long, qty=positionSize)
// Update the average entry price
avgEntryPrice := na(avgEntryPrice) ? close : (avgEntryPrice * entryCount + close) / (entryCount + 1)
entryCount += 1
// Display "BUY" signal on the chart
label.new(bar_index, low, "BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.normal)
// Update lines for average entry price and take profit
if (not na(takeProfitLine))
line.delete(takeProfitLine)
if (not na(avgPriceLine))
line.delete(avgPriceLine)
takeProfitPrice = avgEntryPrice + takeProfitATR * atr
// Sell condition: Take profit = 3 ATR from average entry price
takeProfitPrice = avgEntryPrice + takeProfitATR * atr
if (close >= takeProfitPrice and entryCount > 0)
strategy.close("DCA Buy")
// Reset parameters after closing
avgEntryPrice := na
entryCount := 0
// Remove lines after selling
if (not na(takeProfitLine))
line.delete(takeProfitLine)
if (not na(avgPriceLine))
line.delete(avgPriceLine)
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-27. 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/Multi-Level-Dynamic-Cost-Averaging-Swing-Trading-Strategy-Based-on-RSI-and-ATR.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
- Fibonacci Zone DCA StrategyPine Script · DCA & fixed investment · 1d
- Multi Indicator Confirmation EMA Breakout with DCA and Dynamic Take Profit StrategyPine Script · DCA & fixed investment · 1d
- Bollinger Band and RSI Mixing with DCA StrategyPine Script · DCA & fixed investment · 1d
- DCA Dual Moving Average Turtle Trading StrategyPine Script · DCA & fixed investment · 10m
- EMA Crossover Smart DCA with Dual Trailing Stop SystemPine Script · DCA & fixed investment · 1d
- Dynamic Average Cost Dollar Cost Averaging Compound StrategyPine Script · DCA & fixed investment · 1h