[Mod]change filename of MultiTimeframStrategy

This commit is contained in:
vn.py 2019-02-21 09:22:59 +08:00
parent d0ff8f904d
commit 760da8e7d2

View File

@ -1,7 +1,6 @@
from vnpy.app.cta_strategy import ( from vnpy.app.cta_strategy import (
CtaTemplate, CtaTemplate,
StopOrder, StopOrder,
Direction,
TickData, TickData,
BarData, BarData,
TradeData, TradeData,
@ -13,7 +12,6 @@ from vnpy.app.cta_strategy import (
class MultiTimeframeStrategy(CtaTemplate): class MultiTimeframeStrategy(CtaTemplate):
"""""" """"""
author = '用Python的交易员' author = '用Python的交易员'
rsi_signal = 20 rsi_signal = 20
@ -29,9 +27,12 @@ class MultiTimeframeStrategy(CtaTemplate):
slow_ma = 0 slow_ma = 0
ma_trend = 0 ma_trend = 0
parameters = ['rsi_signal', 'rsi_window',
'fast_window', 'slow_window',
'fixed_size']
parameters = [ 'rsi_signal', 'rsi_window', 'fast_window', 'slow_window','fixed_size'] variables = ['rsi_value', 'rsi_long', 'rsi_short',
variables = ['rsi_value','rsi_long','rsi_short','fast_ma','slow_ma','ma_trend'] 'fast_ma', 'slow_ma', 'ma_trend']
def __init__(self, cta_engine, strategy_name, vt_symbol, setting): def __init__(self, cta_engine, strategy_name, vt_symbol, setting):
"""""" """"""
@ -42,10 +43,10 @@ class MultiTimeframeStrategy(CtaTemplate):
self.rsi_long = 50 + self.rsi_signal self.rsi_long = 50 + self.rsi_signal
self.rsi_short = 50 - self.rsi_signal self.rsi_short = 50 - self.rsi_signal
self.bg5 = BarGenerator(self.on_bar,5, self.on_5min_bar) self.bg5 = BarGenerator(self.on_bar, 5, self.on_5min_bar)
self.am5 = ArrayManager() self.am5 = ArrayManager()
self.bg15 = BarGenerator(self.on_bar,15, self.on_15min_bar) self.bg15 = BarGenerator(self.on_bar, 15, self.on_15min_bar)
self.am15 = ArrayManager() self.am15 = ArrayManager()
def on_init(self): def on_init(self):
@ -80,7 +81,7 @@ class MultiTimeframeStrategy(CtaTemplate):
self.bg5.update_bar(bar) self.bg5.update_bar(bar)
self.bg15.update_bar(bar) self.bg15.update_bar(bar)
def on_5min_bar(self, bar:BarData): def on_5min_bar(self, bar: BarData):
"""""" """"""
self.cancel_all() self.cancel_all()
@ -95,22 +96,21 @@ class MultiTimeframeStrategy(CtaTemplate):
if self.pos == 0: if self.pos == 0:
if self.ma_trend > 0 and self.rsi_value >= self.rsi_long: if self.ma_trend > 0 and self.rsi_value >= self.rsi_long:
self.buy(bar.close_price+5, self.fixed_size) self.buy(bar.close_price + 5, self.fixed_size)
elif self.ma_trend < 0 and self.rsi_value <= self.rsi_short: elif self.ma_trend < 0 and self.rsi_value <= self.rsi_short:
self.short(bar.close_price-5, self.fixed_size) self.short(bar.close_price - 5, self.fixed_size)
elif self.pos > 0: elif self.pos > 0:
if self.ma_trend < 0 or self.rsi_value < 50: if self.ma_trend < 0 or self.rsi_value < 50:
self.sell(bar.close_price-5, abs(self.pos)) self.sell(bar.close_price - 5, abs(self.pos))
elif self.pos < 0: elif self.pos < 0:
if self.ma_trend > 0 or self.rsi_value > 50: if self.ma_trend > 0 or self.rsi_value > 50:
self.cover(bar.close_price+5, abs(self.pos)) self.cover(bar.close_price + 5, abs(self.pos))
self.put_event() self.put_event()
def on_15min_bar(self, bar: BarData):
def on_15min_bar(self, bar:BarData):
"""""" """"""
self.am15.update_bar(bar) self.am15.update_bar(bar)
if not self.am15.inited: if not self.am15.inited:
@ -141,4 +141,3 @@ class MultiTimeframeStrategy(CtaTemplate):
Callback of stop order update. Callback of stop order update.
""" """
pass pass