MACD RSI 短期ブレイクストラテジー

作者: リン・ハーンチャオチャン, 日付: 2023年10月7日 16:08:53
タグ:

概要

これは1分間のMACD指標とRSI指標に基づいた短期的なブレイクアウト戦略です.トレンドを決定しブレイクアウトポイントを見つけ,RSIを組み合わせて,超買与超売状態を判断し,ロングとショートスカルピングの短期的なブレイクアウト機会を見つけます.

戦略の論理

この戦略は,まず1分間のタイムフレームでMACDヒストグラムを計算し,ヒストグラムのブレイクアウト状況を決定するためにボリンジャーバンドをプロットする.同時に,RSI指標を計算し,ロングとショートモメンタムを決定する.ボリンジャーバンド,MACDおよびRSI指標が同時に基準を満たす場合にのみ,取引シグナルが起動する.

具体的には,1分間のMACDヒストグラムが下帯を下回り,RSIが51を超えるとロング,上帯を下回り,RSIが49を下回るとショート.また,不良のトレンド取引を避けるために,取引前に9日,50日,200日間の移動平均が順番である必要があります.

利益が0.5%に達すると,または損失が0.3%に達すると,ポジションを閉じる.

利点分析

この戦略は,トレンド判断と過剰購入/過剰売却判断を組み合わせ,誤ったブレイクを効果的にフィルタリングすることができます.固定TP/SLは,すべての取引が一定の利益期待管理を持つようにします.

その利点とは

  1. MACDはトレンド方向を判断し,RSIはロング/ショートモメントを判断し,トレンドに反する取引を効果的に回避することができます.

  2. ボリンジャー帯を組み合わせて ブレイクシグナルを判断することで 偽ブレイクシグナルをフィルタリングできます

  3. 固定TP/SLを採用すると,すべての取引には特定の利益期待があり,これは単一の取引損失を制御します.

  4. 取引頻度は高く,短期取引に適しています.

リスク分析

この戦略にはいくつかのリスクもあります:

  1. 固定TP/SLは市場の変化に基づいて調整できないので,SLが小さすぎ TPが大きいことが起こる.

  2. 複数のフィルタリングされた信号に依存し,範囲限定市場では複数のSLを誘発する可能性があります.

  3. 取引頻度が高いため 大小の手数料がかかります

  4. MACDとRSIのパラメータはさらなる最適化が必要で,現在のパラメータは最適ではない可能性があります.

次の側面はさらに最適化できる:

  1. 動的 TP/SL を採用し,ATR をベースにした比率を調整する.

  2. ボリンジャー帯を広げ チャンネルを狭め 発射周波数を低くします

  3. MACDとRSIのパラメータを最適化して最適な組み合わせを見つけます

  4. 傾向に反する取引を避けるため,より高い時間枠の傾向に基づいてフィルタリングする.

概要

この戦略は,短期間の機会を効果的に発見できるトレンド,モメンタム,オーバーバイト/オーバーセール分析を組み込む典型的な短期間のブレイクアウトシステムである.しかし,リスクを下げ,収益性を向上させるためにさらなるテストとパラメータ最適化を必要とする特定のリスクがあります.適切に調整された場合,この戦略は効率的な短期間の取引戦略になることができます.


/*backtest
start: 2023-09-06 00:00:00
end: 2023-10-06 00:00:00
period: 1h
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/
// © pluckyCraft54926

//@version=5
strategy("5 Minute Scalp", overlay=true, margin_long=100, margin_short=100)

fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
hist_1m = request.security(syminfo.tickerid,"1",hist [barstate.isrealtime ? 1 : 0])
hline(0, "Zero Line", color=color.new(#787B86, 50))
////////////////////////////////////////////////////
//plotting emas on the chart
len1 = input.int(9, minval=1, title="Length")
src1 = input(close, title="Source")
offset1 = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out1 = ta.ema(src1, len1)
plot(out1, title="EMA9", color=color.blue, offset=offset1)

len2 = input.int(50, minval=1, title="Length")
src2 = input(close, title="Source")
offset2 = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out2 = ta.ema(src2, len2)
plot(out2, title="EMA50", color=color.yellow, offset=offset2)

len3 = input.int(200, minval=1, title="Length")
src3 = input(close, title="Source")
offset3 = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out3 = ta.ema(src3, len3)
plot(out3, title="EMA200", color=color.white, offset=offset3)
//////////////////////////////////////////////////////////////////
//Setting up the BB
/////////////////////////////////////////////////////////////
srcBB = hist_1m
lengthBBLong = input.int(94,title = "LengthBB Long", minval=1)
lengthBBShort = input.int(83,title = "LengthBB Short", minval=1)
multBB = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basisBBLong = ta.sma(srcBB, lengthBBLong)
basisBBShort = ta.sma(srcBB, lengthBBShort)
devBBLong = multBB * ta.stdev(srcBB, lengthBBLong)
devBBShort = multBB * ta.stdev(srcBB, lengthBBShort)
upperBB = basisBBShort + devBBShort
lowerBB = basisBBLong - devBBLong
offsetBB = input.int(0, "Offset", minval = -500, maxval = 500)

/////////////////////////////////////////
//aetting up rsi
///////////////////////////////////////////
rsilengthlong = input.int(defval = 11, title = "Rsi Length Long", minval = 1)
rlong=ta.rsi(close,rsilengthlong)
rsilengthshort = input.int(defval = 29, title = "Rsi Length Short", minval = 1)
rshort=ta.rsi(close,rsilengthshort)
///////////////////////////
//Only taking long and shorts, if RSI is above 51 or bellow 49
rsilong = rlong >= 51
rsishort = rshort <= 49
//////////////////////////////////////
//only taking trades if all 3 emas are in the correct order
long = out1 > out2 and out2 > out3
short = out1 < out2 and out2 < out3
/////////////////////////////////////


///////////////////////////////////////////
//setting up TP and SL
TP = input.float(defval = 0.5, title = "Take Profit %",step = 0.1) / 100
SL = input.float(defval = 0.3, title = "Stop Loss %", step = 0.1) / 100

longCondition = hist_1m <= lowerBB
longhight = input(defval=-10,title = "MacdTick Low")
if (longCondition and long and rsilong and hist_1m <= longhight) 
    strategy.entry("Long", strategy.long)

if (strategy.position_size>0)
    longstop = strategy.position_avg_price * (1-SL)
    longprofit = strategy.position_avg_price * (1+TP)
    strategy.exit(id ="close long",from_entry="Long",stop=longstop,limit=longprofit)

shortCondition = hist_1m >= upperBB
shorthight = input(defval=35,title = "MacdTick High")
if (shortCondition and short and rsishort and hist_1m >= shorthight)
    strategy.entry("short ", strategy.short)

shortstop = strategy.position_avg_price * (1+SL)
shortprofit = strategy.position_avg_price * (1-TP)

if (strategy.position_size<0)
    strategy.exit(id ="close short",stop=shortstop,limit=shortprofit)





もっと