日內(nèi)交易策略(TBQ版)_第1頁
日內(nèi)交易策略(TBQ版)_第2頁
日內(nèi)交易策略(TBQ版)_第3頁
日內(nèi)交易策略(TBQ版)_第4頁
日內(nèi)交易策略(TBQ版)_第5頁
已閱讀5頁,還剩13頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

日內(nèi)交易策略(TBQ版)本策略是一個(gè)日內(nèi)交易策略,主要用于捕捉市場的日內(nèi)波動(dòng)機(jī)會(huì)。策略的核心思想是通過對歷史數(shù)據(jù)的分析和實(shí)時(shí)市場情況的監(jiān)測,結(jié)合多種技術(shù)指標(biāo)和交易規(guī)則,來決定是否進(jìn)行交易以及如何進(jìn)行交易。交易邏輯思路1.**市場監(jiān)測**:策略首先通過訂閱日線數(shù)據(jù),監(jiān)測市場的開盤價(jià)、收盤價(jià)、最高價(jià)和最低價(jià)等關(guān)鍵指標(biāo)。這些數(shù)據(jù)用于計(jì)算各種技術(shù)指標(biāo),如平均波動(dòng)范圍、突破百分比等。2.**交易條件判斷**:策略設(shè)置了多個(gè)條件來判斷是否應(yīng)該進(jìn)行交易。這些條件包括市場是否處于可交易時(shí)間、價(jià)格是否突破了設(shè)定的上下軌、是否有足夠的波動(dòng)空間等。3.**交易執(zhí)行**:當(dāng)滿足交易條件時(shí),策略會(huì)執(zhí)行買入或賣出操作。買入操作通常在價(jià)格突破上軌時(shí)進(jìn)行,賣出操作則在價(jià)格突破下軌時(shí)進(jìn)行。4.**止損與止盈**:策略設(shè)置了多級止損點(diǎn),以控制潛在的虧損。同時(shí),也設(shè)置了平移止損和跟蹤止損,以保護(hù)利潤并減少回撤。5.**交易限制**:策略還考慮了日內(nèi)交易的限制,確保在同一天內(nèi)不會(huì)進(jìn)行過多的交易,避免過度交易帶來的風(fēng)險(xiǎn)。6.**交易結(jié)束**:策略在日內(nèi)交易截止時(shí)間到達(dá)時(shí),無論盈虧都會(huì)清倉結(jié)束交易,以符合日內(nèi)交易的規(guī)則。策略特點(diǎn)-**靈活性**:策略可以根據(jù)不同的市場情況調(diào)整參數(shù),如等待期間、交易百分比、突破百分比等,以適應(yīng)不同的市場環(huán)境。-**風(fēng)險(xiǎn)控制**:通過設(shè)置多級止損點(diǎn)和平移止損,策略能夠有效地控制每筆交易的最大虧損。-**自動(dòng)化**:策略的自動(dòng)化程度高,可以在無人值守的情況下自動(dòng)執(zhí)行交易邏輯,減少人為干預(yù)。-**適應(yīng)性**:策略能夠適應(yīng)不同的交易品種和市場,通過調(diào)整參數(shù)可以應(yīng)用于多種交易場景。-**實(shí)時(shí)性**:策略能夠?qū)崟r(shí)監(jiān)測市場變化,快速響應(yīng)市場的波動(dòng),抓住交易機(jī)會(huì)。-**簡潔性**:盡管策略包含多個(gè)條件和規(guī)則,但其核心邏輯清晰,易于理解和維護(hù)。-**可擴(kuò)展性**:策略設(shè)計(jì)考慮了未來可能的調(diào)整和優(yōu)化,留有足夠的空間進(jìn)行功能擴(kuò)展和改進(jìn)。本日內(nèi)交易策略旨在通過精確的市場分析和嚴(yán)格的風(fēng)險(xiǎn)控制,實(shí)現(xiàn)穩(wěn)健的日內(nèi)交易收益。它結(jié)合了多種交易技巧和原則,旨在捕捉市場的日內(nèi)波動(dòng),同時(shí)嚴(yán)格控制風(fēng)險(xiǎn),確保交易的安全性和盈利性。策略代碼:ParamsNumericwait_period_mins(30);//等待期間Numericinit_trades_endtime(0.1430);//跟蹤交易時(shí)間Numericliq_rev_endtime(0.1200);//反轉(zhuǎn)截止時(shí)間Numerictrade_prcnt(0.85);//交易百分比Numericthrust_prcnt1(0.30);//突破百分比1Numericthrust_prcnt2(0.60);//突破百分比2Numericbreakout_prcnt(0.25);//日線突破百分比Numericfailed_breakout_prcnt(0.25);//失敗突破百分比Numericprot_stop_prcnt1(0.25);//保護(hù)止損百分比1Numericprot_stop_prcnt2(0.15);//保護(hù)止損百分比2(反轉(zhuǎn))Numericprot_stop_amt(3);//保護(hù)止損偏移Numericbreak_even_prcnt(0.50);//觸發(fā)平移事件百分比Numericavg_rng_length(10);//平均波動(dòng)周期Numericavg_oc_length(10);//平均開收周期Numericlots(1);//頭寸Numericday_trades_endtime(0.1450);//日內(nèi)交易截止時(shí)間VarsSeries<Numeric>averageRange;Series<Numeric>averageOCRange(0);Series<Numeric>buyBOPoint;Series<Numeric>sellBOPoint;Series<Numeric>longBreakPt(0);Series<Numeric>shortBreakPt(0);Series<Numeric>longFBOPoint(0);Series<Numeric>shortFBOPoint(0);Series<Numeric>barCounts(0);Series<Numeric>intraHigh(0);Series<Numeric>intraLow(1999999);Series<Numeric>buysToday(0);//當(dāng)日交易多單標(biāo)志Series<Numeric>sellsToday(0);//當(dāng)日交易空單單標(biāo)志Series<Numeric>currTrdType(0);Series<Numeric>longLiqPoint(0);Series<Numeric>shortLiqPoint(0);Series<Numeric>yesterdayOCRRange(0);//昨日開盤收盤真實(shí)波動(dòng)Series<Numeric>intraTradeHigh(0);Series<Numeric>intraTradeLow(1999999);Series<Bool>canTrades(False);//今日啟動(dòng)交易標(biāo)識Series<Bool>buyEasierDay(False);Series<Bool>sellEasierDay(False);NumericMinPoint;//最小變動(dòng)單位NumericmyOpen;//當(dāng)天開盤價(jià)NumericyesDayClose;//昨日收盤價(jià)NumericbefyesCloseToYes;//前日-昨日收盤價(jià)NumericlongTrack;//多單跟蹤NumericshortTrack;//空單跟蹤NumericyesHigh;//昨高NumericyesHigh_up;//昨高+NumericyesHigh_dn;//昨高-NumericyesLow;//昨低NumericyesLow_up;//昨低+NumericyesLow_dn;//昨低-Series<Numeric>myEntryPrice;//開倉價(jià)格Series<Numeric>myExitPrice;//平倉價(jià)格Series<Numeric>preMarketPos(0);//前一次持倉狀態(tài),初始0,多=1,空=-1Series<Numeric>trades_time(0.2100);//日內(nèi)交易時(shí)間Series<Numeric>pre_averageRange;Series<Bool>nightsDay(False);//夜盤Series<Bool>daysDay(False);//白盤Series<Bool>daysDayStockIndex(False);//白盤StockindexfuturesSeries<Bool>trades_time_flag(False);//是否在可交易時(shí)間Series<Bool>high_flag(False);//是否突破昨高一定幅度Series<Bool>low_flag(False);//是否突破昨低一定幅度Events//此處實(shí)現(xiàn)事件函數(shù)//初始化事件函數(shù),策略運(yùn)行期間,首先運(yùn)行且只有一次,應(yīng)用在訂閱數(shù)據(jù)等操作OnInit(){//訂閱日線數(shù)據(jù)//SubscribeBar(Data0.Symbol,"1d",Data0.BeginDateTime);}//在新bar的第一次執(zhí)行之前調(diào)用一次,參數(shù)為新bar的圖層數(shù)組OnBarOpen(ArrayRef<Integer>indexs){//averageRange取值,回溯上一天的值If(TrueDate(1)<>TrueDate(0)){pre_averageRange=averageRange[1];}}//Bar更新事件函數(shù),參數(shù)indexs表示變化的數(shù)據(jù)源圖層ID數(shù)組OnBar(ArrayRef<Integer>indexs){myOpen=OpenD(0);//今開//yesDayClose=data1.CloseD(1);//昨日收盤價(jià)yesDayClose=CloseD(1);//昨日收盤價(jià)yesHigh=HighD(1);yesHigh_up=yesHigh+averageRange*breakout_prcnt;yesHigh_dn=yesHigh-averageRange*breakout_prcnt;yesLow=LowD(1);yesLow_up=yesLow+averageRange*breakout_prcnt;yesLow_dn=yesLow-averageRange*breakout_prcnt;MinPoint=MinMove*PriceScale;//averageRange=data1.AvgTrueRange(avg_rng_length);//日線平均真實(shí)波動(dòng)averageRange=XAverage(Abs(OpenD(1)-CloseD(1)),avg_oc_length*4*12);//日線平均真實(shí)波動(dòng)//yesterdayOCRRange=Abs(data1.OpenD(1)-data1.CloseD(1));//昨波動(dòng)區(qū)間yesterdayOCRRange=Abs(OpenD(1)-CloseD(1));//昨波動(dòng)區(qū)間//averageOCRange=data1.Average(Abs(data1.OpenD(1)-data1.CloseD(1)),avg_oc_length);//日線平均波動(dòng)averageOCRange=Average(Abs(OpenD(1)-CloseD(1)),avg_oc_length*4*12);//日線平均波動(dòng)//buyEasierDay=data1.CloseD(2)<=data1.CloseD(1);//趨買日//sellEasierDay=data1.CloseD(2)>data1.CloseD(1);//趨賣日//buyEasierDay=data1.CloseD(1)<=data1.CloseD(2);//趨買日昨收小于等于昨昨收//sellEasierDay=data1.CloseD(1)>data1.CloseD(2);//趨賣日昨收大于昨昨收buyEasierDay=CloseD(2)<=CloseD(1);//趨買日sellEasierDay=CloseD(2)>CloseD(1);//趨賣日//befyesCloseToYes=data1.CloseD(2)-data1.CloseD(1);//前收盤價(jià)-昨收befyesCloseToYes=CloseD(2)-CloseD(1);//前收盤價(jià)-昨收If(TrueDate(1)<>TrueDate(0)){//判斷當(dāng)日是否可以交易canTrades=False;If(yesterdayOCRRange<trade_prcnt*averageOCRange){canTrades=True;}PlotBool("是否交易",canTrades);Commentary("yesterdayOCRRange="+Text(yesterdayOCRRange));Commentary("averageOCRange="+Text(averageOCRange));//趨買市or趨賣市If(buyEasierDay){PlotString("趨買市","趨買市",High+5*MinPoint);}If(sellEasierDay){PlotString("趨賣市","趨賣市",Low-5*MinPoint);}Commentary("前收-昨收="+Text(befyesCloseToYes));//當(dāng)日交易限制1多1空buysToday=0;sellsToday=0;//突破昨高/低標(biāo)志high_flag=False;low_flag=False;//可交易時(shí)間確定nightsDay=False;//夜盤初始化daysDay=False;//白盤初始化daysDayStockIndex=False;//白盤初始化Stockindexfuturestrades_time=0.2100;//默認(rèn)夜盤九點(diǎn)trades_time_flag=False;If(Time==0.2100){nightsDay=True;//夜盤trades_time=0.2100+wait_period_mins/10000;Commentary("夜盤開盤");}ElseIf(Time==0.0900){daysDay=True;//白盤trades_time=0.0900+wait_period_mins/10000;Commentary("白盤開盤");}ElseIf(Time==0.0930){daysDayStockIndex=True;//白盤Stockindexfuturestrades_time=0.0930+wait_period_mins/10000;Commentary("白盤開盤Stockindexfutures");}}//計(jì)算可交易時(shí)間If(nightsDay){trades_time_flag=(Time>=trades_time&&Time<=0.2400)Or(Time>=0.0000&&Time<=0.0300)Or(Time>=0.0900&&Time<day_trades_endtime);}ElseIf(daysDay){trades_time_flag=(Time>=trades_time&&Time<day_trades_endtime);}ElseIf(daysDayStockIndex){trades_time_flag=(Time>=trades_time&&Time<day_trades_endtime);}//常規(guī)突破上下軌計(jì)算If(buyEasierDay){buyBOPoint=myOpen+thrust_prcnt1*pre_averageRange;sellBOPoint=myOpen-thrust_prcnt2*pre_averageRange;}ElseIf(sellEasierDay){sellBOPoint=myOpen-thrust_prcnt1*pre_averageRange;buyBOPoint=myOpen+thrust_prcnt2*pre_averageRange;}//設(shè)定畫線類型,如:Enum_Dot,Enum_Line,Enum_Bar,Enum_Cross,默認(rèn)為屬性框中設(shè)定//設(shè)定畫線風(fēng)格,如:Enum_Solid,Enum_Dash,Enum_Broken,Enum_Dash_Dot,默認(rèn)為屬性框中設(shè)定//設(shè)定畫線線寬,如:Enum_1Pix,Enum_2Pix,Enum_3Pix,Enum_4Pix,Enum_5Pix,Enum_6Pix,Enum_7Pix,默認(rèn)為屬性框中設(shè)定PlotAuto("myOpen",myOpen,0,White,Enum_Line,Enum_Dash,Enum_1Pix);PlotNumeric("buyBOPoint",buyBOPoint,0,Green);PlotNumeric("sellBOPoint",sellBOPoint,0,Red);//Commentary("myOpen="+Text(myOpen));//Commentary("Time="+Text(Time));//Commentary("trades_time="+Text(trades_time));//Commentary("buyBOPoint="+Text(buyBOPoint));//Commentary("sellBOPoint="+Text(sellBOPoint));//Commentary("averageRange="+Text(averageRange));//Commentary("pre_averageRange="+Text(pre_averageRange));//如果當(dāng)日可以交易If(canTrades){If(MarketPosition<>1&&High>=buyBOPoint&&trades_time_flag&&buysToday==0){myEntryPrice=Max(Open,buyBOPoint);Buy(lots,myEntryPrice);buysToday=1;//當(dāng)日交易限制1多1空Commentary("突破買開buyBOPoint");}If(MarketPosition<>-1&&Low<=sellBOPoint&&trades_time_flag&&sellsToday==0){myEntryPrice=Min(Open,sellBOPoint);SellShort(lots,myEntryPrice);sellsToday=1;//當(dāng)日交易限制1多1空Commentary("*突破賣開sellBOPoint*");}}Else{Return;}//高低點(diǎn)計(jì)算If(MarketPosition==0){intraTradeHigh=0;intraTradeLow=1999999;}ElseIf(MarketPosition==1){intraTradeHigh=Max(intraTradeHigh,High);}ElseIf(MarketPosition==-1){intraTradeLow=Min(intraTradeLow,Low);}Commentary("intraTradeHigh="+Text(intraTradeHigh));Commentary("intraTradeLow="+Text(intraTradeLow));//突破昨高標(biāo)志If(High>yesHigh_up&&!high_flag){high_flag=True;PlotString("high_flag","突破昨高標(biāo)志",High+MinPoint*25);Commentary("前高="+Text(yesHigh));Commentary("前高標(biāo)志+"+Text(yesHigh_up));Commentary("前高失敗位置-"+Text(yesHigh_dn));}//突破昨高標(biāo)志If(Low<yesLow_dn&&!low_flag){low_flag=True;PlotString("low_flag","*突破昨低標(biāo)志*",Low-MinPoint*25);Commentary("*前低="+Text(yesLow));Commentary("*前低標(biāo)志+"+Text(yesLow_dn));Commentary("*前低失敗位置-"+Text(yesLow_up));}//多單處理初始止損1If(MarketPosition==1&&sellsToday==0&&BarsSinceEntry>0){longLiqPoint=myEntryPrice-prot_stop_prcnt1*pre_averageRange;longLiqPoint=Min(longLiqPoint,myEntryPrice-prot_stop_amt*MinPoint);Commentary("longLiqPoint="+Text(longLiqPoint));//貼近真實(shí)交易If(longLiqPoint>=yesHigh_dn){//[1]保護(hù)止損If(Low<=longLiqPoint){myExitPrice=Min(Open,longLiqPoint);If(BarsSinceEntry>4&&Time<=liq_rev_endtime){myEntryPrice=longLiqPoint;myEntryPrice=Min(Open,myEntryPrice);SellShort(lots,myEntryPrice);sellsToday=1;PlotString("liq_rev","---觸發(fā)反轉(zhuǎn)信號---",High+MinPoint*35);Commentary("*失敗突破反轉(zhuǎn)賣開liq_rev-1*");Return;}Sell(0,myExitPrice);Commentary("[1]保護(hù)止損Sell");Return;}//回落昨高標(biāo)志If(high_flag&&low<=yesHigh_dn){myEntryPrice=yesHigh_dn;myEntryPrice=Min(Open,myEntryPrice);SellShort(lots,myEntryPrice);sellsToday=1;//當(dāng)日交易限制1多1空Commentary("*失敗突破反轉(zhuǎn)賣開sellBOPoint*");PlotString("high_flag","突破昨高后又回落~",High+MinPoint*25);Commentary("前高失敗位置-"+Text(yesHigh_dn));}}Else{//回落昨高標(biāo)志If(high_flag&&low<=yesHigh_dn){myEntryPrice=yesHigh_dn;myEntryPrice=Min(Open,myEntryPrice);SellShort(lots,myEntryPrice);sellsToday=1;//當(dāng)日交易限制1多1空Commentary("*失敗突破反轉(zhuǎn)賣開sellBOPoint*");PlotString("high_flag","突破昨高后又回落~",High+MinPoint*25);Commentary("前高失敗位置-"+Text(yesHigh_dn));Return;}//[1]保護(hù)止損If(Low<=longLiqPoint){myExitPrice=Min(Open,longLiqPoint);If(BarsSinceEntry>4&&Time<=liq_rev_endtime){myEntryPrice=longLiqPoint;myEntryPrice=Min(Open,myEntryPrice);SellShort(lots,myEntryPrice);sellsToday=1;PlotString("liq_rev","---觸發(fā)反轉(zhuǎn)信號---",High+MinPoint*35);Commentary("*失敗突破反轉(zhuǎn)賣開liq_rev-2*");Return;}Sell(0,myExitPrice);Commentary("[1]保護(hù)止損Sell");}}}//空單處理初始止損1If(MarketPosition==-1&&buysToday==0&&BarsSinceEntry>0){shortLiqPoint=myEntryPrice+prot_stop_prcnt1*pre_averageRange;shortLiqPoint=Max(shortLiqPoint,myEntryPrice+prot_stop_amt*MinPoint);Commentary("shortLiqPoint="+Text(shortLiqPoint));If(shortLiqPoint<=yesLow_up){//[1]保護(hù)止損BuyToCoverIf(High>=shortLiqPoint){myExitPrice=Max(Open,shortLiqPoint);If(BarsSinceEntry>4&&Time<=liq_rev_endtime){myEntryPrice=shortLiqPoint;myEntryPrice=Max(Open,myEntryPrice);Buy(lots,myEntryPrice);buysToday=1;PlotString("liq_rev","===觸發(fā)反轉(zhuǎn)信號===",Low-MinPoint*35);Commentary("失敗突破反轉(zhuǎn)買開liq_rev-1");Return;}BuyToCover(0,myExitPrice);Commentary("[1]保護(hù)止損BuyToCover:"+Text(shortLiqPoint));Return;}//回落昨低標(biāo)志If(low_flag&&High>=yesLow_up){myEntryPrice=yesLow_up;myEntryPrice=Max(Open,myEntryPrice);Buy(lots,myEntryPrice);buysToday=1;Commentary("失敗突破反轉(zhuǎn)買開buy");PlotString("low_flag","*突破昨低后又沖高~",Low-MinPoint*20);Commentary("前低失敗位置-"+Text(yesLow_up));Return;}}Else{//回落昨低標(biāo)志If(low_flag&&High>=yesLow_up){myEntryPrice=yesLow_up;myEntryPrice=Max(Open,myEntryPrice);Buy(lots,myEntryPrice);buysToday=1;Commentary("失敗突破反轉(zhuǎn)買開buy");PlotString("low_flag","*突破昨低后又沖高~",Low-MinPoint*20);Commentary("前低失敗位置-"+Text(yesLow_up));Return;}//[1]保護(hù)止損BuyToCoverIf(High>=shortLiqPoint){myExitPrice=Max(Open,shortLiqPoint);If(BarsSinceEntry>4&&Time<=liq_rev_endtime){myEntryPrice=shortLiqPoint;myEntryPrice=Max(Open,myEntryPrice);Buy(lots,myEntryPrice);buysToday=1;PlotString("liq_rev","===觸發(fā)反轉(zhuǎn)信號===",Low-MinPoint*35);Commentary("失敗突破反轉(zhuǎn)買開liq_rev-2");Return;}BuyToCover(0,myExitPrice);Commentary("[1]保護(hù)止損BuyToCover:"+Text(shortLiqPoint));Return;}}}//多單處理初始止損2If(MarketPosition==1&&sellsToday==1){longLiqPoint=myEntryPrice-prot_stop_prcnt2*pre_averageRange;longLiqPoint=Min(longLiqPoint,myEntryPrice-prot_stop_amt*MinPoint);If(Low<=longLiqPoint&&BarsSinceEntry>0){myExitPrice=Min(Open,longLiqPoint);Sell(0,myExitPrice);Commentary("[1]保護(hù)止損2Sell");}}//空單處理初始止損2If(MarketPosition==-1&&buysToday==1){shortLiqPoint=myEntryPrice+prot_stop_prcnt2*pre_averageRange;shortLiqPoint=Max(shortLiqPoint,myEntryPrice+prot_stop_amt*MinPoint);If(High>=shortLiqPoint&&BarsSinceEntry>0){myExitPrice=Max(Open,shortLiqPoint);BuyToCover(0,myExitPrice);Commentary("[1]保護(hù)止損2BuyToCover");}}//多單處理平移止損If(MarketPosition==1){If(intraTradeHigh>=myEntryPrice+break_even_prcnt*pre_averageRange){longLiqPoint=myEntryPrice+MinPoint*1;If(High>=intraTradeHigh){PlotString("觸發(fā)平移條件or創(chuàng)新高","@",High+MinPoint*5);}}If(Low<=longLiqPoint&&BarsSinceEntry>0){myExitPrice=Min(Open,longLiq

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論