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

移动平均线买卖策略

Author: 雨幕(youquant), Date: 2022-05-31 10:09:04
Tags: MAEMA

采用两条不同长度的移动平均线来区分定制平均均线上的买入/卖出颜色。

回测测试

img

img

img


/*backtest
start: 2021-12-01 00:00:00
end: 2022-05-30 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","hc2210",360008]]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dannhau2

//@version=5
indicator(title="Moving Average Buy-Sell", shorttitle="MABS", overlay=true, timeframe="", timeframe_gaps=true)

Wave = ta.ema(input(close, title="数据源"), input.int(9, minval=1, title="快线周期"))
Tide = ta.ema(input(close, title="数据源"), input.int(30, minval=1, title="慢线周期"))
AVG = (Wave + Tide)/2

Up = ta.crossover(Wave, Tide)
Down = ta.crossover(Tide,Wave)

var col = color.red

if Up
    col := color.lime

if Down
    col := color.red


P1=plot(AVG, title="MABS", color=col, linewidth = 3, display=display.none)
P2=plot(Wave, title="MA-Wave", color=col, linewidth = 2)
P3=plot(Tide, title="MA-Tide", color=col, linewidth = 3)

fill(P2, P3, color= Wave > Tide ? color.new(color.lime,70):color.new(color.red, 70))

alertcondition(Up, title="Trend Changed Positive", message="Trend Changed Positive")
alertcondition(Down, title="Trend Changed Negative", message="Trend Changed Negative")

if Up
    strategy.entry("Enter Long", strategy.long)
else if Down
    strategy.entry("Enter Short", strategy.short)
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6