
本策略通过计算5日、10日和20日的指数移动平均线(EMA),结合超趋势指标来产生买入和卖出信号。当5日线上穿10日线,并且5日线和10日线均上穿20日线时产生买入信号;当10日线下穿5日线,并且5日线和10日均下穿20日线时产生卖出信号。
主要风险的解决方案:
本策略运用5日、10日和20日三条均线以及超趋势指标构建交易策略。策略简单高效,在趋势判断和发现机会上表现优异。同时具备较强的可定制性和扩展性。优化空间较大,可通过调整参数、增加技术指标以及加入机器学习等方式不断改进策略表现,适应更加复杂的市场环境。
/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
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/
// © aadilpatel07
//@version=4
strategy("5-10-20 Cross", overlay=true)
src = close,
len1 = input(5, minval=1, title="EMA 1")
len2 = input(10, minval=1, title="EMA 2")
len3 = input(20, minval=1, title="EMA 3")
mult = input(type=input.float, defval=2)
len = input(type=input.integer, defval=14)
[superTrend, dir] = supertrend(mult, len)
ema1 = ema(src, len1)
ema2 = ema(src, len2)
ema3 = ema(src, len3)
//EMA Color
col1 = color.lime
col2 = color.blue
col3 = color.red
//EMA Plots
plot(series=ema1,color=col1, title="EMA1")
plot(series=ema2,color=col2, title="EMA2")
plot(series=ema3,color=col3, title="EMA3")
//plot SuperTrend
colResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 100) : color.new(color.green, 100)
colSupport = dir == -1 and dir == dir[1] ? color.new(color.green, 0) : color.new(color.green, 10)
plot(superTrend, color = colResistance, linewidth=1)
plot(superTrend, color = colSupport, linewidth=1)
//longCondition = crossover(ema1, ema2) and crossover(ema1,ema3) and crossover(ema2,ema3)
longCondition = ema1 > ema2 and ema1 > ema3 and ema2 > ema3 and ema2 < ema1 and dir == -1
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
//shortCondition = crossover(ema2, ema1) and crossover(ema3,ema1) and crossover(ema3,ema2)
shortCondition = ema1 < ema2 and ema1 < ema3 and ema2 < ema3 and ema2 > ema1 and dir == 1
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)