




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
海龜法則策略(MC版)一、海龜交易法基礎(chǔ)資金管理:采用波動(dòng)幅度(ATR)管理資金。入市信號(hào):多頭:當(dāng)價(jià)格超過(guò)20日高點(diǎn)時(shí),入市做多??疹^:當(dāng)價(jià)格跌破20日低點(diǎn)時(shí),入市做空。二、增倉(cāng)法則初始建倉(cāng):入市時(shí),只建立一個(gè)單位的頭寸。加倉(cāng)條件:在建立頭寸之后,以0.5ATR的間隔增加頭寸,直到達(dá)到最大許可建倉(cāng)單位數(shù)(LTT)。三、離場(chǎng)法則清倉(cāng)條件:對(duì)于多頭頭寸,當(dāng)價(jià)格跌破10日低點(diǎn)時(shí)清倉(cāng)。對(duì)于空頭頭寸,當(dāng)價(jià)格超過(guò)10日高點(diǎn)時(shí)清倉(cāng)。四、止損法則最大止損風(fēng)險(xiǎn):任何一筆交易的風(fēng)險(xiǎn)不超過(guò)2%。止損點(diǎn)設(shè)置:初始止損點(diǎn)設(shè)置在價(jià)格波動(dòng)2ATR的位置。每次加倉(cāng)后,之前建倉(cāng)頭寸的止損點(diǎn)均向加倉(cāng)點(diǎn)位移動(dòng)0.5ATR,以保證全部頭寸的風(fēng)險(xiǎn)最小。五、代碼邏輯概覽輸入?yún)?shù):ATRlen:計(jì)算ATR的周期長(zhǎng)度(20)Flen:計(jì)算20日高點(diǎn)和低點(diǎn)的周期長(zhǎng)度(20)LTT:最大交易單位數(shù)Percent:增倉(cāng)時(shí)每次增加的頭寸比例(0.5)StopATRCnt:止損時(shí)使用的ATR倍數(shù)(2)主要變量:Myfhigh:20日高點(diǎn)Myflow:20日低點(diǎn)mp:市場(chǎng)位置(多頭或空頭)Myatr:計(jì)算得到的ATR值StopPrice:止損價(jià)格AveragePrice:持倉(cāng)均價(jià)邏輯流程:初始化:計(jì)算ATR值,檢查市場(chǎng)位置。入場(chǎng):根據(jù)20日高點(diǎn)和低點(diǎn)決定買(mǎi)賣(mài)。增倉(cāng):在已有頭寸基礎(chǔ)上,根據(jù)市場(chǎng)位置和ATR值增加頭寸。止損:根據(jù)市場(chǎng)位置和ATR值設(shè)置止損價(jià)格,并隨著加倉(cāng)移動(dòng)止損點(diǎn)。離場(chǎng):根據(jù)10日突破法則清倉(cāng)。策略代碼注解:輸入?yún)?shù)
ATRlen
:計(jì)算ATR的周期長(zhǎng)度,這里設(shè)為20。
Flen
:計(jì)算20日高點(diǎn)和低點(diǎn)的周期長(zhǎng)度,這里也設(shè)為20。
LTT
:最大交易單位數(shù)。
Percent
:增倉(cāng)時(shí)每次增加的頭寸比例,這里設(shè)為0.5。
StopATRCnt
:止損時(shí)使用的ATR倍數(shù),這里設(shè)為2。變量定義
Myfhigh
:20日高點(diǎn)。
Myflow
:20日低點(diǎn)。
mp
:市場(chǎng)位置(多頭或空頭)。
Myatr
:計(jì)算得到的ATR值。
StopPrice
:止損價(jià)格。
AveragePrice
:持倉(cāng)均價(jià)。初始化操作在每次交易開(kāi)始時(shí),計(jì)算ATR值,并檢查市場(chǎng)位置。日志打印打印當(dāng)前日期、時(shí)間、價(jià)格、買(mǎi)賣(mài)價(jià)、當(dāng)前K線索引、ATR值、市場(chǎng)位置、合約數(shù)、各頭寸的入場(chǎng)價(jià)格。入場(chǎng)邏輯當(dāng)市場(chǎng)位置為0(無(wú)持倉(cāng))時(shí),計(jì)算20日高點(diǎn)和低點(diǎn)。如果價(jià)格超過(guò)20日高點(diǎn),則買(mǎi)入(做多)。如果價(jià)格跌破20日低點(diǎn),則賣(mài)出(做空)。增倉(cāng)邏輯當(dāng)當(dāng)前合約數(shù)等于
LTT
時(shí),根據(jù)市場(chǎng)位置和ATR值增加頭寸。每次增倉(cāng)的間隔為0.5N(0.5倍ATR)。止損邏輯計(jì)算持倉(cāng)均價(jià)。根據(jù)市場(chǎng)位置和ATR值設(shè)置止損價(jià)格。每增加一次頭寸,之前的止損點(diǎn)均向加倉(cāng)點(diǎn)位移動(dòng)0.5N。離場(chǎng)邏輯使用10日突破退出法則。對(duì)于多頭頭寸,當(dāng)價(jià)格跌破10日低點(diǎn)時(shí)清倉(cāng)。對(duì)于空頭頭寸,當(dāng)價(jià)格超過(guò)10日高點(diǎn)時(shí)清倉(cāng)。代碼邏輯1.
初始化:計(jì)算ATR值,檢查市場(chǎng)位置。2.
入場(chǎng):當(dāng)無(wú)持倉(cāng)時(shí),根據(jù)20日高點(diǎn)和低點(diǎn)決定買(mǎi)賣(mài)。3.
增倉(cāng):在已有頭寸基礎(chǔ)上,根據(jù)市場(chǎng)位置和ATR值增加頭寸。4.
止損:根據(jù)市場(chǎng)位置和ATR值設(shè)置止損價(jià)格。5.
離場(chǎng):根據(jù)10日突破法則清倉(cāng)。本策略實(shí)現(xiàn)了海龜交易法的基本邏輯,通過(guò)計(jì)算和比較價(jià)格的移動(dòng)平均和ATR值來(lái)決定買(mǎi)賣(mài)時(shí)機(jī)和頭寸管理。策略代碼://輸入?yún)?shù)?Input:ATRlen(20),Flen(20),LTT(10),Percent(0.5),StopATRCnt(2);//變量定義?var:Myfhigh(0),Myflow(0),mp(0),Myatr(0),StopPrice(0),AveragePrice(0);//初始化操作mp=marketposition;ifmp<>0andmp[1]=0thenbeginMyatr=AvgTrueRange(ATRlen);//計(jì)算ATRend;//打印?ifdom_isconnected=truethenbeginprint(date,"",CurrentTime_s,"PRICE=",close,"ASK1=",q_ask,"BID=",q_bid,"BarIndex=",currentbar,"ATR=",Myatr,"MP=",mp,"Cnt=",currentcontracts,"EntryPrice1=",PosTradeEntryPrice(0,0),"EntryPrice2=",PosTradeEntryPrice(0,1),"EntryPrice3=",PosTradeEntryPrice(0,2),"EntryPrice4=",PosTradeEntryPrice(0,3));endelsebeginprint(date,"",CurrentTime_s,"PRICE=",close,"ASK1=",q_ask,"BID=",q_bid,"BarIndex=",currentbar,"ATR=",Myatr,"MP=",mp,"Cnt=",currentcontracts,"EntryPrice1=",PosTradeEntryPrice(0,0),"EntryPrice2=",PosTradeEntryPrice(0,1),"EntryPrice3=",PosTradeEntryPrice(0,2),"EntryPrice4=",PosTradeEntryPrice(0,3));end;//入場(chǎng)ifmp=0thenbeginMyfhigh=Highest(high,Flen);//20日高點(diǎn)Myflow=Lowest(low,Flen);//20日低點(diǎn)buy("buy-entry")LTTsharesnextbaratMyfhighstop;sellshort("Sell-entry")LTTsharesnextbaratMyflowstop;end;//增倉(cāng)ifcurrentcontracts=LTTthenbeginifmp=1thenbeginbuy("buy-add1")LTTsharesnextbaratPosTradeEntryPrice(0,0)+(Percent*Myatr)stop;end;ifmp=-1thenbeginsellshort("Sell-add1")LTTsharesnextbaratPosTradeEntryPrice(0,0)-(Percent*Myatr)stop;end;end;ifcurrentcontracts=2*LTTthenbeginifmp=1thenbeginifPosTradeEntryPrice(0,1)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,0)+PosTradeEntryPrice(0,1))/2;StopPrice=AveragePrice+Percent*Myatr+(Percent/2)*Myatr;buy("buy-add2")LTTsharesnextbaratStopPricestop;end;ifPosTradeEntryPrice(0,1)=0thenbeginStopPrice=PosTradeEntryPrice(0,0)+Percent*Myatr+(Percent/2)*Myatr;buy("buy-add2")LTTsharesnextbaratStopPricestop;end;end;ifmp=-1thenbeginifPosTradeEntryPrice(0,1)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,0)+PosTradeEntryPrice(0,1))/2;StopPrice=AveragePrice-Percent*Myatr-(Percent/2)*Myatr;sellshort("Sell-add2")LTTsharesnextbaratStopPricestop;end;ifPosTradeEntryPrice(0,1)=0thenbeginStopPrice=PosTradeEntryPrice(0,0)-Percent*Myatr-(Percent/2)*Myatr;sellshort("Sell-add2")LTTsharesnextbaratStopPricestop;end;end;end;ifcurrentcontracts=3*LTTthenbeginifmp=1thenbeginifPosTradeEntryPrice(0,2)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,0)+PosTradeEntryPrice(0,1)+PosTradeEntryPrice(0,2))/3;StopPrice=AveragePrice+Percent*Myatr+2*(Percent/2)*Myatr;buy("buy-add3")LTTsharesnextbaratStopPricestop;end;ifPosTradeEntryPrice(0,2)=0thenbeginifPosTradeEntryPrice(0,1)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,0)+PosTradeEntryPrice(0,1))/2;StopPrice=AveragePrice+Percent*Myatr+2*(Percent/2)*Myatr;buy("buy-add3")LTTsharesnextbaratStopPricestop;end;ifPosTradeEntryPrice(0,1)=0thenbeginStopPrice=PosTradeEntryPrice(0,0)+Percent*Myatr+2*(Percent/2)*Myatr;buy("buy-add3")LTTsharesnextbaratStopPricestop;end;end;end;ifmp=-1thenbeginifPosTradeEntryPrice(0,2)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,0)+PosTradeEntryPrice(0,1)+PosTradeEntryPrice(0,2))/3;StopPrice=AveragePrice-Percent*Myatr-2*(Percent/2)*Myatr;sellshort("Sell-add3")LTTsharesnextbaratStopPricestop;end;ifPosTradeEntryPrice(0,2)=0thenbeginifPosTradeEntryPrice(0,1)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,0)+PosTradeEntryPrice(0,1))/2;StopPrice=AveragePrice-Percent*Myatr-2*(Percent/2)*Myatr;sellshort("Sell-add3")LTTsharesnextbaratStopPricestop;end;ifPosTradeEntryPrice(0,1)=0thenbeginStopPrice=PosTradeEntryPrice(0,0)-Percent*Myatr-2*(Percent/2)*Myatr;sellshort("Sell-add3")LTTsharesnextbaratStopPricestop;end;end;end;end;//止損法則//計(jì)算持倉(cāng)均價(jià)ifPosTradeEntryPrice(0,3)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,3)+PosTradeEntryPrice(0,2)+PosTradeEntryPrice(0,1)+PosTradeEntryPrice(0,0))/4;endelseifPosTradeEntryPrice(0,2)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,2)+PosTradeEntryPrice(0,1)+PosTradeEntryPrice(0,0))/3;endelseifPosTradeEntryPrice(0,1)<>0thenbeginAveragePrice=(PosTradeEntryPrice(0,1)+PosTradeEntryPrice(0,0))/2;endelseifPosTradeEntryPrice(0,0)<>0thenbeginAveragePrice=PosTradeEntryPrice(0,0);end;ifcurrentcontracts=LTTthenbeginifmp=1thenbeginsell("Sell-Stop1")allsharesnextbaratAveragePrice-StopATRCnt*Myatrstop;end;ifmp=-1thenbeginbuytocover("buy-Stop1")allsharesnextbaratAveragePrice+StopATRCnt*Myatrstop;end;end;ifcurrentcontracts=2*LTTthenbeginifmp=1thenbeginsell("Sell-Stop2")allsharesnextbaratAveragePrice-StopATRCnt*Myatrstop;end;ifmp=-1thenbeginbuytocover("buy-Stop2")allsharesnextbaratAveragePrice+StopATRCnt*Myatrstop;end;end;ifcurrentcontracts=3*LTTthenbeginifmp=1thenbeginsell("Sell-Stop3")allsharesnextbaratAveragePrice-StopATRCnt*Myatrstop;end
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 古詩(shī)課題申報(bào)書(shū)
- 課題申報(bào)書(shū)作假
- 發(fā)廊眾籌合同范本
- 員工內(nèi)部借款合同范本
- 修補(bǔ)材料合同范本
- 合同范本找誰(shuí)寫(xiě)好
- 分公司保證合同范本
- 合同范例工程范例
- 住宅電梯出售合同范本
- 修建小型廠房合同范本
- 2024年普通高等學(xué)校招生全國(guó)統(tǒng)一考試(新課標(biāo)I卷)語(yǔ)文含答案
- 工程索賠報(bào)告范文
- 內(nèi)審員考試試題含答案
- 員工期權(quán)合同模板
- 八年級(jí)上學(xué)期期末復(fù)習(xí)《全等三角形》單元試卷(含部分解析) 2024-2025學(xué)年人教版數(shù)學(xué)
- 2024至2030年中國(guó)毛巾繡電腦繡花機(jī)控制系統(tǒng)行業(yè)投資前景及策略咨詢研究報(bào)告
- 2024年重慶市公務(wù)員考試《行測(cè)》真題及答案解析
- 無(wú)人機(jī)理論培訓(xùn)
- 《冠心病病人的護(hù)理》課件
- 安裝窗戶護(hù)欄安全免責(zé)協(xié)議書(shū)范文范本
- 《現(xiàn)代家政導(dǎo)論》電子教案 3.2模塊三項(xiàng)目二家庭生活質(zhì)量認(rèn)知
評(píng)論
0/150
提交評(píng)論