TB改写问题 [文华财经]
- 咨询内容:
//------------------------------------------------------------------------// 简称: ITF_TurtleRules_V105// 名称: TurtleRules_V105// 类别: 公式应用// 类型: 用户应用// 输出://------------------------------------------------------------------------
Params Numeric Capital(1000000); // 初始资金; Numeric DateStart(20120101); // 此日的开盘将资金初始化为Capital; Numeric Direction(0); // 多空信号过滤条件,值为0不过滤,值为1只做多,值为1只做空; Numeric RiskRatio(1); // % Risk Per N ( 0 - 100) Numeric LengthAtr(20); // 平均波动周期 ATR Length Numeric LengthFast(20); // 短周期 BreakOut Length Numeric LengthSlow(55); // 长周期 FailSafe Length Numeric LengthExit(10); // 离市周期 Trailing Exit Length Bool LastProfitableTradeFilter(True); // 使用入市过滤条件 Bool UseLongSysFlag(False); // 只是用短期系统Vars Numeric MinPoint; // 最小变动单位 NumericSeries N; // N 值 NumericSeries TotalEquity; // 按最新收盘价计算出的总资产 NumericSeries TurtleUnits; // 交易单位 NumericSeries DonchianFastUpper; // 短周期唐奇安通道上轨,长度LengthFast; NumericSeries DonchianFastLower; // 短周期唐奇安通道下轨,长度LengthFast; NumericSeries DonchianSlowUpper; // 长周期唐奇安通道上轨,长度LengthSlow; NumericSeries DonchianSlowLower; // 长周期唐奇安通道下轨,长度LengthSlow; NumericSeries DonchianExitUpper; // 离市时判断需要的N周期最高价,长度LengthExit; NumericSeries DonchianExitLower; // 离市时判断需要的N周期最低价,长度LengthExit; NumericSeries MyPrice; NumericSeries MyExitPrice; // 平仓价格 NumericSeries preEntryPrice(0); // 前一次开仓的价格 BoolSeries PreBreakoutFailure(false); // 前一次突破是否失败 Bool SendOrderThisBar(False); // 当前Bar有过交易 NumericSeries AtrAve; // 记录日线级别长度为lengthAtr的平均真实波幅; NumericSeries DayHigh; // 一天中的最高价; NumericSeries DayLow; // 一天中的最低价; Numeric i; // 循环计算所需指针; NumericSeries Atr(0); // 当天的ATR Numeric AtrIndex(0); // 存储真实波幅的全局变量的环的索引值; NumericSeries DayCount(0); // 交易日数; NumericSeries CloseD_1; // 上一个交易日收盘价,过度CloseD(1); NumericSeries MyBarsSinceToday; // 过度BarsSinceToday; NumericSeries CapitalCurrent; // 调整资产规模后的最新资产; NumericSeries CapitalPeak; // 调整资产规模后的最新资产峰值; NumericSeries ProfitClosing; // 平仓盈亏; NumericSeries LotsTotal(0); // 持仓手数; NumericSeries MyAvgEntryPrice; // 持仓均价; NumericSeries TimesOverWeight(0); // 加仓次数记录;Begin MinPoint = MinMove*PriceScale; MyBarsSinceToday = BarsSinceToday; CloseD_1 = CloseD(1); if(BarsSinceToday==0) { DayCount = DayCount + 1; //记录交易日数; DayHigh = High; DayLow = Low; //从第二个交易日开始记录; if(DayCount>=2) { // 前一日真实波幅; Atr = max(max(Abs(DayHigh[1]-CloseD_1),Abs(DayLow[1]-CloseD_1)),DayHigh[1]-DayLow[1]); // 存储前一天的Atr到全局变量环0-19; AtrIndex = (DayCount-2)%LengthAtr; SetGlobalVar(AtrIndex,Atr[1]); } // 从第LengthAtr+1个交易日开始计算; if(DayCount>=LengthAtr+1) { // 计算日线级别长度为LengthAtr的平均真实波幅; AtrAve = 0 ; for i=0 to LengthAtr-1 { AtrAve = AtrAve + getGlobalVar(i); } AtrAve = AtrAve/LengthAtr; N = IntPart(AtrAve); DonchianFastUpper = Highest(DayHigh[1],(LengthAtr-0.1)*(MyBarsSinceToday[1]+1)); DonchianFastLower = Lowest(DayLow[1],(LengthAtr-0.1)*(MyBarsSinceToday[1]+1)); DonchianSlowUpper = Highest(DayHigh[1],(LengthSlow-0.1)*(MyBarsSinceToday[1]+1)); DonchianSlowLower = Lowest(DayLow[1],(LengthSlow-0.1)*(MyBarsSinceToday[1]+1)); DonchianExitUpper = Highest(DayHigh[1],(LengthExit-0.1)*(MyBarsSinceToday[1])); DonchianExitLower = Lowest(DayLow[1],(LengthExit-0.1)*(MyBarsSinceToday[1])); } // 资产规模调整; // 如果有设置初始本金的开始时间; if(Date==DateStart and DateStart!=0 and Date!=Date[1]) { CapitalCurrent = Capital; // 调整资产规模后的最新资产; Commentary("标识:第99行"); } // 如果没有设置初始本金的开始时间; else if(DateStart==0 or (BarStatus==0 and Date>DateStart) ) { CapitalCurrent = Capital; Commentary("标识:第105行"); } CapitalPeak = Max(Max(Capital,CapitalCurrent[1]),CapitalCurrent+ProfitClosing); // 调整资产规模后的最新资产峰值; //标准单位头寸 = (最新资产*风险比例)/价值波动率 TurtleUnits = (CapitalCurrent*RiskRatio/100) /(N * ContractUnit()*BigPointValue()); TurtleUnits = IntPart(TurtleUnits); // 对小数取整 // PlotString("Units","Units="+Text(TurtleUnits),High+(High-Low),white); // PlotString("N","N="+Text(N),Low-(High-Low)/2,white); } Else { DayHigh = Max(DayHigh,High); DayLow = Min(DayLow,Low); }
If(MarketPosition==0 and TurtleUnits>=1 and DonchianFastUpper>0) { // 首次入市1:带过滤条件的,如果过滤条件为真,则需要前一笔交易是否是突破失败; if(LastProfitableTradeFilter==false Or PreBreakoutFailure ) { //开多1:突破短周期唐奇安通道上轨; If(High>DonchianFastUpper and Direction!=-1) { MyPrice = Max(Open,DonchianFastUpper)+MinPoint; preEntryPrice = MyPrice; Buy(TurtleUnits,MyPrice); MyExitPrice = MyPrice - 2*N; SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = TurtleUnits; TimesOverWeight = 1; } //开空1:突破短周期唐奇安通道下轨; if(Low<DonchianFastLower and Direction!=1) { MyPrice = Min(Open,DonchianFastLower)-MinPoint; preEntryPrice = MyPrice; SellShort(TurtleUnits,MyPrice); MyExitPrice = MyPrice + 2*N; SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = TurtleUnits; TimesOverWeight = 1; } } // 首次入市2:过滤条件之外的,长周期唐奇安通道突破开仓; //开多2:突破长周期唐奇安通道上轨; else { if(CrossOver(High,DonchianSlowUpper) and Direction!=-1 and UseLongSysFlag = True) { MyPrice = Max(Open,DonchianSlowUpper)+MinPoint; preEntryPrice = MyPrice; Buy(TurtleUnits,MyPrice); MyExitPrice = MyPrice - 2*N; SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = TurtleUnits; TimesOverWeight = 1; } //开空2:突破长周期唐奇安通道下轨; if(CrossUnder(Low,DonchianSlowLower) and Direction!=1 and UseLongSysFlag = True) { MyPrice = Min(Open,DonchianSlowLower)+MinPoint; preEntryPrice = MyPrice; SellShort(TurtleUnits,MyPrice); MyExitPrice = MyPrice + 2*N; SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = TurtleUnits; TimesOverWeight = 1; } } } // 当持有多单; if(MarketPosition==1 and TimesOverWeight>0) { //离市:价格反向穿越离市的唐奇安通道; if(CrossUnder(Low,DonchianExitLower)) { MyPrice = Min(Open,DonchianExitLower)-MinPoint; Sell(0,MyPrice); PreBreakoutFailure = False; //假突破值为假; // PlotBool("突破",PreBreakoutFailure,High,white); ProfitClosing = (MyPrice - MyAvgEntryPrice)*LotsTotal*ContractUnit()*BigPointValue(); CapitalCurrent = CapitalCurrent + ProfitClosing; TimesOverWeight = 0; LotsTotal = 0; } Else { // 第一次加仓:如果开盘价就大于最近一次开仓价N,则以开盘价发单; if(Open>LastEntryPrice+0.5*N and TurtleUnits>=1 and TimesOverWeight<2) { MyPrice = Open; preEntryPrice = MyPrice; Buy(TurtleUnits,MyPrice); SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = TimesOverWeight + 1; } // 以最高价为标准,判断能进行几次增仓 while(High >= preEntryPrice + N and TimesOverWeight<2) { MyPrice = preEntryPrice + N; preEntryPrice = MyPrice; Buy(TurtleUnits,MyPrice); SendOrderThisBar = True; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = TimesOverWeight + 1; } // 第二三次加仓:如果开盘价就大于最近一次开仓价+0.5*N,则以开盘价发单; if(Open>LastEntryPrice+0.5*N and TurtleUnits>=2 and TimesOverWeight<4) { MyPrice = Open; preEntryPrice = MyPrice; Buy(TurtleUnits,MyPrice); SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = TimesOverWeight + 1; } // 第二三次加仓:以最高价为标准,判断能进行几次增仓 while(High >= preEntryPrice + 0.5*N and TimesOverWeight<4) { MyPrice = preEntryPrice + 0.5 * N; preEntryPrice = MyPrice; Buy(TurtleUnits,MyPrice); SendOrderThisBar = True; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = TimesOverWeight + 1; } // 止损:价格反向穿越最近一次开仓价格-2N; if(Low<LastEntryPrice-2*N) { MyPrice = Min(Open,LastEntryPrice-2*N)-MinPoint; Sell(0,MyPrice); PreBreakoutFailure = True; //假突破值为真; // PlotBool("突破",PreBreakoutFailure,High,white); ProfitClosing = (MyPrice - MyAvgEntryPrice)*LotsTotal*ContractUnit()*BigPointValue(); CapitalCurrent = CapitalCurrent + ProfitClosing; TimesOverWeight = 0; LotsTotal = 0; } } } // 当持有空单; else if(MarketPosition==-1 and TimesOverWeight>0) { // 离市:价格反向穿越离市的唐奇安通道; if(CrossOver(High,DonchianExitUpper)) { MyPrice = Max(Open,DonchianExitUpper)+MinPoint; BuyToCover(0,MyPrice); PreBreakoutFailure = False; //假突破值为假; // PlotBool("突破",PreBreakoutFailure,High,white); ProfitClosing = (MyAvgEntryPrice - MyPrice)*LotsTotal*ContractUnit()*BigPointValue(); CapitalCurrent = CapitalCurrent + ProfitClosing; TimesOverWeight = 0; LotsTotal = 0; } Else { // 第一次加仓:与最近一次开仓价格间隔N开仓; if(Open<LastEntryPrice-N and TurtleUnits>=1 and TimesOverWeight<2) { MyPrice = Open; preEntryPrice = MyPrice; SellShort(TurtleUnits,MyPrice); SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = 0; } // 以最低价为标准,判断能进行几次增仓 while(Low <= preEntryPrice - N and TimesOverWeight<2) { MyPrice = preEntryPrice - N; preEntryPrice = MyPrice; SellShort(TurtleUnits,MyPrice); SendOrderThisBar = True; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = TimesOverWeight + 1; } // 二三次加仓:与最近一次开仓价格间隔0.5*N开仓; if(Open<LastEntryPrice-0.5*N and TurtleUnits>=2 and TimesOverWeight<4) { MyPrice = Open; preEntryPrice = MyPrice; SellShort(TurtleUnits,MyPrice); SendOrderThisBar = true; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = 0; } // 以最低价为标准,判断能进行几次增仓 while(Low <= preEntryPrice - 0.5*N and TimesOverWeight<4) { MyPrice = preEntryPrice - 0.5 * N; preEntryPrice = MyPrice; SellShort(TurtleUnits,MyPrice); SendOrderThisBar = True; MyAvgEntryPrice = AvgEntryPrice; LotsTotal = LotsTotal + TurtleUnits; TimesOverWeight = TimesOverWeight + 1; } // 止损:价格反向穿越最近一次开仓价格+2N; if(High>LastEntryPrice+2*N) { MyPrice = Max(Open,LastEntryPrice+2*N)+MinPoint; BuyToCover(0,MyPrice); PreBreakoutFailure = True; //假突破值为真; // PlotBool("突破",PreBreakoutFailure,High,white); ProfitClosing = (MyAvgEntryPrice - MyPrice)*LotsTotal*ContractUnit()*BigPointValue(); CapitalCurrent = CapitalCurrent + ProfitClosing; TimesOverWeight = 0; LotsTotal = 0; } } } PlotNumeric("DonchianFastUpper",DonchianFastUpper); PlotNumeric("DonchianFastLower",DonchianFastLower); PlotNumeric("DonchianSlowUpper",DonchianSlowUpper); PlotNumeric("DonchianSlowLower",DonchianSlowLower); PlotNumeric("DonchianExitUpper",DonchianExitUpper); PlotNumeric("DonchianExitLower",DonchianExitLower); Commentary("点值="+Text(ContractUnit()*BigPointValue())); Commentary("TotalEquity="+Text(TotalEquity)); Commentary("N="+Text(N)); Commentary("Units="+Text(TurtleUnits)); // Commentary("Atr="+Text(Atr)); // Commentary("AtrAve="+Text(AtrAve)); // PlotNumeric("AtrAve",AtrAve); Commentary("DayCount="+Text(DayCount)); Commentary("MyBarsSinceToday="+Text(MyBarsSinceToday[1]+1)); Commentary("CapitalCurrent="+Text(CapitalCurrent)); Commentary("LotsTotal="+Text(LotsTotal)); Commentary("MyAvgEntryPrice="+Text(MyAvgEntryPrice)); Commentary("MyPrice="+Text(MyPrice)); Commentary("ProfitClosing="+Text(ProfitClosing)); Commentary("CurrentBar="+Text(CurrentBar));End - 文华技术人员:
您的模型是含有加仓编写的模型赢顺V6.7不支持加仓的编写
请下载赢智V8.2使用http://cxh.wenhua.com.cn/index.asp
- 文华客服:
您指的显示100变量重复定义是怎样的情况 是把1楼的源码加入到赢智V8.2中的编写平台吗
麦语言的编写 不兼容楼上编写的 需要改写后才能实现的
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容