Overview
The Smart Progressive Envelope Dynamic Position Scaling Strategy is a long-term trading strategy based on moving average envelopes that initiates buys when price drops below the lower envelope band and adds to positions in a stepwise, risk-controlled manner. The strategy supports up to 8 buy-ins with a cooldown period between purchases, and exits based on either a take profit calculated from the average entry price or a stop loss based on risk management parameters. The strategy limits backtesting to the last 365 days to provide more controlled testing results.
The core concept of this strategy is to buy when price retraces to the lower band of the moving average envelope, which typically represents a short-term oversold area, and then take profit when the price rises to the upper band, while setting reasonable stop losses to control risk. This strategy effectively utilizes price volatility characteristics by reducing the average cost through multiple batch purchases and is suitable for application in highly volatile market environments.
Strategy Principles
The core principles of this strategy are based on several key components:
Moving Average Envelope Calculation:
- First calculates a basis line (either SMA or EMA)
- Upper envelope = basis line * (1 + percentage offset)
- Lower envelope = basis line * (1 - percentage offset)
Entry Conditions:
- Price falls below the lower envelope
- The cooldown period since the last purchase has elapsed
- Current number of buy-ins has not exceeded the maximum limit (8 times)
- Price is below average entry price (or in an uptrend)
- Price is below the last buy price
Exit Conditions:
- Price rises above the set take profit percentage from the average entry price
- Or price falls below the set stop loss percentage from the average entry price
Position Management:
- Each buy-in is recorded and the average entry price is updated
- Maximum of 8 buy-ins allowed, forming a stepped position scaling
- All positions are closed at once when take profit or stop loss is triggered
Trend Determination:
- Trend direction is judged by the direction of the basis line (rising basis indicates uptrend)
- In an uptrend, some buy-in conditions are relaxed
Strategy Advantages
Progressive Risk Control:
The strategy employs a progressive position scaling method rather than buying the full position at once, effectively spreading entry risk. With up to 8 opportunities to add to positions, it continuously lowers the average cost during downtrends, increasing the probability of eventual profit.Automated Entry and Exit Mechanisms:
The strategy determines entry and exit points automatically based on clear technical indicators (moving average envelope), reducing emotional trading decisions from subjective judgments.Flexible Parameter Adjustment:
The strategy offers a rich set of adjustable parameters, including envelope length, offset percentage, take profit and stop loss ratios, and buy-in cooldown period, which can be optimized for different market environments.Trend Awareness Capability:
The strategy identifies trends by judging the direction of the basis line, relaxing buy-in conditions appropriately in uptrends, enhancing flexibility and adaptability.Volatility Utilization:
Particularly suitable for application in high volatility markets, it effectively utilizes price fluctuations for position scaling and profit-taking, with greater potential returns in more volatile conditions.
Strategy Risks
Trend Reversal Risk:
In strong downtrends, prices may continuously break through the envelope band, leading to losses even after multiple position additions. Although a stop loss mechanism is set, significant losses may be triggered in extreme market conditions.Parameter Sensitivity:
Strategy performance is highly dependent on parameter settings, with different market environments potentially requiring different parameter combinations. Incorrect parameter settings may lead to overtrading or missed trading opportunities.Capital Requirements:
Since the strategy allows up to 8 buy-ins, sufficient capital is needed to support multiple position additions if the market continues to decline, which may exceed the capacity of small-capital accounts.Cooldown Period Risk:
Improper cooldown periods may cause missed important buying opportunities or premature position additions at inappropriate times.Take Profit Setting Risk:
If the take profit percentage is set too high, profit opportunities may be missed; if set too low, it may limit potential profit space.
Strategy Optimization Directions
Dynamic Envelope Parameter Adjustment:
Consider automatically adjusting the envelope offset percentage based on market volatility, using smaller offsets in low volatility markets and larger offsets in high volatility markets. This would better adapt to different market environments.Integration of More Complex Trend Filters:
The current strategy uses a simple basis line direction to judge trends. Consider adding more complex trend indicators (such as MACD, ADX, etc.) to improve trend judgment accuracy and avoid buying too early in strong downtrends.Dynamic Take Profit and Stop Loss Mechanisms:
Fixed percentage take profit and stop loss could be replaced with dynamic adjustment mechanisms based on market volatility, such as setting take profit and stop loss levels based on ATR (Average True Range).Capital Management Optimization:
Implement dynamic position allocation instead of fixed amount purchases each time. For example, use a smaller proportion of funds for the first buy-in and gradually increase buy-in amounts as prices continue to fall.Addition of Time Filters:
Consider adding time-based filtering conditions to avoid trading during low market activity periods, or identify the most favorable trading sessions based on historical statistical data.
Summary
The Smart Progressive Envelope Dynamic Position Scaling Strategy is a systematic trading method that combines technical analysis and risk management. The strategy identifies potential buying opportunities through moving average envelopes, uses progressive position scaling to lower average costs, and sets clear take profit and stop loss rules to control risk.
This strategy is particularly suitable for application in more volatile markets, effectively utilizing price fluctuations to create profit opportunities. At the same time, there is significant room for improvement through parameter optimization and the addition of extra filters. However, users need to be aware of the strategy's risks, especially the risk of consecutive losses in strong downtrends, ensure sufficient capital to support multiple position additions, and adjust parameter settings based on different market environments.
Overall, this strategy provides a systematic trading framework that combines elements of trend following and counter-trend trading, reducing emotional decision-making through clear rules and helping to cultivate disciplined trading habits. For traders seeking stable returns in volatile markets, this is a strategy worth considering.
Strategy source code
/*backtest
start: 2024-05-14 00:00:00
end: 2025-05-12 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("SmartScale Envelope DCA",
overlay=true,
pyramiding=8,
default_qty_type=strategy.cash,
default_qty_value=25, // Order size = $25 CAD
initial_capital=200, // Initial capital = $200 CAD
currency=currency.CAD) // Base currency = CAD
// === Inputs
len = input.int(13, title="Envelope Length", minval=1)
percent = input.float(6.6, title="Envelope % Offset", step=0.1) / 100
src = input(close, title="Source")
exponential = input(false)
stopLossPctInput = input.float(15.0, title="Stop Loss %", minval=0.1, step=0.1)
takeProfitPctInput = input.float(5.0, title="Take Profit % from Avg Entry", minval=0.1, step=0.1)
cooldown = input.int(7, title="Candles Between Buys") // moved to bottom
stopLossPct = stopLossPctInput / 100
takeProfitPct = takeProfitPctInput / 100
maxBuys = 8 // Hardcoded max buy-ins
// === Envelope Calculation
basis = exponential ? ta.ema(src, len) : ta.sma(src, len)
upper = basis * (1 + percent)
lower = basis * (1 - percent)
// === Limit Backtest to Last 365 Days
startDate = timestamp("GMT-5", year(timenow), month(timenow), dayofmonth(timenow)) - 365 * 24 * 60 * 60 * 1000
inDateRange = time >= startDate
// === State Tracking
var float avgEntryPrice = na
var float lastBuyPrice = na
var int buyCount = 0
var int lastBuyBar = na
// === Trend Detection
isUptrend = basis > basis[1]
// === Entry Conditions
lowBelowLower = low < lower
cooldownPassed = na(lastBuyBar) or (bar_index - lastBuyBar >= cooldown)
belowAvgEntry = na(avgEntryPrice) or close < avgEntryPrice
lowerThanLastBuy = na(lastBuyPrice) or close < lastBuyPrice
allowBuyIn = (belowAvgEntry and lowerThanLastBuy) or isUptrend
highAboveUpper = high > upper
// === Exit Conditions
sellCondition = not na(avgEntryPrice) and close >= avgEntryPrice * (1 + takeProfitPct)
stopLossTriggered = not na(avgEntryPrice) and close <= avgEntryPrice * (1 - stopLossPct)
// === Buy Logic
if inDateRange and lowBelowLower and cooldownPassed and buyCount < maxBuys and allowBuyIn and (na(lastBuyPrice) or close <= lastBuyPrice)
buyCount += 1
strategy.entry("Buy in " + str.tostring(buyCount), strategy.long)
lastBuyBar := bar_index
lastBuyPrice := close
avgEntryPrice := na(avgEntryPrice) ? close : (avgEntryPrice * (buyCount - 1) + close) / buyCount
// === Sell Logic
if strategy.position_size > 0 and highAboveUpper and sellCondition
strategy.close_all(comment="Take Profit")
avgEntryPrice := na
buyCount := 0
lastBuyBar := na
lastBuyPrice := na
// === Stop Loss Logic
if strategy.position_size > 0 and stopLossTriggered
strategy.close_all(comment="Stop Loss Hit")
avgEntryPrice := na
buyCount := 0
lastBuyBar := na
lastBuyPrice := na
// === Plot Envelope
plot(basis, "Basis", color=color.orange)
u = plot(upper, "Upper", color=color.blue)
l = plot(lower, "Lower", color=color.blue)
fill(u, l, color=color.rgb(33, 150, 243, 95), title="Envelope Background")
// === Plot Avg Entry Price
plot(strategy.position_size > 0 and not na(avgEntryPrice) ? avgEntryPrice : na,
title="Avg Entry Price",
color=color.rgb(173, 195, 226),
linewidth=2,
style=plot.style_line)
Strategy parameters
The original address: Smart Progressive Envelope Dynamic Position Scaling Strategy
Progressive envelopes with dynamic scaling? Sounds like your algo just got a PhD in 'position sizing psychology'! Clever way to ride trends without going full YOLO—but let’s see how it handles a crypto flash crash or a sleepy forex Monday. Backtest or it’s just another ‘woulda-coulda’ trading bedtime story!