三重EMA和MACD策略

Author: 雨幕, Date: 2022-05-30 09:40:16
Tags: MACD EMA

多头 50>200 ema 空头 50<200 ema

祝你今天愉快!

回测测试

img

img

img


/*backtest
start: 2021-12-01 00:00:00
end: 2022-05-29 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["v_input_3",60],["v_input_4",70],["v_input_5",80],["ContractType","rb2210",360008]]
*/



//@version=4
//@Author: AdventTrading
//Modified by viraltaco_

// This indicator was made to allow three moving averages to be displayed 
// without needing to use up 3 charting indicators individually

strategy(title = "Triple EMA + MACD", shorttitle = "tEMACd", overlay = true)

// Checkbox's for the other 2 MA's
line_2 = input(true, title = "使用第二条MA指标线")
line_3 = input(true, title = "使用第三条MA指标线")

len_1 = input(60, minval = 1, title = "第一条MA的周期")
len_2 = input(70, minval = 1, title = "第二条MA的周期")
len_3 = input(80, minval = 1, title = "第三条MA的周期")

src_1 = input(close, title = "第一条MA的数据源")
src_2 = input(close, title = "第二条MA的数据源")
src_3 = input(close, title = "第三条MA的数据源") 

tit_1 = "EMA-1"
tit_2 = "EMA-2"
tit_3 = "EMA-3"

plot(ema(src_1, len_1), title = tit_1, color = #10aaff)
plot((line_2) ? ema(src_2, len_2) : na, title = tit_2, color = #10ad00)
plot((line_3) ? ema(src_3, len_3) : na, title = tit_3, color = #ad0010)

//strategy("MACD Strategy", overlay=true)

fastLength = input(12, title="MACD快线")
slowlength = input(26, title="MACD慢线")
MACDLength = input(9, title="MACD信号周期")

SMema = ema(src_1, len_1)
LGema = ema(src_3, len_3)
MACD = ema(close, fastLength) - ema(close, slowlength)
aMACD = ema(MACD, MACDLength)
delta = MACD - aMACD


if (crossover(delta, 0) and SMema > LGema)
    strategy.entry("MacdLE", strategy.long, comment="MacdLE")


if (crossunder(delta, 0) and SMema < LGema)
    strategy.entry("MacdSE", strategy.short, comment="MacdSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)

相关内容

更多内容