本策略通过观察价格与长周期均线(如200日线)的关系,在价格突破均线时建仓做多,在价格跌破均线时平仓,属于长线震荡突破操作策略。该策略追求长期持有并减少交易频率。
策略原理:
计算一条长周期的移动平均线,典型参数为200日线。
当收盘价从下方突破该均线时,进行买入做多操作。
当收盘价从上方跌破该均线时,进行卖出平仓操作。
在做多状态则持续持有,直至价格跌破均线止损。
该策略的优势:
长线均线可有效识别价格中长线趋势。
突破交易方式可及时捕捉股价长线反转。
减少交易频率,有助于降低交易成本和风险。
该策略的风险:
长周期均线滞后问题较严重,入场时点不佳。
无法限制突破后的回调波动带来的亏损。
频繁出现小幅震荡突破可能带来连续小额损失。
总之,该HODL策略通过长周期均线震荡来判断持有时机,可减少交易频率。但在参数优化与止损设置方面仍有改进空间,以控制回撤并获得长期稳定收益。
/*backtest
start: 2022-09-05 00:00:00
end: 2023-04-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("HODLBot", default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_every_tick=true, overlay=true)
//// Time limits
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(01, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2029, "Backtest Stop Year")
testStopMonth = input(1, "Backtest Stop Month")
testStopDay = input(1, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
testPeriod() => true
maPeriod = input(200, "MA Period")
smoothing = input(defval="EMA", options=["EMA", "SMA"])
ma(smoothing, src, length) =>
if smoothing == "EMA"
ema(src, length)
else
if smoothing == "SMA"
sma(src, length)
//// Main ////
movingAverage = ma(smoothing, close, maPeriod)
plot(movingAverage, color=orange, style = line, linewidth = 4)
// very simple, price over MA? Buy and HODL
if (testPeriod() and close > movingAverage)
strategy.entry("HODL", strategy.long)
// Price under, close long
if (testPeriod() and close < movingAverage)
strategy.close("HODL")