日内交易策略(TBQ版)_第1页
日内交易策略(TBQ版)_第2页
日内交易策略(TBQ版)_第3页
日内交易策略(TBQ版)_第4页
日内交易策略(TBQ版)_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

日内交易策略(TBQ版)本策略是一个日内交易策略,主要用于捕捉市场的日内波动机会。策略的核心思想是通过对历史数据的分析和实时市场情况的监测,结合多种技术指标和交易规则,来决定是否进行交易以及如何进行交易。交易逻辑思路1.**市场监测**:策略首先通过订阅日线数据,监测市场的开盘价、收盘价、最高价和最低价等关键指标。这些数据用于计算各种技术指标,如平均波动范围、突破百分比等。2.**交易条件判断**:策略设置了多个条件来判断是否应该进行交易。这些条件包括市场是否处于可交易时间、价格是否突破了设定的上下轨、是否有足够的波动空间等。3.**交易执行**:当满足交易条件时,策略会执行买入或卖出操作。买入操作通常在价格突破上轨时进行,卖出操作则在价格突破下轨时进行。4.**止损与止盈**:策略设置了多级止损点,以控制潜在的亏损。同时,也设置了平移止损和跟踪止损,以保护利润并减少回撤。5.**交易限制**:策略还考虑了日内交易的限制,确保在同一天内不会进行过多的交易,避免过度交易带来的风险。6.**交易结束**:策略在日内交易截止时间到达时,无论盈亏都会清仓结束交易,以符合日内交易的规则。策略特点-**灵活性**:策略可以根据不同的市场情况调整参数,如等待期间、交易百分比、突破百分比等,以适应不同的市场环境。-**风险控制**:通过设置多级止损点和平移止损,策略能够有效地控制每笔交易的最大亏损。-**自动化**:策略的自动化程度高,可以在无人值守的情况下自动执行交易逻辑,减少人为干预。-**适应性**:策略能够适应不同的交易品种和市场,通过调整参数可以应用于多种交易场景。-**实时性**:策略能够实时监测市场变化,快速响应市场的波动,抓住交易机会。-**简洁性**:尽管策略包含多个条件和规则,但其核心逻辑清晰,易于理解和维护。-**可扩展性**:策略设计考虑了未来可能的调整和优化,留有足够的空间进行功能扩展和改进。本日内交易策略旨在通过精确的市场分析和严格的风险控制,实现稳健的日内交易收益。它结合了多种交易技巧和原则,旨在捕捉市场的日内波动,同时严格控制风险,确保交易的安全性和盈利性。策略代码:ParamsNumericwait_period_mins(30);//等待期间Numericinit_trades_endtime(0.1430);//跟踪交易时间Numericliq_rev_endtime(0.1200);//反转截止时间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);//保护止损百分比1Numericprot_stop_prcnt2(0.15);//保护止损百分比2(反转)Numericprot_stop_amt(3);//保护止损偏移Numericbreak_even_prcnt(0.50);//触发平移事件百分比Numericavg_rng_length(10);//平均波动周期Numericavg_oc_length(10);//平均开收周期Numericlots(1);//头寸Numericday_trades_endtime(0.1450);//日内交易截止时间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);//当日交易多单标志Series<Numeric>sellsToday(0);//当日交易空单单标志Series<Numeric>currTrdType(0);Series<Numeric>longLiqPoint(0);Series<Numeric>shortLiqPoint(0);Series<Numeric>yesterdayOCRRange(0);//昨日开盘收盘真实波动Series<Numeric>intraTradeHigh(0);Series<Numeric>intraTradeLow(1999999);Series<Bool>canTrades(False);//今日启动交易标识Series<Bool>buyEasierDay(False);Series<Bool>sellEasierDay(False);NumericMinPoint;//最小变动单位NumericmyOpen;//当天开盘价NumericyesDayClose;//昨日收盘价NumericbefyesCloseToYes;//前日-昨日收盘价NumericlongTrack;//多单跟踪NumericshortTrack;//空单跟踪NumericyesHigh;//昨高NumericyesHigh_up;//昨高+NumericyesHigh_dn;//昨高-NumericyesLow;//昨低NumericyesLow_up;//昨低+NumericyesLow_dn;//昨低-Series<Numeric>myEntryPrice;//开仓价格Series<Numeric>myExitPrice;//平仓价格Series<Numeric>preMarketPos(0);//前一次持仓状态,初始0,多=1,空=-1Series<Numeric>trades_time(0.2100);//日内交易时间Series<Numeric>pre_averageRange;Series<Bool>nightsDay(False);//夜盘Series<Bool>daysDay(False);//白盘Series<Bool>daysDayStockIndex(False);//白盘StockindexfuturesSeries<Bool>trades_time_flag(False);//是否在可交易时间Series<Bool>high_flag(False);//是否突破昨高一定幅度Series<Bool>low_flag(False);//是否突破昨低一定幅度Events//此处实现事件函数//初始化事件函数,策略运行期间,首先运行且只有一次,应用在订阅数据等操作OnInit(){//订阅日线数据//SubscribeBar(Data0.Symbol,"1d",Data0.BeginDateTime);}//在新bar的第一次执行之前调用一次,参数为新bar的图层数组OnBarOpen(ArrayRef<Integer>indexs){//averageRange取值,回溯上一天的值If(TrueDate(1)<>TrueDate(0)){pre_averageRange=averageRange[1];}}//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组OnBar(ArrayRef<Integer>indexs){myOpen=OpenD(0);//今开//yesDayClose=data1.CloseD(1);//昨日收盘价yesDayClose=CloseD(1);//昨日收盘价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);//日线平均真实波动averageRange=XAverage(Abs(OpenD(1)-CloseD(1)),avg_oc_length*4*12);//日线平均真实波动//yesterdayOCRRange=Abs(data1.OpenD(1)-data1.CloseD(1));//昨波动区间yesterdayOCRRange=Abs(OpenD(1)-CloseD(1));//昨波动区间//averageOCRange=data1.Average(Abs(data1.OpenD(1)-data1.CloseD(1)),avg_oc_length);//日线平均波动averageOCRange=Average(Abs(OpenD(1)-CloseD(1)),avg_oc_length*4*12);//日线平均波动//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);//前收盘价-昨收befyesCloseToYes=CloseD(2)-CloseD(1);//前收盘价-昨收If(TrueDate(1)<>TrueDate(0)){//判断当日是否可以交易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));//当日交易限制1多1空buysToday=0;sellsToday=0;//突破昨高/低标志high_flag=False;low_flag=False;//可交易时间确定nightsDay=False;//夜盘初始化daysDay=False;//白盘初始化daysDayStockIndex=False;//白盘初始化Stockindexfuturestrades_time=0.2100;//默认夜盘九点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");}}//计算可交易时间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);}//常规突破上下轨计算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;}//设定画线类型,如:Enum_Dot,Enum_Line,Enum_Bar,Enum_Cross,默认为属性框中设定//设定画线风格,如:Enum_Solid,Enum_Dash,Enum_Broken,Enum_Dash_Dot,默认为属性框中设定//设定画线线宽,如:Enum_1Pix,Enum_2Pix,Enum_3Pix,Enum_4Pix,Enum_5Pix,Enum_6Pix,Enum_7Pix,默认为属性框中设定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));//如果当日可以交易If(canTrades){If(MarketPosition<>1&&High>=buyBOPoint&&trades_time_flag&&buysToday==0){myEntryPrice=Max(Open,buyBOPoint);Buy(lots,myEntryPrice);buysToday=1;//当日交易限制1多1空Commentary("突破买开buyBOPoint");}If(MarketPosition<>-1&&Low<=sellBOPoint&&trades_time_flag&&sellsToday==0){myEntryPrice=Min(Open,sellBOPoint);SellShort(lots,myEntryPrice);sellsToday=1;//当日交易限制1多1空Commentary("*突破卖开sellBOPoint*");}}Else{Return;}//高低点计算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));//突破昨高标志If(High>yesHigh_up&&!high_flag){high_flag=True;PlotString("high_flag","突破昨高标志",High+MinPoint*25);Commentary("前高="+Text(yesHigh));Commentary("前高标志+"+Text(yesHigh_up));Commentary("前高失败位置-"+Text(yesHigh_dn));}//突破昨高标志If(Low<yesLow_dn&&!low_flag){low_flag=True;PlotString("low_flag","*突破昨低标志*",Low-MinPoint*25);Commentary("*前低="+Text(yesLow));Commentary("*前低标志+"+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));//贴近真实交易If(longLiqPoint>=yesHigh_dn){//[1]保护止损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","---触发反转信号---",High+MinPoint*35);Commentary("*失败突破反转卖开liq_rev-1*");Return;}Sell(0,myExitPrice);Commentary("[1]保护止损Sell");Return;}//回落昨高标志If(high_flag&&low<=yesHigh_dn){myEntryPrice=yesHigh_dn;myEntryPrice=Min(Open,myEntryPrice);SellShort(lots,myEntryPrice);sellsToday=1;//当日交易限制1多1空Commentary("*失败突破反转卖开sellBOPoint*");PlotString("high_flag","突破昨高后又回落~",High+MinPoint*25);Commentary("前高失败位置-"+Text(yesHigh_dn));}}Else{//回落昨高标志If(high_flag&&low<=yesHigh_dn){myEntryPrice=yesHigh_dn;myEntryPrice=Min(Open,myEntryPrice);SellShort(lots,myEntryPrice);sellsToday=1;//当日交易限制1多1空Commentary("*失败突破反转卖开sellBOPoint*");PlotString("high_flag","突破昨高后又回落~",High+MinPoint*25);Commentary("前高失败位置-"+Text(yesHigh_dn));Return;}//[1]保护止损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","---触发反转信号---",High+MinPoint*35);Commentary("*失败突破反转卖开liq_rev-2*");Return;}Sell(0,myExitPrice);Commentary("[1]保护止损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]保护止损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","===触发反转信号===",Low-MinPoint*35);Commentary("失败突破反转买开liq_rev-1");Return;}BuyToCover(0,myExitPrice);Commentary("[1]保护止损BuyToCover:"+Text(shortLiqPoint));Return;}//回落昨低标志If(low_flag&&High>=yesLow_up){myEntryPrice=yesLow_up;myEntryPrice=Max(Open,myEntryPrice);Buy(lots,myEntryPrice);buysToday=1;Commentary("失败突破反转买开buy");PlotString("low_flag","*突破昨低后又冲高~",Low-MinPoint*20);Commentary("前低失败位置-"+Text(yesLow_up));Return;}}Else{//回落昨低标志If(low_flag&&High>=yesLow_up){myEntryPrice=yesLow_up;myEntryPrice=Max(Open,myEntryPrice);Buy(lots,myEntryPrice);buysToday=1;Commentary("失败突破反转买开buy");PlotString("low_flag","*突破昨低后又冲高~",Low-MinPoint*20);Commentary("前低失败位置-"+Text(yesLow_up));Return;}//[1]保护止损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","===触发反转信号===",Low-MinPoint*35);Commentary("失败突破反转买开liq_rev-2");Return;}BuyToCover(0,myExitPrice);Commentary("[1]保护止损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]保护止损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]保护止损2BuyToCover");}}//多单处理平移止损If(MarketPosition==1){If(intraTradeHigh>=myEntryPrice+break_even_prcnt*pre_averageRange){longLiqPoint=myEntryPrice+MinPoint*1;If(High>=intraTradeHigh){PlotString("触发平移条件or创新高","@",High+MinPoint*5);}}If(Low<=longLiqPoint&&BarsSinceEntry>0){myExitPrice=Min(Open,longLiq

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论