- 策略广场
- 使用画线类库画K线以及均线图表范例
使用画线类库画K线以及均线图表范例
Author:
扫地僧, Date: 2021-11-05 10:33:04
Tags:
画线工具JavaScript
/*backtest
start: 2021-08-07 00:00:00
end: 2021-11-04 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/
var PreBarTime = 0
function PlotMA_Kline(records, param, isFirst){
var ma = TA.MA(records, param)
$.PlotRecords(records, "K")
if(isFirst){
for(var i = records.length - 1; i >= 0; i--){
if(ma[i] !== null){
$.PlotLine("ma", ma[i], records[i].Time)
}
}
PreBarTime = records[records.length - 1].Time
} else {
if(PreBarTime !== records[records.length - 1].Time){
$.PlotLine("ma", ma[ma.length - 2], records[records.length - 2].Time)
PreBarTime = records[records.length - 1].Time
}
$.PlotLine("ma", ma[ma.length - 1], records[records.length - 1].Time)
}
}
function main(){
var maCyc = MaCyc
var isFirst = true
exchange.SetContractType('rb000')
while(1){
var records = exchange.GetRecords()
if(records && records.length > maCyc){
PlotMA_Kline(records, maCyc, isFirst)
isFirst = false
}
Sleep(1000)
}
}
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6