Dynamic ATR Stop Loss Center Line Strategy
Overview
This strategy uses a linear regression function and least squares method to calculate a price channel, consisting of two green and red lines. It employs a dynamic stop loss based on recent ATR.
Strategy Logic
The strategy calculates the center line xLG using linear regression with length 25 and shift 5. Then it takes 6% above and below the center line as channel range, with xLG1r as the upper line and xLG1s as the lower line.
When price is above xLG1r, it goes long. When price is below xLG1s, it goes short. It records the last long and short time. A long signal is generated when the last long time is greater than the last short time. A short signal is generated when the last short time is greater than the last long time.
The dynamic ATR stop loss uses ATR period of 1 and multiplier of 2. For long trades, the stop loss is closing price minus ATR value times multiplier. For short trades, the stop loss is closing price plus ATR value times multiplier.
Advantage Analysis
- Uses linear regression channel to track long term trends
- ATR-based stop loss adjusts dynamically to avoid stops being too wide or too tight
- Price breakout signals help avoid false signals
Risks and Improvements
- Regression channel parameters need optimization, current range may be too narrow
- ATR multiplier also needs testing to find optimal parameter
- Consider adding confirmation on breakout to avoid false breakouts
Optimization Directions
- Test different regression period lengths to find better parameters
- Try different ATR periods and stop loss multipliers
- Add additional confirmation on breakout signals, like volume breakout
Conclusion
This strategy combines multiple techniques like trend following, dynamic stops and breakout signals to create an adaptive trend tracking system. Further enhancements in parameter optimization and signal filtering can improve robustness and profitability. It provides a valuable approach for quant traders.
/*backtest
start: 2023-01-01 00:00:00
end: 2023-06-24 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
// Thanks to HPotter for the original code for Center of Gravity Backtest
strategy("Center of Gravity BF 🚀", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.15)
- 1

