移動平均振動のHODL戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-12 16:02:24
タグ:

この戦略は,長期間の移動平均値 (例えば200日) の周りに価格の振動を観察し,保持信号を決定し,ポジションエントリーのためのトレードブレイクアウトおよびストップ損失としてブレイク以下を使用する.長期保有の取引頻度を最小化することを目的としています.

戦略論理:

  1. 長期移動平均を計算します.通常は200日です.

  2. 価格が移動平均値を超えるとロングに入ります

  3. 価格が移動平均値を下回る時,ロングアウトする.

  4. ストップ・ロスの下までロングポジションを保持する.

利点:

  1. 長期的MAは中期から長期の傾向を効果的に特定します

  2. 脱出取引は 長期的逆転を 適時に把握します

  3. 取引頻度が低いとコストとリスクが減ります

リスク:

  1. 長期間のMAsは著しく遅れており,入場タイミングが悪くなっています.

  2. 脱退後の引き上げリスクは制限されません

  3. 頻繁に小規模な脱出は 持続的な小規模な損失をもたらします

要約すると,このHODL戦略は,トレード頻度を最小限に抑え,保持タイミングを決定するために長いMA振動を使用します. しかし,パラメータ最適化とストップロスの配置は,安定した長期的利益のためにパフォーマンスとリスク管理を改善することができます.


/*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")


もっと