This strategy judges trend direction based on breaking through periodic highs and lows. It goes long when price breaks through the periodic high and goes short when price breaks below the periodic low. It belongs to the trend tracking strategy.
The strategy first reads the user-defined cycle (daily, weekly, etc.) and lookback periods. Then it gets the highest and lowest prices for the lookback period based on these parameters. For example, if it is set to daily cycle and lookback 1 period, it takes the highest and lowest prices for the previous day.
In actual trading, if the closing price is greater than or equal to the lowest price of the lookback period, it is judged as an upward breakthrough and it goes long. If the closing price is less than or equal to the highest price of the lookback period, it is judged as a downward breakthrough and it goes short.
By capturing the trend direction through breaking through periodic highs and lows, this strategy belongs to a kind of trend tracking strategy.
The main advantages of this strategy are:
Capturing the big trend after strong consolidation by judging direction based on breakthrough points.
Simple and easy to understand, very suitable for beginners to learn and use.
Easy to optimize by adjusting periodic parameters, applicable to different varieties.
Can set reverse input for reverse operation, enriching strategy use.
Drawing periodic highs and lows to assist judgement and form multi-validation.
There are also some risks:
Cannot effectively filter sideways volatility, possible multiple mis-operations.
Cannot control stop loss, certain degree of loss risk exists.
Sensitive to trading costs, actual PnL may deviate.
Cannot limit position size, over-trading risk exists.
To address these risks, methods like setting stop loss, optimizing filter conditions, controlling position size can be used.
The main optimization directions are:
Adding filter mechanisms to avoid frequent opening during sideways. Set price channel, volatility filters etc.
Set trailing stop loss or time stop loss to control single loss risk and ensure overall profitability.
Optimize position sizing and money management to prevent over-trading and ensure stability.
Test effects of different periodic parameters and select optimal parameter combinations.
Increase algorithmic trading modules, use machine learning algorithms to improve decision efficiency.
In summary, this breakthrough high low backtest strategy is simple to operate based on trend tracking, suitable for beginners to learn, but risks being trapped exist. By adding optimizations like filters, stops, position control, these risks can be reduced and strategy results improved. It can provide ideas and references for our further research and improvements.
/*backtest start: 2023-01-01 00:00:00 end: 2024-01-07 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 //////////////////////////////////////////////////////////// // Copyright by HPotter v1.0 03/07/2018 // This script shows a high and low period value. // Width - width of lines // SelectPeriod - Day or Week or Month and etc. // LookBack - Shift levels 0 - current period, 1 - previous and etc. // // You can change long to short in the Input Settings // WARNING: // - For purpose educate only // - This script to change bars colors. //////////////////////////////////////////////////////////// strategy(title="High and Low Levels Backtest", shorttitle="HL Levels", overlay = true) SelectPeriod = input("D", defval="D") LookBack = input(1, minval=0) reverse = input(false, title="Trade reverse") xHigh = request.security(syminfo.tickerid, SelectPeriod, high[LookBack]) xLow = request.security(syminfo.tickerid, SelectPeriod, low[LookBack]) vS1 = xHigh vR1 = xLow pos = iff(close > vR1, 1, iff(close < vS1, -1, nz(pos[1], 0))) possig = iff(reverse and pos == 1, -1, iff(reverse and pos == -1, 1, pos)) if (possig == 1) strategy.entry("Long", strategy.long) if (possig == -1) strategy.entry("Short", strategy.short) barcolor(possig == -1 ? red: possig == 1 ? green : blue )