
この戦略の主な考えは,平滑な移動平均を使用して平滑な開明平均線を計算し,価格トレンドを検出し,価格と平滑な開明平均線が金叉の発生時に多行し,死叉の発生時に空行することである.
この策略はまず,平滑移動平均を計算する関数smoothedMovingAvgを定義し,その関数は,前の周期の移動平均値と最新の値を取り,一定の重みで現在の周期の平滑移動平均を計算する.
次に,関数 getHAClose を定義し,開値,最高値,最低値,閉値に基づいて,明平均線の閉値を計算する.
主策の論理では,まず異なる周期の原始価格を取得し,smoothedMovingAvg関数を使用して滑らかな移動平均を計算し,getHAClose関数を使用して滑らかな終了価格を計算します.
最後に,価格が上滑して閉店価格を告げる時に多めにして,下滑して平仓する.価格が下滑して閉店価格を告げる時に空きをして,上滑して平仓する.
この戦略の最大の利点は,平らな移動平均を利用して平らな開明平均線を計算することであり,価格トレンドをより正確に判断し,部分的なノイズをフィルターして,振動中に誤った信号を発生させないようにすることです.さらに,開明平均線自体は突出的なトレンドの利点を有しており,価格と組み合わせて使用すると,判断の正確性をさらに向上させることができます.
この戦略には以下のリスクがあります.
上記のリスクに対して,平滑パラメータの調整,ストップ・ローズメカニズムの導入,単一取引ポジションの減少などの方法によって,リスクを軽減し,戦略の安定性を向上させることができます.
この戦略は,以下の点で最適化できます.
上記のいくつかのポイントを最適化することで,戦略の曲線適合リスクをさらに軽減し,戦略の適応性と安定性を向上させることができます.
この戦略の全体的な考え方は明確で分かりやすく,平らな啓明均線を計算することによって価格傾向を判断し,それに応じて長短のアプローチを行う.最大の優位性は,部分的なノイズをフィルターして,信号判断の正確性を向上させることにある.しかし,一定のパラメータの最適化が困難であり,急速な反転を逃す可能性があるリスクもある.自適應機構の導入,指標の組み合わせの拡大などの手段によってさらに最適化できる.深入な研究に値する.
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Smoothed Heiken Ashi Strategy", overlay=true)
// Inputs
g_TimeframeSettings = 'Display & Timeframe Settings'
time_frame = input.timeframe(title='Timeframe for HA candle calculation', defval='', group=g_TimeframeSettings)
g_SmoothedHASettings = 'Smoothed HA Settings'
smoothedHALength = input.int(title='HA Price Input Smoothing Length', minval=1, maxval=500, step=1, defval=10, group=g_SmoothedHASettings)
// Define a function for calculating the smoothed moving average
smoothedMovingAvg(src, len) =>
smma = 0.0
smma := na(smma[1]) ? ta.sma(src, len) : (smma[1] * (len - 1) + src) / len
smma
// Function to get Heiken Ashi close
getHAClose(o, h, l, c) =>
((o + h + l + c) / 4)
// Calculate smoothed HA candles
smoothedHAOpen = request.security(syminfo.tickerid, time_frame, open)
smoothedMA1close = smoothedMovingAvg(request.security(syminfo.tickerid, time_frame, close), smoothedHALength)
smoothedHAClose = getHAClose(smoothedHAOpen, smoothedHAOpen, smoothedHAOpen, smoothedMA1close)
// Plot Smoothed Heiken Ashi candles
plotcandle(open=smoothedHAOpen, high=smoothedHAOpen, low=smoothedHAOpen, close=smoothedHAClose, color=color.new(color.blue, 0), wickcolor=color.new(color.blue, 0))
// Strategy logic
longCondition = close > smoothedHAClose
shortCondition = close < smoothedHAClose
strategy.entry("Buy", strategy.long, when=longCondition)
strategy.close("Buy", when=shortCondition)
plotshape(series=longCondition, title="Buy Signal", color=color.green, style=shape.labelup, location=location.belowbar)
plotshape(series=shortCondition, title="Sell Signal", color=color.red, style=shape.labeldown, location=location.abovebar)