基于MACD和RSI的短线突破策略


创建日期: 2023-10-07 16:08:53 最后修改: 2023-10-07 16:08:53
复制: 0 点击次数: 960
avatar of ChaoZhang ChaoZhang
1
关注
1330
关注者

概述

该策略是基于1分钟MACD指标和RSI指标设计的短线突破策略。它结合了MACD指标判断趋势和找出突破点,以及RSI指标判断超买超卖的能力,寻找短线突破机会进行长短做波动。

策略原理

该策略首先在1分钟时间框架计算MACD指标的集散线,并绘制布林带判断集散线的突破情况。同时计算RSI指标判断多空力道。只有当布林带、MACD和RSI指标同时符合条件时,才会发出交易信号。

具体来说,当1分钟MACD集散线低于下轨且RSI高于51时做多,当MACD集散线高于上轨且RSI低于49时做空。并要求9日、50日和200日均线顺序排列才能交易,防止不利的趋势逆势操作。

采取固定的止盈止损 Exit 当收益达到0.5%或亏损达到0.3%时平仓。

优势分析

该策略结合了趋势判断和超买超卖判断,可以有效过滤假突破。固定止盈止损使每单获利有一定的预期管理。

优势如下:

  1. MACD判断趋势方向,RSI判断多空力道,可以有效避免逆势操作。

  2. 结合布林带通道判断突破信号,可以过滤假突破。

  3. 采取固定止盈止损,每单获利有一定预期,可以控制单笔亏损。

  4. 交易频率较高,适合短线操作。

风险分析

该策略也存在一些风险:

  1. 固定止盈止损无法根据市场变化调整,可能导致止损过小止盈过大。

  2. 依赖指标多重过滤信号,在盘整区域会出现多次触发止损。

  3. 高频交易手续费负担较重。

  4. MACD和RSI参数需要优化,目前参数可能不是最优。

以下几点可以进一步优化:

  1. 采用动态止盈止损,根据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)