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

双均线实盘

Author: ianzeng123, Date: 2024-07-01 14:16:06
Tags:


/*backtest
start: 2024-01-05 09:00:00
end: 2024-06-06 22:51:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","depthDeep":20}]
args: [["symbol","sc888"]]
*/

function main() {
    SetErrorFilter("502:|503:|tcp|character|unexpected|network|timeout|WSARecv|Connect|GetAddr|no such|reset|http|received|EOF|reused|(CTP_T@10010)|(CTP_T@7090)")
    var c = KLineChart()
    var initAccount = _C(exchange.GetAccount)
    $.CTA(symbol, function(st) {

        var r = st.records

        if (r.length < longPeriod) {
            return
        }

        var long_line = talib.MA(r, longPeriod)
        var short_line = talib.MA(r, shortPeriod)

        var long_signal = short_line[r.length - 2] > long_line[r.length - 2]
        var short_signal = short_line[r.length - 2] < long_line[r.length - 2]

        if (st.position.amount <= 0 && long_signal ) {
            Log("当前持仓: ", st.position);
            return st.position.amount < 0 ? 2 : 1
        } else if (st.position.amount >= 0 && short_signal) {
            Log("当前持仓: ", st.position);
            return st.position.amount > 0 ? -2 : -1
        }

        for (var i = 0 ; i < r.length ; i++) {
            var bar = r[i]
            c.begin(bar)
            c.plot(long_line[i], "短线", {overlay: true})
            c.plot(short_line[i], "长线", {overlay: true})
            c.close()
        }

        var accountInfo = _C(exchange.GetAccount)

        var curprofit = accountInfo.Info.Balance - initAccount.Info.Balance
        LogProfit(curprofit, "权益", '&')

    })
}
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6