This strategy buys when the price breaks out above the historical n-day high in a bull market, with EMA stop loss. It belongs to trend following strategies.
Calculate the highest price over the past n days as the historical high price.
Buy when the current close exceeds the historical high price.
Use x-day EMA as the stop loss. Exit when price drops below EMA.
Values of n and x adjustable via parameters, default to 200-day high and 90-day EMA.
Simple and clear logic easy to implement.
Automatically follows trends formed by new highs.
EMA trailing stop locks in most profits.
No need to predict prices, just follow buy signals.
Default parameters work well in bull markets.
Concise code easy to understand and modify.
Massive losses when bull market ends.
Improper stop loss setups lead to premature or delayed stops.
Unable to predict strength and pullback of new highs.
Strong bias makes it unsuitable for other markets.
Parameter optimization risks overfitting to historical data.
Test different parameter combinations for optimum values.
Evaluate other stop methods like fixed percentage stops.
Optimize stops to balance frequency and risk control.
Add filters to avoid buying on noise.
Research ways to gauge buy signal strength.
Can add profit taking exits to lock in gains.
This strategy automates trend following on new highs with EMA trailing stops. Though effective in some cases, it needs expansion and optimization to become robust across all markets.
/*backtest start: 2023-08-20 00:00:00 end: 2023-09-19 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © gmhfund //@version=5 strategy("ATH 200d",overlay=1) plot(close) bars = input.int(200, "ATH period", minval=5, maxval=2000, step=1) range_ema = input.int(90,"ema line",minval=100,maxval=400,step=1) ath_price = ta.highest(bars)[1] plot(ath_price,color=color.blue) line_ema = ta.ema(close,range_ema) exit_condition = ta.crossunder(close,line_ema) plot(line_ema,color=color.orange) strategy.entry("Buy", strategy.long, 1, when = close > ath_price) // enter long by market if current open great then previous high //strategy.close("Buy",when = close < strategy.position_avg_price*0.9 ) strategy.close("Buy",when = exit_condition )