多要素量的な取引戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-31 13:55:37
タグ:

img

概要

これは複数の技術指標を組み込む定量的な取引戦略である.移動平均値,MACD,ボリンジャー帯,RSIおよびその他の指標を組み合わせて,多要素モデルを駆動した自動取引を実装する.

戦略の論理

この戦略の取引信号は以下の部分から来ます.

  1. 二重移動平均の金十字と死十字
  2. MACDゼロラインクロスオーバー
  3. ボリンジャー・バンド 上下回転
  4. RSI 過剰購入および過剰販売の逆転

上記の指標が同時に買い/売る信号を発信すると,戦略は対応する長または短の決定を下します.

具体的には,高速移動平均が遅い平均を横切ると,MACDヒストグラムが上昇し始め,RSIが過剰販売ゾーンから反転し,価格がボリンジャーバンドの下線に近づくと,それはロングエントリーのためのトレンド逆転信号とみなされます.

そして,高速MAが緩やかなMAを下回ると,MACDヒストグラムが低下し始め,RSIが過買いエリアから落ち,価格がボリンジャー帯上部に達すると,それは短期的な短期的な上位逆転と見なされます.

複数の指標からの信号を組み合わせることで 偽信号を効果的にフィルタリングし 戦略の安定性を向上させることができます

利点分析

この戦略の最大の利点は,多要素の取引モデルを採用し,信号の信頼性,安定性,収益性を高めることです.

  1. 多要素モデルでは,取引信号を相互に検証し,偽信号による干渉を効果的に削減できます.

  2. 異なるカテゴリーの指標は,市場の動きのより包括的な特徴を把握し,より正確な判断を行うことができます.

  3. 複数の指標を組み合わせることで 個々の指標の変動を平ら化し,より安定した収益を確保できます

  4. 組み合わせの指標とその重さは,異なる市場状況に合わせて戦略を柔軟に調整できます.

リスク分析

この戦略のリスクは以下のとおりです.

  1. 複数の指標の複雑な組み合わせは,正確なパラメータ調整とテストを必要とし,そうでなければ無効な信号を生む可能性があります.

  2. 単一の製品でのパフォーマンスが十分に安定していない場合もあります.リスクの多様化のために,適切な製品からなるポートフォリオを構築する必要があります.

  3. ポジションのサイズとストップ・ロスのメカニズムは,極端な市場条件下で損失を制限するために厳格に制御されるべきです.

オプティマイゼーションの方向性

この戦略を最適化できるいくつかの方向性:

  1. より多くの指標の組み合わせをテストし,暗黙の変動,ボリュームなど,最適なパラメータを特定します.

  2. マシン学習方法を活用して,自動的にインディケーターとパラメータセットの最適組み合わせを生成する.

  3. より長い時間枠で バックテストと最適化を行い 異なる市場段階に合わせて 体重を調整します

  4. 単一の取引と全体的なポジションの損失を厳格に制御するためのリスク管理ツールを組み込む.

結論

この戦略は,さまざまな技術指標の利点を充分活用し,多要素モデルを形成し,信号の正確性を効果的に向上させます.一方,リスク管理,パラメータ調整,戦略更新は,安定性と収益性を継続的に向上させるために不可欠です.


/*backtest
start: 2023-12-31 00:00:00
end: 2024-01-30 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Математическая Торговая Система с Ишимоку, TP/SL, ADX, RSI, OBV", shorttitle="МТС Ишимоку TP/SL ADX RSI OBV", overlay=true)

is_short_enable = input(0, title="Короткие сделки")
is_long_enable = input(1, title="Длинные сделки")

// Входные параметры для скользящих средних
fast_length = input(21, title="Быстрый период")
slow_length = input(26, title="Медленный период")

// Входные параметры для Ишимоку
tenkan_length = input(9, title="Тенкан-сен")
kijun_length = input(26, title="Киджун-сен")
senkou_length = input(52, title="Сенкоу-спан B")

// Входные параметры для ADX
adx_length = input(14, title="ADX период")
adx_level = input(30, title="ADX уровень")

// Входные параметры для RSI
rsi_length = input(14, title="RSI период")
rsi_overbought = input(70, title="RSI перекупленность")
rsi_oversold = input(30, title="RSI перепроданность")

// Входные параметры для OBV
obv_length = input(14, title="OBV период")

// Вычисление скользящих средних
fast_ma = ta.sma(close, fast_length)
slow_ma = ta.sma(close, slow_length)

// Вычисление Ишимоку
tenkan_sen = ta.sma(high + low, tenkan_length) / 2
kijun_sen = ta.sma(high + low, kijun_length) / 2
senkou_span_a = (tenkan_sen + kijun_sen) / 2
senkou_span_b = ta.sma(close, senkou_length)

// Вычисление ADX
[diplus, diminus, adx_value] = ta.dmi(14, adx_length)

// Вычисление RSI
rsi_value = ta.rsi(close, rsi_length)

// Вычисление OBV
f_obv() => ta.cum(math.sign(ta.change(close)) * volume)
f_obv_1() => ta.cum(math.sign(ta.change(close[1])) * volume[1])
f_obv_2() => ta.cum(math.sign(ta.change(close[2])) * volume[2])
f_obv_3() => ta.cum(math.sign(ta.change(close[3])) * volume[3])
obv_value = f_obv()

price_is_up = close[1] > close[3] 
price_crossover_fast_ma = close > fast_ma
fast_ma_is_up = ta.sma(close[1], fast_length) > ta.sma(close[3], fast_length)
rsi_is_trand_up = ta.rsi(close[1], rsi_length) > ta.rsi(close[3], rsi_length)
rsi_is_upper_50 = rsi_value > 50
obv_is_trand_up = f_obv_1() > f_obv_3() and obv_value > ta.sma(obv_value, obv_length)
is_up = price_is_up and price_crossover_fast_ma and fast_ma_is_up and rsi_is_trand_up and rsi_is_upper_50 and obv_is_trand_up

fast_ma_is_down = close < fast_ma
rsi_is_trend_down =  ta.rsi(close[1], rsi_length) < ta.rsi(close[2], rsi_length)
rsi_is_crossover_sma = rsi_value < ta.sma(rsi_value, rsi_length)
obv_is_trend_down =  f_obv_1() < f_obv_2()
obv_is_crossover_sma = obv_value < ta.sma(obv_value, obv_length)
is_down = fast_ma_is_down and rsi_is_trend_down and rsi_is_crossover_sma and obv_is_trend_down and obv_is_crossover_sma

//----------//
// MOMENTUM //
//----------//
ema8 = ta.ema(close, 8)
ema13 = ta.ema(close, 13)
ema21 = ta.ema(close, 21)
ema34 = ta.ema(close, 34)
ema55 = ta.ema(close, 55)

longEmaCondition = ema8 > ema13 and ema13 > ema21 and ema21 > ema34 and ema34 > ema55
exitLongEmaCondition = ema13 < ema55

shortEmaCondition = ema8 < ema13 and ema13 < ema21 and ema21 < ema34 and ema34 < ema55
exitShortEmaCondition = ema13 > ema55

// ----------  //
// OSCILLATORS //
// ----------- //
rsi = ta.rsi(close, 14)
longRsiCondition = rsi < 70 and rsi > 40
exitLongRsiCondition = rsi > 70

shortRsiCondition = rsi > 30 and rsi < 60
exitShortRsiCondition = rsi < 30

// Stochastic
length = 14, smoothK = 3, smoothD = 3
kFast = ta.stoch(close, high, low, 14)
dSlow = ta.sma(kFast, smoothD)

longStochasticCondition = kFast < 80
exitLongStochasticCondition = kFast > 95

shortStochasticCondition = kFast > 20
exitShortStochasticCondition = kFast < 5

// Логика входа и выхода
longCondition = longEmaCondition and longRsiCondition and longStochasticCondition and strategy.position_size == 0
exitLongCondition = (exitLongEmaCondition or exitLongRsiCondition or exitLongStochasticCondition) and strategy.position_size > 0

shortCondition = shortEmaCondition and shortRsiCondition and shortStochasticCondition and strategy.position_size == 0
exitShortCondition = (exitShortEmaCondition or exitShortRsiCondition or exitShortStochasticCondition) and strategy.position_size < 0

enter_long = (ta.crossover(close, senkou_span_a) or is_up) and longCondition
enter_short = (ta.crossunder(close, senkou_span_a) or is_down) and shortCondition

exit_long = ((ta.crossunder(fast_ma, slow_ma) or ta.crossunder(close, senkou_span_b) or enter_short) or exitLongCondition) 
exit_short = ((ta.crossover(fast_ma, slow_ma) or ta.crossover(close, senkou_span_b) or enter_long) or exitShortCondition)

// Выполнение сделок
if is_long_enable == 1
    strategy.entry("Long", strategy.long, when=enter_long)
    strategy.close("Long", when=exit_long)

if is_short_enable == 1
    strategy.entry("Short", strategy.short, when=enter_short)
    strategy.close("Short", when=exit_short)


もっと