- 策略广场
- 双均线实盘
双均线实盘
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: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["symbol","sc888,i888"]]
*/
function main() {
$.CTA(symbol, function(st) {
Log($.IndexCount())
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
}
})
}
更多内容