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 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容