




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
原版海龜策略(TB版)策略信號代碼:ParamsNumericCapital(1000000);//初始資金;NumericDateStart(20120101);//此日的開盤將資金初始化為Capital;NumericDirection(0);//多空信號過濾條件,值為0不過濾,值為1只做多,值為1只做空;NumericRiskRatio(1);//%RiskPerN(0-100)NumericLengthAtr(20);//平均波動周期ATRLengthNumericLengthFast(20);//短周期BreakOutLengthNumericLengthSlow(55);//長周期FailSafeLengthNumericLengthExit(10);//離市周期TrailingExitLengthBoolLastProfitableTradeFilter(True);//使用入市過濾條件VarsNumericMinPoint;//最小變動單位NumericSeriesN;//N值NumericSeriesTotalEquity;//按最新收盤價計算出的總資產(chǎn)NumericSeriesTurtleUnits;//交易單位NumericSeriesDonchianFastUpper;//短周期唐奇安通道上軌,長度LengthFast;NumericSeriesDonchianFastLower;//短周期唐奇安通道下軌,長度LengthFast;NumericSeriesDonchianSlowUpper;//長周期唐奇安通道上軌,長度LengthSlow;NumericSeriesDonchianSlowLower;//長周期唐奇安通道下軌,長度LengthSlow;NumericSeriesDonchianExitUpper;//離市時判斷需要的N周期最高價,長度LengthExit;NumericSeriesDonchianExitLower;//離市時判斷需要的N周期最低價,長度LengthExit;NumericSeriesMyPrice;NumericSeriesMyExitPrice;//平倉價格NumericSeriespreEntryPrice(0);//前一次開倉的價格BoolSeriesPreBreakoutFailure(false);//前一次突破是否失敗BoolSendOrderThisBar(False);//當(dāng)前Bar有過交易NumericSeriesAtrAve;//記錄日線級別長度為lengthAtr的平均真實(shí)波幅;NumericSeriesDayHigh;//一天中的最高價;NumericSeriesDayLow;//一天中的最低價;Numerici;//循環(huán)計算所需指針;NumericSeriesAtr(0);//當(dāng)天的ATRNumericAtrIndex(0);//存儲真實(shí)波幅的全局變量的環(huán)的索引值;NumericSeriesDayCount(0);//交易日數(shù);NumericSeriesCloseD_1;//上一個交易日收盤價,過度CloseD(1);NumericSeriesMyBarsSinceToday;//過度BarsSinceToday;NumericSeriesCapitalCurrent;//調(diào)整資產(chǎn)規(guī)模后的最新資產(chǎn);NumericSeriesCapitalPeak;//調(diào)整資產(chǎn)規(guī)模后的最新資產(chǎn)峰值;NumericSeriesProfitClosing;//平倉盈虧;NumericSeriesLotsTotal(0);//持倉手?jǐn)?shù);NumericSeriesMyAvgEntryPrice;//持倉均價;NumericSeriesTimesOverWeight(0);//加倉次數(shù)記錄;BeginMinPoint=MinMove*PriceScale;MyBarsSinceToday=BarsSinceToday;CloseD_1=CloseD(1);if(BarsSinceToday==0){DayCount=DayCount+1;//記錄交易日數(shù);DayHigh=High;DayLow=Low;//從第二個交易日開始記錄;if(DayCount>=2){//前一日真實(shí)波幅;Atr=max(max(Abs(DayHigh[1]-CloseD_1),Abs(DayLow[1]-CloseD_1)),DayHigh[1]-DayLow[1]);//存儲前一天的Atr到全局變量環(huán)0-19;AtrIndex=(DayCount-2)%LengthAtr;SetGlobalVar(AtrIndex,Atr[1]);}//從第LengthAtr+1個交易日開始計算;if(DayCount>=LengthAtr+1){//計算日線級別長度為LengthAtr的平均真實(shí)波幅;AtrAve=0;fori=0toLengthAtr-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]));}//資產(chǎn)規(guī)模調(diào)整;//如果有設(shè)置初始本金的開始時間;if(Date==DateStartandDateStart!=0andDate!=Date[1]){CapitalCurrent=Capital;//調(diào)整資產(chǎn)規(guī)模后的最新資產(chǎn);Commentary("標(biāo)識:第99行");}//如果沒有設(shè)置初始本金的開始時間;elseif(DateStart==0or(BarStatus==0andDate>DateStart)){CapitalCurrent=Capital;Commentary("標(biāo)識:第105行");}CapitalPeak=Max(Max(Capital,CapitalCurrent[1]),CapitalCurrent+ProfitClosing);//調(diào)整資產(chǎn)規(guī)模后的最新資產(chǎn)峰值;//標(biāo)準(zhǔn)單位頭寸=(最新資產(chǎn)*風(fēng)險比例)/價值波動率TurtleUnits=(CapitalCurrent*RiskRatio/100)/(N*ContractUnit()*BigPointValue());TurtleUnits=IntPart(TurtleUnits);//對小數(shù)取整//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==0andTurtleUnits>=1andDonchianFastUpper>0){//首次入市1:帶過濾條件的,如果過濾條件為真,則需要前一筆交易是否是突破失敗;if(LastProfitableTradeFilter==falseOrPreBreakoutFailure){//開多1:突破短周期唐奇安通道上軌;If(High>DonchianFastUpperandDirection!=-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<DonchianFastLowerandDirection!=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)andDirection!=-1){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)andDirection!=1){MyPrice=Min(Open,DonchianSlowLower)+MinPoint;preEntryPrice=MyPrice;SellShort(TurtleUnits,MyPrice);MyExitPrice=MyPrice+2*N;SendOrderThisBar=true;MyAvgEntryPrice=AvgEntryPrice;LotsTotal=TurtleUnits;TimesOverWeight=1;}}}//當(dāng)持有多單;if(MarketPosition==1andTimesOverWeight>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{//加倉:如果開盤價就大于最近一次開倉價+0.5*N,則以開盤價發(fā)單;if(Open>LastEntryPrice+0.5*NandTurtleUnits>=1andTimesOverWeight<4){MyPrice=Open;preEntryPrice=MyPrice;Buy(TurtleUnits,MyPrice);SendOrderThisBar=true;MyAvgEntryPrice=AvgEntryPrice;LotsTotal=LotsTotal+TurtleUnits;TimesOverWeight=TimesOverWeight+1;}//以最高價為標(biāo)準(zhǔn),判斷能進(jìn)行幾次增倉while(High>=preEntryPrice+0.5*NandTimesOverWeight<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;}}}//當(dāng)持有多單;if(MarketPosition==1andTimesOverWeight>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{//加倉:如果開盤價就大于最近一次開倉價+0.5*N,則以開盤價發(fā)單;if(Open>LastEntryPrice+0.5*NandTurtleUnits>=1andTimesOverWeight<4){MyPrice=Open;preEntryPrice=MyPrice;Buy(TurtleUnits,MyPrice);SendOrderThisBar=true;MyAvgEntryPrice=AvgEntryPrice;LotsTotal=LotsTotal+TurtleUnits;TimesOverWeight=TimesOverWeight+1;}//以最高價為標(biāo)準(zhǔn),判斷能進(jìn)行幾次增倉while(High>=preEntryPrice+0.5*NandTimesOverWeight<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;}}}//當(dāng)持有空單;elseif(MarketPosition==-1andTimesOverWeight>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{//加倉:與最近一次開倉價格間隔0.5*N開倉;if(Open<LastEntryPrice-0.5*NandTurtleUnits>=1andTimesOverWeight<4){MyPrice=Open;preEntryPrice=MyPrice;SellShort(TurtleUnits,MyPrice);SendOrderThisBar=true;MyAvgEntryPrice=AvgEntryPrice;LotsTotal=LotsTotal+TurtleUnits;TimesOverWeight=0;}//以最低價為標(biāo)準(zhǔn),判斷能進(jìn)行幾次增倉while(Low<=preEntryPrice-0.5*NandTimesOverWeight<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)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 健康促進(jìn)與健康教育課件
- 生理衛(wèi)生保健知識講座
- T/ZGZS 0303-2023再生工業(yè)鹽硫酸鈉
- 幼兒園指甲衛(wèi)生
- 咖啡店畢業(yè)設(shè)計
- 校園社團(tuán)管理系統(tǒng)前端設(shè)計
- 創(chuàng)傷現(xiàn)場急救課件
- 健康傳播材料課件
- 體育科學(xué)碩士研究生入學(xué)考試題及答案2025年
- 藏族傳統(tǒng)謎語文化解析
- 2024屆江蘇省南京東山外國語學(xué)校高考三模數(shù)學(xué)試卷(原卷版)
- 2024年湖南湘西自治州公開招募“三支一扶”高校畢業(yè)生(高頻重點(diǎn)復(fù)習(xí)提升訓(xùn)練)共500題附帶答案詳解
- 打地坪施工合同范本
- 廠區(qū)保潔服務(wù)投標(biāo)方案【2024版】技術(shù)方案
- 2024中考化學(xué)成都10年考情及趨勢分析【必考知識點(diǎn)】
- 腹腔鏡手術(shù)設(shè)備使用說明與注意事項(xiàng)
- 二手房委托代理協(xié)議書范本參考
- 西藏2024屆小升初模擬數(shù)學(xué)測試卷含解析
- 人教版五年級下冊美術(shù)測試題
- JBT 14716-2023 增材制造裝備 面曝光光固化三維打印機(jī) (正式版)
- 自體外周血干細(xì)胞移植的護(hù)理
評論
0/150
提交評論