0
tập trung vào
0
Người theo dõi

Trục kép MACD của Python, hiện tại một số cú pháp đã được thay đổi nhưng vẫn không hoạt động bình thường. Lỗi chủ yếu xuất phát từ đối tượng Chart. Tôi nên tiếp tục thay đổi nó như thế nào?

Được tạo ra trong: 2019-12-31 13:21:25, cập nhật trên:
comments   1
hits   1418

import json chart = { ‘__isStock’: True, ‘title’: { ‘text’: ‘Thử nghiệm API: Chart({…}) ’ }, ‘yAxis’: { ‘plotLines’: [{ ‘value’: 4520, ‘color’: ‘red’, ‘width’: 2, ‘label’: { ‘text’: ‘line1’, ‘align’: ‘center’ }, }, { ‘value’: 4500, ‘color’: ‘green’, ‘width’: 2, ‘label’: { ‘text’: ‘line2’, ‘align’: ‘center’ }, }] }, ‘series’: [{ ‘type’: ‘candlestick’, ‘name’: ‘thời kỳ hiện tại’, ‘id’: ‘primary’, ‘data’: [] }] }

preTime = 0

def main(): Global Chart # Nhớ Log(exchange.GetAccount()) exchange.SetContractType(‘rb000’) exchange.SetRate(1) records = None ChartObj = Chart(chart) #ChartObj = ext.GetCfg()

records = exchange.GetRecords()
while((records is None) or len(records) < 30):
    records = exchange.GetRecords()
    LogStatus("records.length:", len(records))
    Sleep(1000)

ext.PlotRecords(records, 'OK期货');
ext.PlotLine('dif', 0, records[len(records) - 1].Time)
ext.PlotLine('dea', 0, records[len(records) - 1].Time)
chart = ext.PlotLine('macd', 0, records[len(records)- 1].Time)

# 修改指标线 坐标轴Y轴
for key in ChartObj.series:
    if(ChartObj.series[key].name == 'dif' or ChartObj.series[key].name == 'dea' or ChartObj.series[key].name == 'macd'):
        ChartObj.series[key].yAxis = 1
    

chart.update(ChartObj)
chart.reset()
while(true):
    records = exchange.GetRecords()
    if(len(records) > 50):
        ext.PlotRecords(records, 'OK期货')
        MACD = TA.MACD(records)
        dif = MACD[0]
        dea = MACD[1]
        macd = MACD[2]
        if preTime != records[records.length - 1].Time:
            ext.PlotLine('dif', dif[dif.length - 2], records[records.length - 2].Time)
            ext.PlotLine('dea', dea[dea.length - 2], records[records.length - 2].Time)
            ext.PlotLine('macd', macd[macd.length - 2], records[records.length - 2].Time)
            
            ext.PlotLine('dif', dif[dif.length - 1], records[records.length - 1].Time)
            ext.PlotLine('dea', dea[dea.length - 1], records[records.length - 1].Time)
            ext.PlotLine('macd', macd[macd.length - 1], records[records.length - 1].Time)
            
            preTime = records[records.length - 1].Time
        else:
            ext.PlotLine('dif', dif[dif.length - 1], records[records.length - 1].Time)
            ext.PlotLine('dea', dea[dea.length - 1], records[records.length - 1].Time)
            ext.PlotLine('macd', macd[macd.length - 1], records[records.length - 1].Time)
        
    LogStatus("records.length:", records.length, records[records.length - 1])
    Sleep(1000)