ハイン・アシュとスーパートレンド戦略


作成日: 2023-11-02 16:15:18 最終変更日: 2023-11-02 16:15:18
コピー: 1 クリック数: 1214
1
フォロー
1621
フォロワー

ハイン・アシュとスーパートレンド戦略

概要

ハインアシューとスーパートレンド戦略は,ハインアシューの図とスーパートレンドの指標を融合したトレンド追跡戦略である.この戦略は,トレンドの方向性を認識し,トレンドエリアで取引し,トレンドが逆転すると迅速に退出し,非トレンド取引による損失を最大限に抑えることを目的としている.

戦略原則

ハイン・アシューチャート (Hain-Ashiu Chart) は,特別なK線図であり,開場価格,閉場価格,最高価格,最低価格の平均値を用い,の実体を描画する.これにより,市場のノイズをフィルターし,グラフをより明確にする.スーパートレンド指数は,2つの曲線で構成され,動的なサポートとレジスタンスラインによってトレンドの方向を判断する.

この戦略は,まずハイン・アシュー図を計算し,その後ハイン・アシューK線をベースに超トレンド指標を計算する.価格が超トレンド指標を突破すると取引信号を生成する.具体的には,この戦略は,ハイン・アシューK線を使用して実際の波幅を計算し,波幅と平均価格を組み合わせて超トレンドの上下軌道を得ます.価格が下軌道を突破すると多信号を生成し,上軌道を突破すると空信号を生成する.

戦略はまた,スーパートレンド指標のパラメータを最適化して,最適なパラメータの組み合わせを採用し,指標の感性を高めます.さらに,戦略は,利潤を保証しながらリスクを制御できる止損機構を追加しました.

優位分析

  • ハイン・アシューマップを使用すると,ノイズをフィルターして信号をより明確にする.
  • 超トレンド指数は,トレンドの変化を素早く捉え,取引信号を間に合うように発信します.
  • パラメータ最適化は指標の信頼性を高めます.
  • 内部の止損メカニズムにより,リスクが効果的に制御されます.
  • トレンドトラッキングと機械取引システムと組み合わせた自動化が高い.

リスク分析

  • 取引システムは高度に自動化されているため,異常を避けるために注意深く監視する必要があります.
  • ハイン・アシューの地図は,ノイズをフィルターできるが,小さな反転信号も漏れる.
  • 超トレンド指標は誤信号を生じさせ,早期入場や止損を引き起こす可能性があります.
  • ストップポイントを正しく設定しないことで,不必要な損失を招くこともあります.
  • 回測データの不十分は,過適合を引き起こす可能性がある.实体と回測の結果は,大きな偏差がある可能性がある.

最適化の方向

  • 超トレンド指標のさらなる最適化のために,より多くのパラメータの組み合わせをテストする.
  • 他の指標で超トレンド指標の信号を確認してみて,誤信号率を下げる.
  • 利潤を保証する前提で,不要な損失を最小限に抑えるために,ストップ・ロスの戦略を最適化する.
  • 機械学習のアルゴリズムを拡張し,ビッグデータ訓練を活用して真のトレンドを判断する能力を高めます.
  • 信頼性を高めるため,より長い時間周期とより多くの異なる市場の歴史的データを使用します.

要約する

ハインアシューとスーパートレンド戦略は,トレンド追跡戦略である.トレンドの方向を識別し,大トレンドの下で取引し,逆転時に迅速に止まる.戦略は,ハインアシュー図のノイズフィルタリングとスーパートレンド指標の急速なトレンド変化を捕捉する能力を統合している.パラメータの最適化とストップ・メカニズムの設計により,収益を向上させながらリスクを制御することができる.将来,パラメータのさらなる最適化,確認指標の追加,反測データの拡大などの方法によって,この戦略を最適化し,システムの安定性と信頼性を向上させることができる.

ストラテジーソースコード
/*backtest
start: 2022-10-26 00:00:00
end: 2023-11-01 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5

strategy("Heiken Ashi & Super Trend_ARM", overlay=true,  pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.02)

///////////////////////////////////////////////////
////////////////////Function///////////////////////
///////////////////////////////////////////////////


heikinashi_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
heikinashi_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
heikinashi_low  = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
heikinashi_close= request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
heikinashi_color = heikinashi_open < heikinashi_close ? #53b987 : #eb4d5c
// plotbar(heikinashi_open, heikinashi_high, heikinashi_low, heikinashi_close, color=heikinashi_color)

x_sma(x, y) =>
    sumx = 0.0
    for i = 0 to y - 1
        sumx := sumx + x[i] / y
    sumx

x_rma(src, length) =>
	alpha = 1/length
	sum = 0.0
	sum := na(sum[1]) ? x_sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

x_atr(length) =>
    trueRange = na(heikinashi_high[1])? heikinashi_high-heikinashi_low : math.max(math.max(heikinashi_high - heikinashi_low, math.abs(heikinashi_high - heikinashi_close[1])), math.abs(heikinashi_low - heikinashi_close[1]))
    //true range can be also calculated with ta.tr(true)
    x_rma(trueRange, length)

x_supertrend(factor, atrPeriod) =>
	src = (heikinashi_high+heikinashi_low)/2
	atr = x_atr(atrPeriod)
	upperBand = src + factor * atr
	lowerBand = src - factor * atr
	prevLowerBand = nz(lowerBand[1])
	prevUpperBand = nz(upperBand[1])

	lowerBand := lowerBand > prevLowerBand or heikinashi_close[1] < prevLowerBand ? lowerBand : prevLowerBand
	upperBand := upperBand < prevUpperBand or heikinashi_close[1] > prevUpperBand ? upperBand : prevUpperBand
	int direction = na
	float superTrend = na
	prevSuperTrend = superTrend[1]
	if na(atr[1])
		direction := 1
	else if prevSuperTrend == prevUpperBand
		direction := heikinashi_close > upperBand ? -1 : 1
	else
		direction := heikinashi_close < lowerBand ? 1 : -1
	superTrend := direction == -1 ? lowerBand : upperBand
	[superTrend, direction]
	

///////////////////////////////////////////////////
////////////////////Indicators/////////////////////
///////////////////////////////////////////////////

factor = input.float(3.0, "Factor", step = 0.01)
atrPeriod = input(10, "ATR Length")


[supertrend, direction] = x_supertrend(factor, atrPeriod)

bodyMiddle = plot((heikinashi_open + heikinashi_close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)

///////////////////////////////////////////////////
////////////////////Strategy///////////////////////
///////////////////////////////////////////////////

var bool longCond                    = na, var bool shortCond                   = na, longCond := nz(longCond[1]), shortCond := nz(shortCond[1])
var int CondIni_long                 = 0, var int CondIni_short                 = 0, CondIni_long := nz(CondIni_long[1]), CondIni_short := nz(CondIni_short[1])
var float open_longCondition         = na, var float open_shortCondition   = na


long  = ta.change(direction) < 0
short = ta.change(direction) > 0


longCond        :=                                                              long
shortCond       :=                                                              short

CondIni_long    :=                                                              longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_long[1])
CondIni_short   :=                                                              longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_short[1])
longCondition   =                                                               (longCond[1] and nz(CondIni_long[1]) == -1)
shortCondition  =                                                               (shortCond[1] and nz(CondIni_short[1]) == 1)


open_longCondition             :=                                          long ? close[1] :                                                      nz(open_longCondition[1])
open_shortCondition            :=                                          short ? close[1] :                                                     nz(open_shortCondition[1])


//TP
tp                    = input.float(1.1  , "TP [%]",                      step = 0.1) 

//BACKTESTING inputs --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

testStartYear       =                   input.int(2000,                             title="start year",                                         minval = 1997, maxval = 3000,                                                   group= "BACKTEST") 
testStartMonth      =                   input.int(01,                               title="start month",                                        minval = 1, maxval = 12,                                                        group= "BACKTEST")
testStartDay        =                   input.int(01,                               title="start day",                                          minval = 1, maxval = 31,                                                        group= "BACKTEST")
testPeriodStart     =                   timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear        =                   input.int(3333,                             title="stop year",                                          minval=1980, maxval = 3333,                                                     group= "BACKTEST")
testStopMonth       =                   input.int(12,                               title="stop month",                                         minval=1, maxval=12,                                                            group= "BACKTEST")
testStopDay         =                   input.int(31,                               title="stop day",                                           minval=1, maxval=31,                                                            group= "BACKTEST")
testPeriodStop      =                   timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
testPeriod          =                   time >= testPeriodStart and time <= testPeriodStop ? true : false

// Backtest  ==================================================================================================================================================================================================================================================================================================================================


if longCond
    strategy.entry("L", strategy.long, when=testPeriod)

if shortCond
    strategy.entry("S", strategy.short, when=testPeriod)
    

strategy.exit("TP_L", "L", profit =((open_longCondition   *       (1+(tp/100))) - open_longCondition)/syminfo.mintick)

strategy.exit("TP_S", "S", profit =((open_shortCondition  *       (1+(tp/100))) - open_shortCondition)/syminfo.mintick)