Loading ...

CTA策略模板

Author: Hukybo, Date: 2018-03-27 19:39:28
Tags:


/*backtest
start: 2019-05-01 09:00:00
end: 2020-06-21 15:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/

function main() {
    $.CTA("rb000/rb888", function(st) {
        var r = st.records
        var mp = st.position.amount
        if (r.length < 20) {
            return
        }
        var cross = _Cross(TA.MA(r, short), TA.MA(r, 20));
        if (mp <= 0 && cross > 2) {
            return 1 * (mp < 0 ? 2 : 1)
        }
        if (mp >= 0 && cross < -2) {
            return -1 * (mp > 0 ? 2 : 1)
        }
    })
}

More