首页 > 解决方案 > 打印问题或未定义变量

问题描述

我有这个代码类 Main(QCAlgorithm):

def Initialize(self):
    self.SetStartDate(2012, 1, 1)
    self.SetEndDate(2020, 1, 1)
    self.SetCash(100000) 
    self.dji = self.AddEquity("DJI", Resolution.Daily).Symbol
    self.AddEquity("IBM", Resolution.Hour) ## Subscribe to hourly TradeBars
    
    
   
    
def OnData(self, data):
## You can access the TradeBar dictionary in the slice object and then subset by symbol
## to get the TradeBar for IBM
    tradeBars = data.Bars
    ibmTradeBar = tradeBars['IBM']
    ibmOpen = ibmTradeBar.Open      ## Open price
    ibmClose = ibmTradeBar.Close    ## Close price
    
    ## Or you can access the IBM TradeBar by directly subsetting the slice object
    ## (since you are subscribed to IBM equity data, this will return a TradeBar rather than a QuoteBar)
    ##ibmOpen = data['IBM'].Open         ## Open price
    ##imbClose = data['IBM'].Close       ## Close price
    
    ibmmove = "100*(imbClose-ibmOpen)/ibmOpen"
    print(ibmmove) 

它完全忽略了打印语句,如果我减少缩进,我会得到 ibmmove 未定义

标签: quantconnect

解决方案


推荐阅读