0
关注
83
关注者
Simple multi-variety commodity futures moving average line strategy
创建于 2018-08-31 11:36:35 更新于 2019-12-03 17:33:28
2
1864
Simple multi-variety commodity futures moving average line strategy
www.fmz.com
The commodity futures library implements the strategic framework of the $.CTA function. With this strategy framework, a multi-variety strategy of concurrent stable and real market strategy can be achieved in just a few dozen lines.
function main() {
// using commodity futures library of the CTA strategy framework
$.CTA(Symbols, function(st) {
var r = st.records
var mp = st.position.amount
var symbol = st.symbol
/*
r is the K line, mp is the current variety position, positive number refers to long positions, negative number refers to short position, 0 means no position,
symbol refers to variety name
The return value is n:
n = 0 : Refers to close all position (regardless of the current holdings position)
n > 0 : If there are currently holding long positions, adding n long positions, if the current position is short position, then close n short positions,
if n is greater than the current holding position, then open long positions
n < 0 : If the current position is short position, adding n short positions. If the current position is long positions, then close n long positions.
If -n is greater than the current holding position, then open short position.
No return value means doing nothing
*/
if (r.length < SlowPeriod) {
return
}
var cross = _Cross(TA.EMA(r, FastPeriod), TA.EMA(r, SlowPeriod));
if (mp <= 0 && cross > ConfirmPeriod) {
Log(symbol, "up cross cycle", cross, "Current holding position", mp);
return Lots * (mp < 0 ? 2 : 1)
} else if (mp >= 0 && cross < -ConfirmPeriod) {
Log(symbol, "down cross cycle", cross, "Current holding position", mp);
return -Lots * (mp > 0 ? 2 : 1)
}
});
}
相关推荐
exchange.IO("api","","","");函数访问好多交易所的API都报错。调用 _C 时出错, in g__C TypeError: 'OOOOi11i1' object is not callableposition[-1].Profit 输出的盈亏和计算的盈亏不一致画图程序怎么设置显示时间可否多人异地登录?团队开发需要怎么办?30-line gambler strategy (Selling short)OKCoin newbies HarvesterNew version of Dual Thrust Trading strategyThe new version of “the grid strategy” only contain 50-lines of coding!New version of Dynamic balance

