MA策略实盘
# MA策略实盘
// @version=2
// 该脚本仅作为自动化交易能力展示,不构成投资建议,请审慎进行投资,注意控制风险
// 交易逻辑:ma120金叉买入,ma120死叉卖出
period = 120
// 计算 ma120 的值
ma= ma(close, period)
// 计算预警条件的值
golden_cross=crossup(close, ma)
dead_cross=crossdown(close, ma)
// 执行交易指令
// 合约平多 / 现货卖出
exitLong(dead_cross, price="market", amount=1)
// 合约开多 / 现货买入
enterLong(golden_cross, price="market", amount=1)
// 创建对应的预警条件,以便在添加预警的窗口中使用
alertcondition(golden_cross, title="MA120金叉", direction="buy")
alertcondition(dead_cross, title="MA120死叉", direction="sell")
// 绘制到图表
plot(ma, title="MA120")
plotText(golden_cross, title="金叉", text='金叉', color='green', refSeries=ma, placement='bottom')
plotText(dead_cross, title="死叉", text='死叉', color='red', refSeries=ma, placement='top')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28