
The Simple Moving Average Envelope Dynamic Trading Strategy is a trading approach based on the relationship between price and the SMA200. The core concept leverages market mean-reversion characteristics by entering long positions when price drops below a specific percentage of the SMA200, and exiting when price returns to the SMA200 or reaches the upper envelope band. This strategy primarily targets large-cap stocks, utilizes a daily timeframe, sets a 14% envelope bandwidth, and offers two different exit mechanisms to accommodate various market environments and trader risk preferences.
The core principle of this strategy is based on the relationship between price and the SMA200 (200-day Simple Moving Average):
Entry Conditions:
Exit Conditions (two optional modes):
Technical Parameters:
Backtesting Time Settings:
The execution logic is clear: boolean input parameters determine which exit strategy to use, ensuring that the two modes are not enabled simultaneously, and trading signals are generated based on whether price meets the entry and exit conditions.
Clear Entry and Exit Points: The strategy provides objective, clear entry and exit signals, reducing emotional interference from subjective judgment.
Mean Reversion Principle: Effectively utilizes the market’s mean reversion characteristics, particularly suitable for relatively stable assets like large-cap stocks.
Flexible Exit Mechanisms: Offers two exit strategy options, allowing traders to adjust according to their risk preferences and market conditions:
Parameter Optimization Space: The strategy allows adjustment of entry and exit percentage levels, providing adaptability for different market environments.
Customizable Backtesting Dates: Allows users to specify the time range for backtesting, facilitating strategy evaluation for specific market phases.
Price Extremes Signal Triggering: Uses price highs and lows as signal trigger conditions rather than closing prices, better capturing intraday fluctuations.
False Breakout Risk: Prices may temporarily break through the set thresholds and then retreat, leading to false signals. A solution could be adding confirmation indicators or setting time filters.
Market Trend Shift Risk: Mean reversion strategies may underperform in strongly trending markets. It’s advisable to assess the current market environment before use or add trend filters.
Parameter Sensitivity: The choice of SMA period and envelope percentage significantly impacts strategy performance. Different parameter combinations should be backtested to find optimal settings.
Long-Only Limitation: The current strategy only implements long logic, potentially missing opportunities in continuously declining markets. Consider adding short logic to address various market environments.
Timeframe Limitation: The strategy explicitly specifies use only on daily charts, with performance on other timeframes unverified.
Lack of Risk Management Mechanism: The code does not include stop-loss settings, potentially leading to significant losses in extreme market conditions. Adding appropriate stop-loss mechanisms is recommended.
Add Short Strategy: The current strategy only implements long positions; adding short logic would make the strategy adaptable to more market environments. This can be implemented by adding reverse condition triggers for short entries and exits.
Incorporate Stop-Loss Mechanism: To avoid substantial losses in extreme market conditions, add ATR-based or fixed percentage stop-loss settings.
Combine with Other Technical Indicators: Additional filtering conditions can be added, such as RSI, MACD, or volume indicators, to improve signal quality. For example, require RSI to be in an oversold region when price meets entry conditions.
Dynamic Parameter Adjustment: Envelope width can be dynamically adjusted based on market volatility, widening the envelope range when volatility increases and narrowing it when volatility decreases.
Enhanced Position Management: Implement partial position closing functionality rather than closing all positions, to optimize capital utilization and risk control.
Add Time Filters: Include filtering conditions based on market sessions to avoid generating signals during unfavorable trading periods.
Implement Position Sizing: Dynamically adjust the size of each trade based on volatility or risk indicators, rather than using fixed positions.
Multi-Timeframe Analysis: Combine analyses from longer and shorter time periods to improve the accuracy of entry and exit timing.
The Simple Moving Average Envelope Dynamic Trading Strategy is a quantitative trading approach based on technical analysis, capitalizing on trading opportunities by leveraging the relationship between price and the long-term moving average. This strategy is particularly suitable for daily trading of large-cap stocks, entering positions when prices significantly deviate from the SMA200 and exiting when prices revert to or exceed specific levels to capture profits.
The main advantages of the strategy lie in its clear rules, objective signals, and provision of two different exit mechanisms to accommodate different trading styles. However, the strategy also has limitations such as high parameter sensitivity, lack of stop-loss mechanisms, and long-only trading restrictions.
By adding short logic, stop-loss mechanisms, additional technical indicator filtering, and dynamic parameter adjustments, this strategy has the potential to achieve more stable performance across different market environments. For quantitative traders, this provides a solid foundation framework that can be further customized and improved according to individual needs and market characteristics.
/*backtest
start: 2024-06-11 00:00:00
end: 2025-06-11 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © prasathalye
//@version=6
strategy("Upper or Lower Band Env Entry and Exit", overlay=true, fill_orders_on_standard_ohlc = true)
//Get User Input for LONG or SHORT ENVELOPE STRATEGY
//@version=6
//indicator("Input in an expression`", "", true)
//bool input_strategy = input.string("SHORT", "Strategy", options = ["SHORT", "LONG"]) == "SHORT"
//plot(plotDisplayInput ? close : na)
//string StrategySelection= input.text_area("SELECT EITHER LONG or SHORT")
bool strategyShortEnvelope=input.bool(true,"Exit at SMA200 STRATEGY")
bool strategyLongEnvelope=input.bool(false,"Exit at Upper Band STRATEGY")
if strategyShortEnvelope== true
strategyLongEnvelope == false
if strategyLongEnvelope == true
strategyShortEnvelope==false
//Basis = 20 Period SMA
//Upper Envelope = 20 Period SMA + (20 Period SMA x 0.1)
//Lower Envelope = 20 Period SMA - (20 Period SMA x 0.1)
// strategy for the exit at UPPER band of Envelope
if strategyLongEnvelope == true
conditionForBuy_1= low <= ta.sma(close,200) * 0.86
conditionForBuy_2= low <= ta.sma(close,200) * 0.9
conditionForSell_1= high >= ta.sma(close,200) * 1.1
conditionForSell_2 = high >= ta.sma(close,200) * 1.14
if conditionForBuy_1 or conditionForBuy_2
strategy.entry("My Long Entry Id", strategy.long)
if conditionForSell_1 or conditionForSell_2
strategy.close_all("Target Price Reached")
// strategy for the exit at LOWER band of Envelope
if strategyShortEnvelope == true
conditionForBuy_1= low <= ta.sma(close,200) * 0.85
conditionForBuy_2= low <= ta.sma(close,200) * 0.9
conditionForSell_1= high >= ta.sma(close,200) * 1.03
conditionForSell_2 = high >= ta.sma(close,200)
if conditionForBuy_1 or conditionForBuy_2
strategy.entry("My Long Entry Id", strategy.long)
if conditionForSell_1 or conditionForSell_2
strategy.close_all("Target Price Reached")