转换任意K线周期管理模板(最近更新20180627)
6
Follow
4
Followers
更新于20171114
a. 解决Open找不到问题,是record数组访问越界造成的,访问越界是之前的K线有问题导致的。
更新于20171113
a. 过滤掉起始时间不正确的K线组合
b. 过滤掉时间间隔不正确的K线组合
更新于20170622
a. RecordsManager 增加Name参数,便于区分不同的K线
b. Fix 当固定K线数目不满一根新K线周期时,Time计算不正确的问题
更新于20170531
a. fix Volume计算错误
- 修改自小小梦的"转换任意K线周期" 模板
原理:
- 获得固定K线的周期,然后合成任意固定K线整数倍的新K线周期
功能:
- 转换基础K线为任意K线周期
- 暂时不支持 秒级别
限制:
- 新K线周期必须是固定K线周期的整数倍.
- 固定K线周期为1min, 3min, 5min, 15min, 30min, 新K线周期也必须是分钟且<60
- 固定K线周期为1hour, 新K线周期也必须是小时且<24
- 固定K线周期为1day, 新K线周期也必须是天
- 每次获得的固定K线周期数目必须>=2
测试版本,如有BUG ,问题 欢迎留言。
输出函数:
$.RecordsManager(NewCycleMS, Name) 生成新周期管理器
NewCycleMS 为新K线周期毫秒数. 默认(10006060*2) 2hour.
Name: 为该K线管理指定名字
返回K线管理器
$.AssembleRecords(records, BaseCycleMS)
records: 拿到的原始records
BaseCycleMS 为固定K线周期毫秒,默认用固定records进行计算
返回新K线周期的records
$.GetRecordsTable(n) 得到新K线最新的N个条目, 默认输出所有条目, 输出为table类型,便于LogStatus输出
$.Get***** 获得一些基本信息
Source
JavaScript
Strategy parameters
Related strategies
Comment
All comments (13)
得到的K线时间不对啊 大神看一下
4小时周期 得到的数据是:
2018-07-30 19:00:00.000+08:00 8162.42 8187.69 8200 8156.84 681.53875929
2018-07-30 12:00:00.000+08:00 8192.91 8185.3 8209.35 8151 902.81758958
2018-07-30 08:00:00.000+08:00 8213.11 8154.49 8225.18 8051 899.96507317
2018-07-30 04:00:00.000+08:00 8214.25 8191.52 8229.08 8190.03 879.26269857
2018-07-30 00:00:00.000+08:00 8234.88 8185.32 8247.36 8170.04 817.78392428
7天周期 等到的数据是:
2018-08-05 08:00:00.000+08:00 8213.11 8186.16 8278.23 8051 7869.96734215
2018-07-29 08:00:00.000+08:00 8235.84 8213.63 8301.2 8116.8 20943.43495
2018-07-28 08:00:00.000+08:00 8187.47 8236.39 8245.23 8070 21465.51463651
2018-07-27 08:00:00.000+08:00 7930.92 8188.83 8278 7800.44 22985.16836742
2018-07-26 08:00:00.000+08:00 8171.44 7936.88 8316.49 7850.88 22644.64610719
2018-07-25 08:00:00.000+08:00 8404.91 8171.44 8485 8050 22036.92873654
2018-07-24 08:00:00.000+08:00 7715.53 8404.95 8498.04 7695.05 23595.19928712
2018-07-23 08:00:00.000+08:00 7395.57 7716.12 7813 7370.26 27205.92883481
2018-07-22 08:00:00.000+08:00 7402.1 7395.14 7585.15 7330.64 26186.61248972
2018-07-21 08:00:00.000+08:00 7326.6 7404 7450 7210 28545.21532011
2018-07-20 08:00:00.000+08:00 7472.61 7326.59 7691.67 7265.14 28703.79798543
代码:
function main() {
// 5分钟
const period_M5 = 1000*60*5
// 4小时
const period_H4 = 1000*60*60*4
// 周线
const period_D7 = 1000*60*60*24*7
const periods = [
period_M5,
period_H4,
period_D7,
]
while (true) {
const tables = periods.map(period=>{
let records = null
if (period>period_D1) {
records = exchange.GetRecords(PERIOD_D1)
Log("日线级别", records.length)
} else if (period>period_H1) {
records = exchange.GetRecords(PERIOD_H1)
Log("小时线级别", records.length)
} else {
records = exchange.GetRecords(PERIOD_M1)
Log("分钟线级别", records.length)
}
const recordManager = $.RecordsManager(period)
const newRecords = recordManager.AssembleRecords(records, period)
const table = recordManager.GetRecordsTable()
return table
})
LogStatus(`\`${JSON.stringify(tables)}\``)
Sleep(60*1000)
}
}
8 years ago
TypeError: cannot read property 'Time' of undefined at main (FILE:525)
基本上运行一天就出现这样的报错停止,生成的K线有时候找不到Time
8 years ago
- 1
