一目均衡表、MACD、ストキャスティクスに基づくマルチタイムフレームトレンドフォロー戦略


作成日: 2024-02-05 10:30:45 最終変更日: 2024-02-05 10:30:45
コピー: 2 クリック数: 768
1
フォロー
1617
フォロワー

一目均衡表、MACD、ストキャスティクスに基づくマルチタイムフレームトレンドフォロー戦略

概要

この戦略は,イチモク雲図,移動平均,MACD,ストキャスティック,ATRなどの複数の指標を統合して,複数の時間枠でのトレンドの識別と追跡を実現します.高い確率のトレンドシグナルを取得した後に,ATRサイクルストップスロープ方式を採用してリスク管理を行う.

戦略原則

  1. イチモク雲図は中長線のトレンド方向を判定する。CLOSE価格の雲図の上を貫くターニングラインと基準線は多頭信号,下を貫く空頭信号。

  2. MACDはショートラインのトレンドとオーバーバイオーバーセルの状況を判断する.MACD柱線の横断信号線は多頭信号で,下は空頭信号である.

  3. ストキャスティックKDは超買い超売区を判断する。K線上には20が多頭信号,下には80が空頭信号。

  4. 移動平均は中期トレンドを判定する. 閉盤価格の上穿は移動平均が多頭信号で,下穿は空頭信号である.

  5. 以上の複数の指標信号を統合し,部分的な偽信号をフィルタリングし,高い確率の継続的なトレンド信号を形成する.

  6. ATRをベースにストップ・ストップ・価格を計算する.特定のATR倍数でストップ・ポイントとストップ・ポイントとして,リスクコントロールを実現する.

戦略的優位性

  1. 複数の時間枠でトレンドを認識し,信号の正確性を向上させる.

  2. 偽信号を効率的にフィルターする指標組み合わせフィルタリング技術が広く使用されている.

  3. ATR周期的な止損停止,単一損失を最大限に制御する.

  4. 応募条件の厳しさは,異なるリスクの好みに合わせてカスタマイズできます.

戦略リスク

  1. トレンドトラッキングを中心に,突発的な出来事による逆転を識別できない.

  2. ATRの周期的な停止は理想化されすぎ,リールディスクで完全に複製することは困難である.

  3. パラメータの設定を間違えた場合,取引頻度が高くなり,信号認識の正確性が低下する可能性があります.

  4. 異なる品種と市場環境に対応するためにパラメータを調整する必要があります.

戦略最適化の方向性

  1. 機械学習のアルゴリズムを追加し,トレンドの転換点を判断する.

  2. ATR倍数パラメータを最適化し,異なる品種には異なる倍数設定が可能である.

  3. 取引量の変化などの他の要因と組み合わせて,突破信号の精度を向上させる.

  4. テスト結果に基づいてパラメータを常に最適化し,最適なパラメータの組み合わせを見つけます.

要約する

この戦略は,イチモク雲図,MACD,Stochasticなどの複数の指標を総合的に使って,複数のタイムフレームのトレンドを識別し,トレンドを把握しながら,突発的な事件に囚われないようにします.ATR周期的な損失停止方法は,単一損失を効果的に制御する,推奨されるトレンド追跡戦略です.より多くの補助判断指標と機械学習方法の導入によって,この戦略のさらなる最適化には余地があります.

ストラテジーソースコード
/*backtest
start: 2024-01-05 00:00:00
end: 2024-02-04 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FXFUNDINGMATE

//@version=4
strategy(title="FXFUNDINGMATE TREND INDICATOR", overlay=true)

//Ichimoku Cloud
conversionPeriods = input(9, minval=1, title="Conversion Line Length")
basePeriods = input(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Length")
displacement = input(26, minval=1, title="Displacement")
donchian(len) => avg(lowest(len), highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)[displacement - 1]
leadLine2 = donchian(laggingSpan2Periods)[displacement - 1]


//macd
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)

fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal


//kd
periodK = input(5, title="%K Length", minval=1)
smoothK = input(3, title="%K Smoothing", minval=1)
periodD = input(3, title="%D Smoothing", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)


//atr
atrlength = input(title="Atr Length", defval=8, minval=1)
SMulti = input(title="Stop loss multi Atr", defval=1.0)
TMulti = input(title="Take profit multi Atr", defval=1.0)
smoothing = input(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
ma_function(source, length) =>
	if smoothing == "RMA"
		rma(source, length)
	else
		if smoothing == "SMA"
			sma(source, length)
		else
			if smoothing == "EMA"
				ema(source, length)
			else
				wma(source, length)
atr = ma_function(tr(true), atrlength)


operation_type = input(defval = "Both", title = "Position side", options = ["Long", "Short", "Both"])
operation = operation_type == "Long" ? 1 : operation_type == "Short" ? 2 : 3
showlines = input(true,  title="Show sl&tp lines")

// MA
sma_len = input(100, title="MA Length", type=input.integer)
sma = sma(close, sma_len)

longCond = crossover(k, 20) and macd > 0 and close > sma and close > leadLine1 and close > leadLine2
shortCond = crossunder(k, 80)  and macd < 0 and close < sma and close < leadLine1 and close < leadLine2

entry_price  = float(0.0) //set float
entry_price := strategy.position_size != 0 or longCond or shortCond ? strategy.position_avg_price : entry_price[1]
entry_atr = valuewhen(longCond or shortCond, atr,0)
short_stop_level     = float(0.0)   //set float
short_profit_level   = float(0.0)   //set float
long_stop_level      = float(0.0)   //set float
long_profit_level    = float(0.0)   //set float
short_stop_level    := entry_price + SMulti * entry_atr
short_profit_level  := entry_price - TMulti * entry_atr
long_stop_level     := entry_price - SMulti * entry_atr
long_profit_level   := entry_price + TMulti * entry_atr


//  Strategy Backtest Limiting Algorithm
i_startTime = input(defval = timestamp("1 Jan 2020 00:00 +0000"), title = "Backtesting Start Time", type = input.time)
i_endTime = input(defval = timestamp("31 Dec 2025 23:59 +0000"), title = "Backtesting End Time", type = input.time)
timeCond = true

if (operation == 1 or operation == 3)
    strategy.entry("long" , strategy.long , when=longCond and timeCond, alert_message = "Long")
    strategy.exit("SL/TP", from_entry = "long" , limit = long_profit_level , stop = long_stop_level , alert_message = "Long exit")

if (operation == 2 or operation == 3)
    strategy.entry("short", strategy.short, when=shortCond and timeCond, alert_message="Short")
    strategy.exit("SL/TP", from_entry = "short", limit = short_profit_level , stop = short_stop_level , alert_message = "Short exit")
    
if time > i_endTime  
    strategy.close_all(comment = "close all", alert_message = "close all")
    
plot(showlines and strategy.position_size <= 0 ? na : long_stop_level,    color=color.red,  style=plot.style_linebr, linewidth = 2)
plot(showlines and strategy.position_size <= 0 ? na : long_profit_level,  color=color.lime, style=plot.style_linebr, linewidth = 2)
plot(showlines and strategy.position_size >= 0 ? na : short_stop_level,   color=color.red,  style=plot.style_linebr, linewidth = 2)
plot(showlines and strategy.position_size >= 0 ? na : short_profit_level, color=color.lime, style=plot.style_linebr, linewidth = 2)

//}