VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 1
声望: 0

能否同时获取 15分钟、1小时、4小时、1天的K先数据,我根据multi_timeframe_strategy.py编写了一个策略,但是15分钟一直没有触发生效。
请帮我看下,哪里写的不对,谢谢了。

初始化

def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
        """"""
        super().__init__(cta_engine, strategy_name, vt_symbol, setting)
        # self.bg = BarGenerator(self.on_bar)
        self.bg4h = BarGenerator(self.on_bar, 4, self.on_4h_bar,interval=Interval.HOUR)
        self.am4 = ArrayManager()

        self.bg15min = BarGenerator(self.on_bar, 15, self.on_15min_bar)
        self.am15 = ArrayManager()

        self.bg1h = BarGenerator(self.on_bar, 1, self.on_1h_bar,interval=Interval.HOUR)
        self.am1 = ArrayManager()
 def on_tick(self, tick: TickData):
        """
        Callback of new tick data update.
        """
        self.bg15min.update_tick(tick)

 def on_bar(self, bar: BarData):
        """
        Callback of new bar data update.
        """
        self.bg15min.update_bar(bar)
        self.bg1h.update_bar(bar)
        self.bg4h.update_bar(bar)

15分钟

def on_15min_bar(self, bar: BarData):
        """
        Callback of new bar data update.
        """
        self.cancel_all()

        am = self.am15
        am.update_bar(bar)
        if not am.inited:
            return


        self.rsi_value_15min = am.rsi(self.rsi_length)
        # self.dif,self.dea,self.macd= am.macd(self.macd_fast_period,self.macd_slow_period,self.macd_signal_period)
        _,self.stockrsi_d_value_15min = am.stockrsi(self.stoch_rsi_timeperiod,self.stoch_rsi_fastk_period,self.stoch_rsi_fastd_period,self.stoch_rsi_fastd_matype)

        if self.trading: #进入真正的交易状态
            if self.rsi_value_15min<40  and self.stockrsi_d_value_15min <5:
                      self.trend_15min = "多"
            elif  self.rsi_value_15min >70 and self.stockrsi_d_value_15min > 70:
                      self.trend_15min = "空"
            else:
                self.trend_15min = ""

        if self.trend_4h and self.trend_4h!=self.trend_1h:
            self.send_email(bar,self.message4h.format(self.trend_4h))
            if self.trend_4h == self.trend_1h and self.trend_1h != "":
                self.send_email(bar,self.message4h.format(self.trend_4h)+','+self.message1h.format(self.trend_1h))
            elif self.trend_1h == self.trend_4h  and self.trend_4h == self.trend_15min and self.trend_4h!="":
                self.send_email(bar,self.message4h.format(self.trend_4h)+','+self.message1h.format(self.trend_1h)+','+self.message15min.format(self.trend_15min))
Member
avatar
加入于:
帖子: 4766
声望: 289

请在对应的on_bar函数下打印看看是否收到了合成的K线,如果收到了但是变量没有值,可能是数据太少不够am初始化导致的

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】