From e5aa92aaaf232e9928494745522a4330c917ecb0 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Wed, 19 Oct 2016 11:01:59 +0800 Subject: [PATCH] =?UTF-8?q?CTA=E7=9A=84=E7=AD=96=E7=95=A5=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97=EF=BC=8C=E4=B8=BB=E8=A6=81=E6=98=AF?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=BC=80=E5=85=B3=EF=BC=8C=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=BC=80=E4=BB=93=E3=80=81=E5=B9=B3=E4=BB=93=E3=80=81=E5=8A=A0?= =?UTF-8?q?=E4=BB=93=E3=80=81=E6=AD=A2=E6=8D=9F=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctaAlgo/ctaPolicy.py | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 vn.trader/ctaAlgo/ctaPolicy.py diff --git a/vn.trader/ctaAlgo/ctaPolicy.py b/vn.trader/ctaAlgo/ctaPolicy.py new file mode 100644 index 00000000..e75b1628 --- /dev/null +++ b/vn.trader/ctaAlgo/ctaPolicy.py @@ -0,0 +1,65 @@ +# encoding: UTF-8 + +from ctaBase import * +from vtConstant import * + + +DEBUGCTALOG = True + +class CtaPolicy(object): + """CTA的策略规则类 + 包括: + 1、风险评估 + 2、最低止损位置 + 3、保本止损位置 + 4、跟随止损/止盈位置 + 5、是否加仓等 + + R1,Big Range/Renko + R2,Small Range/Renko + """ + + def __init__(self, r1Period=EMPTY_STRING, r2Period=EMPTY_STRING): + + self.openR1Period = r1Period # 开仓周期Mode + self.openR2Period = r2Period # 开仓周期Mode + + self.entryPrice = EMPTY_FLOAT # 开仓价格 + self.lastPeriodBasePrice = EMPTY_FLOAT # 上一个周期内的最近高价/低价(看R2 Rsi的高点和低点) + self.entryTime = None + + self.riskLevel = EMPTY_INT # 风险评分,1、低;2、中;3、高 + + self.cancelInNextBar = False + + self.addPos = False # 是否加仓 + self.addPosOnPips = EMPTY_INT # 价格超过开仓价多少点时加仓 + self.addPosOnRtnPercent = EMPTY_FLOAT # 价格回撤比例时加仓 + self.addPosOnRsiRtnWithPips = EMPTY_INT # 价格超过开仓价,并且低位RSI反转(多:RSI低位折返,空:RSI高位折返) + self.addPosOnKdjRtnWithPips = EMPTY_INT # 价格超过开仓价,并且低位Kdj反转(多:Kdj低位折返,空:Kdj高位折返) + + self.exitOnStopPrice = EMPTY_FLOAT # 固定止损价格。 这个规则最优先匹配,作为最大亏损线。 + self.exitOnWinPrice = EMPTY_FLOAT # 固定止盈价格。 + + self.exitOnProtectedPrice = EMPTY_FLOAT # 保本价格。 + self.exitOnLastRtnPips = EMPTY_INT # 盈利后,最后开仓价的回调点数。 使用时,pips* minDiff + self.exitOnTopRtnPips = EMPTY_INT # 盈利后,最高盈利的回撤点数。 使用时,pips * minDiff + + self.exitOnR2RsiRtn = False # First RSI Return + self.exitOnR2EmaCrossed = False # EMA(inputEma1Len) Cross Above、 Under + self.exitOnR2KamaCrossed = False # AMA(inputAma1Len) Cross Above、 Under + self.exitOnR2KamaRtn = False # 盈利后,Kama[-1] vs Kama[-2] + + self.exitOnR1RsiRtn = False # First RSI Return + self.exitOnR1EmaCrossed = False # EMA(inputEma1Len) Cross Above、 Under + self.exitOnR1KamaCrossed = False # AMA(inputAma1Len) Cross Above、 Under + self.exitOnR1KamaRtn = False # 盈利后,Kama[-1] vs Kama[-2] + + self.exitOnR1PeriodChanged = False # R1 Period Changed, if True,openR1Period != periodMode + self.exitOnR2PeriodChanged = False # R2 Period Changed, if True,openR2Period != periodMode + + self.exitOnR1PeriodModes = [] # 可以与exitOnR1PeriodChanged ,指定的立场周期;进入后,激活 exitOnR2RsiRtn + + + +