本文主要分析了Ravikant_sharma开发的基于多重指数移动平均线(EMA)和相对强弱指数(RSI)的量化交易策略。该策略通过EMA不同周期的交叉以及RSI的数值判定,识别价格趋势,确定入场和出场时机。
策略使用5条不同周期的EMA,包括9日线、21日线、51日线、100日线和200日线。代码中仅绘制了前4条EMA。RSI参数设置为14。
满足以下任一条件时,策略做多开仓:
同时需要RSI大于65,表示强势上涨趋势。
满足以下任一条件时,策略平仓退出:
这是一个典型的趋势追踪策略,具有以下优势:
该策略也存在一些风险:
该策略还可以从以下几个方向进行优化:
本策略整体上是一个可靠、易于实施的趋势追踪策略。它使用EMA多周期交叉判定趋势方向,再结合RSI过滤假信号,在回测效果较好的基础上进行参数优化和模型优化,可望获得稳定收益。但交易者在使用时,仍需警惕行情反转和参数不当带来的风险。
/*backtest
start: 2024-01-30 00:00:00
end: 2024-02-29 00:00:00
period: 3h
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/
// © Ravikant_sharma
//@version=5
strategy('new', overlay=true)
start = timestamp(1990, 1, 1, 0, 0)
end = timestamp(2043, 12, 12, 23, 59)
ema0 = ta.ema(close, 9)
ema1 = ta.ema(close, 21)
ema2 = ta.ema(close, 51)
ema3 = ta.ema(close, 100)
ema4 = ta.ema(close, 200)
rsi2=ta.rsi(ta.sma(close,14),14)
plot(ema0, '9', color.new(color.green, 0))
plot(ema1, '21', color.new(color.black, 0))
plot(ema2, '51', color.new(color.red, 0))
plot(ema3, '200', color.new(color.blue, 0))
//plot(ema4, '100', color.new(color.gray, 0))
//LongEntry = ( ta.crossover(ema0,ema3) or ta.crossover(ema0,ema2) or ta.crossunder(ema2,ema3) ) // ta.crossover(ema0,ema1) //
LongEntry=false
if ta.crossover(ema0,ema1)
if rsi2>65
LongEntry:=true
if ta.crossover(ema1,ema2)
if rsi2>65
LongEntry:=true
LongExit = ta.crossunder(ema0,ema2) or close >(strategy.position_avg_price*1.25) or rsi2 <40 or close < (strategy.position_avg_price*0.98)
if time >= start and time <= end
if(LongEntry and rsi2>60)
strategy.entry('Long', strategy.long, 1)
if(LongExit)
strategy.close('Long')