资源加载中... loading...

三重EMA指标策略

Author: 雨幕(youquant), Date: 2022-05-26 12:11:01
Tags: EMA

回测测试

img

img

img

img


/*backtest
start: 2021-12-01 00:00:00
end: 2022-05-25 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["v_input_int_2",30],["v_input_int_3",60],["ContractType","rb2210",360008]]
*/

//@version=5
indicator("3EMA ", overlay=true)

short = input.int(20, "短期EMA均线周期")
mid = input.int(30, "中期EMA均线周期")
long = input.int(60, "长期EMA均线周期")

short_ma = ta.ema(close, short)
mid_ma = ta.ema(close, mid)
long_ma = ta.ema(close, long)

long_condition = (short_ma > mid_ma) and (mid_ma > long_ma) and (ta.rising(mid_ma, 2))

IN_LONG_AREA = long_condition and (close > mid_ma) and (close <= short_ma)

short_condition = (short_ma < mid_ma) and (mid_ma < long_ma) and (ta.falling(mid_ma, 2))

IN_SHORT_AREA = short_condition and (close <= mid_ma) and (close > short_ma)

if IN_LONG_AREA
    alert("Long " +timeframe.period+" "+ syminfo.basecurrency)
else if IN_SHORT_AREA
    alert("Short " +timeframe.period+" "+ syminfo.basecurrency)

p3 = plot(long_ma, color=color.red, linewidth=1, title='LONG EMA')
p2 = plot(mid_ma, color=color.orange, linewidth=1, title='MID EMA')
p1 = plot(short_ma, color=color.green, linewidth=1, title='SHORT EMA')


fill(p1, p2, color=long_condition?color.new(color.green, 65):color.new(color.white, 100))
fill(p1, p2, color=short_condition?color.new(color.red, 65):color.new(color.white, 100))


bgcolor(IN_LONG_AREA ? color.new(color.green, 90) : na)
bgcolor(IN_SHORT_AREA ? color.new(color.red, 90) : na)


if IN_LONG_AREA
    strategy.entry("Enter Long", strategy.long)
else if IN_SHORT_AREA
    strategy.entry("Enter Short", strategy.short)

相关内容

更多内容