Buying Strategy Based on Historical High Breakout
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.
Overview
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.
Strategy Logic
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.
Advantages
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.
Risks
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.
Enhancement
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.
Conclusion
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.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_int_1 | 200 | ATH period |
| v_input_int_2 | 90 | ema line |
Source Pine Script
/*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 )Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-20. 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/Buying-Strategy-Based-on-Historical-High-Breakout.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
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h
- BB Breakout StrategyPine Script · Breakout · 1d
- BMSB Breakout Strategy BMSBPine Script · Breakout · 1h
- Bollinger Band T3 Moving Average StrategyPine Script · Breakout · 10m
- Bollinger Bands Dual track Breakthrough StrategyPine Script · Breakout · 30m
- Bollinger Breakout StrategyPine Script · Breakout · 30m