能否同时获取 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))