我问一下,程序话交易买完一次没平仓又买了一次是为什么呢
//------------------------------------------------------------------------// 简称: dy_zs// 名称: 豆油带止损// 类别: 公式应用// 类型: 用户应用// 输出: Void//------------------------------------------------------------------------Params Integer shou(1);//交易手数 Numeric offset5(40);//五分钟的偏离率,买入或者卖出开仓时候离40分钟线的位置 Numeric offset6(60);//五分钟的偏离率,买入或者卖出开仓时候离40分钟线的位置 //Numeric onset(100);//5分钟和十五分钟绿线差值 Numeric reset(30);//连续出现3根阴线或者阳性多少距离不开仓 //均线 5 10 20 40 Numeric length5(5); Numeric length10(10); Numeric length20(20); Numeric length40(40); //macd Numeric FastLength(12); Numeric SlowLength(26); Numeric MACDLength(9);Vars Numeric distinctk; Numeric distincts; //开平仓时间条件 Bool pdkcsk; Bool pdpcsp; //均线 5 10 20 40 Series<Numeric> a;//5日均线 Series<Numeric> b;//10日均线 Series<Numeric> d;//20日均线 Series<Numeric> e; //40日均线 Series<Numeric> bkcjg;//买开仓价格 Series<Numeric> skcjg;//卖开仓价格 Array<Bool> pdbuyk1;//各种买入信号 Bool pdbuyk;//发出买入信号 Array<Bool> pdbuyp1;//各种卖出平仓信号 Bool pdbuyp;//发出卖出平仓信号 Array<Bool> pdsellk1;//各种卖出开仓信号 Bool pdsellk;//发出卖出开仓信号 Array<Bool> pdsellp1;//各种买入平仓信号 Bool pdsellp;//发出买入平仓信号 //MACDLength Numeric MACDDiff; //20日周期macd Numeric AvgMACD;//20日周期macd Numeric MACDValue;//20日周期macd Numeric MACDDiff5;//5日周期macd Numeric AvgMACD5;//5日周期macd Numeric MACDValue5;//5日周期macd //交易 Global String Accountid; Global CodeProperty heyue; //获取当前合约 Global String hy;//获取当前合约 Global Numeric zj; Numeric Value;//浮动盈亏 Position p;Defs //此处添加公式函数 Events //此处实现事件函数 //初始化事件函数,策略运行期间,首先运行且只有一次 OnInit() { SetConsecEntries(0);//设置连续开仓次数 } OnReady() { //获取当前合约 GetProperty(heyue); hy=heyue.symbol; Accountid=A_AccountID; } //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组 OnBar(ArrayRef<Integer> indexs) { pdkcsk= (0.0900 < time and time< 0.1445) or (0.2100 <= time and time< 0.2245);//开仓时间小于预设时间 if((time==0.1450) or (time==0.2250) or (time==0.0900) or (time==0.2100)){ //If(MarketPosition==1){ Sell(Open); //卖出平仓 //PlotString(\"shell\",\"sp\"+Text(Close),High+10); Commentary(\"当前价格平仓收盘前\"); //} //If(MarketPosition==-1){ BuyToCover(Open);//买入平仓 //PlotString(\"shell\",\"mp\"+Text(Close),low-10); Commentary(\"当前价格平仓收盘前\"); //} } //划线 Range[0:datasourcesize()-1] { a=AverageFC(Open,length5);//5日均线 b=AverageFC(Open,length10);//10日均线 d=AverageFC(Open,length20);//20日均线 e=AverageFC(Open,length40);//40日均线 PlotNumeric(\"MA5\",a); PlotNumeric(\"MA15\",b); PlotNumeric(\"MA20\",d); PlotNumeric(\"MA40\",e); Commentary(\"当前时间\"+Accountid); //MACD MACDDiff = XAverage( data2.Close, FastLength ) - XAverage( data2.Close, SlowLength ) ; //20日周期macd AvgMACD = XAverage(MACDDiff,MACDLength); //20日周期macd MACDValue = MACDDiff - AvgMACD; //20日周期macd MACDDiff5=XAverage( Close, FastLength ) - XAverage( Close, SlowLength ) ;//5日周期macd AvgMACD5 = XAverage(MACDDiff5,MACDLength); //5日周期macd MACDValue5 = MACDDiff5 - AvgMACD5; //5日周期macd //PlotNumeric(\"MACDDiff\",MACDDiff); //PlotNumeric(\"MACDDEA\",AvgMACD); //If (MACDValue >= 0) // PlotAuto(\"MACD\",MACDValue,0,Red,Enum_Bar); //Else // PlotAuto(\"MACD\",MACDValue,0,Green,Enum_Bar); //PlotNumeric(\"零线\",0); } ////////////////////////////////////////////////////////// //买入开仓开始 pdbuyk1[1]=(e<d) and (d<b) and (b<a) and (High>a) ;//5分钟周期买入开仓信号1 pdbuyk1[2]=(data1.e<data1.d) and (data1.d<data1.b) and (data1.b<data1.a) ;//15分钟周期买入开仓信号2 pdbuyk1[3]=MACDDiff-AvgMACD>0;//60分钟周期买入开仓信号macd3 //pdbuyk1[4]=abs(Data0.e-data1.e)<onset;//5分钟周期15分钟周期绿线相近 //pdbuyk1[5]= (data[2].MACDDiff>0) and (data[2].AvgMACD>0); pdbuyk1[5]= Not(((close[2]-Open[2])>0) and (close[1]-Open[1]>0) and (((close[2]-Open[2])+(close[1]-Open[1]))>reset)); //pdbuyk1[6]=Not(((close[2]-open[2])<0) and ((close[1]-Open[1])<0) and (Abs(close[2]-open[2])>=8) and (Abs(close[1]-Open[1])>=8)); pdbuyk=pdbuyk1[1] and pdbuyk1[2] and pdbuyk1[3] and pdbuyk1[5] /*and pdbuyk1[6]*/ and pdkcsk;//买入开仓条件 if(pdbuyk) { If(((CurrentEntries<1))){ Buy(shou,Open);//买入开仓 bkcjg=EntryPrice(); distinctk=bkcjg-e; PlotString(\"buy\",\"bk\"+text(bkcjg),low-10); Commentary(\"当前价格买入开仓合约为:\"+hy); Commentary(\"当前价格买入开仓合约为:\"+hy); Commentary(\"当前价格买入开仓合约为:\"+Text(close[2]-open[2])); } //PlotBool(\"buy\",True); } //买入开仓结束 //卖出平多仓止损或者止盈 if((MarketPosition==1) and (Low<e)){ Sell(shou,Open); //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); commentary(\"当前价格平仓\"); } if(bkcjg>Low) //盈利之后的策略 { if(distinctk>offset5 and distinctk<offset6 ) //如果是买入价格在offset5或者offset6之间在10日均线止盈 { if((MarketPosition==1) and (Low<b)){ Sell(shou,Open); //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); commentary(\"当前价格平仓\"); } } //结束 Else If(distinctk>offset6) //如果是买入价格在offset6之上,回撤两根均线止盈 { if((MarketPosition==1) and ((Low<low[2]) or (low<low[1])) /*and ((close[1]-Open[1])<0) and ((close[2]-Open[2])<0)*/ ){ Sell(shou,Open); //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); commentary(\"当前价格平仓\"); } } //结束 Else{ pdbuyp1[1]=Low<e; //5分钟发出卖出平仓信号 pdbuyp=pdbuyp1[1];//卖出平仓条件 If(pdbuyp){ If(MarketPosition==1) { Sell(shou,Open); //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); Commentary(\"当前价格平仓\"); } } //卖出平仓结束 } } if(bkcjg<High) //多头止损策略 { if(distinctk>offset5) //如果是买入价格在offset5之上,十日线止损 { if((MarketPosition==1) and (Low<b)){ Sell(shou,Open); //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); commentary(\"当前价格平仓\"); } } //结束 Else{ if((MACDValue5<0) and (MarketPosition==1)){ Sell(shou,Open); //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); commentary(\"当前价格平仓\"); } } } //卖出平多仓止盈止损结束 //卖出开仓开始 pdsellk1[1]=(e>d) and (d>b) and (b>a) and (Low<a);//5分钟周期卖出开仓信号1 pdsellk1[2]=(data1.e>data1.d) and (data1.d>data1.b) and (data1.b>data1.a);//15分钟周期卖出开仓信号2 pdsellk1[3]=(MACDDiff-AvgMACD<0);//60分钟周期卖出开仓信号3 //pdsellk1[4]=abs(Data0.e-data1.e)<onset;//5分钟周期15分钟周期绿线相近 //pdbuyk1[5]= (data[2].MACDDiff<0) and (data[2].AvgMACD<0); pdsellk1[5]=Not((Close[2]-open[2]<0) and (Close[1]-open[1]<0) and (Abs((Close[2]-open[2])+(Close[1]-open[1]))>reset)); //pdsellk1[6]=Not((close[2]-open[1])>0 and (close[1]-open[1])>0 and (Abs(close[2]-open[2])>=8) and (Abs(close[1]-Open[1])>=8)); pdsellk=pdsellk1[1] and pdsellk1[2] and pdsellk1[3] and pdsellk1[5] /*and pdsellk1[6]*/ and pdkcsk;//卖出开仓条件 if(pdsellk) { If((CurrentEntries<1)){ SellShort(shou,Open);//卖出开仓 skcjg=EntryPrice(); distincts=skcjg-e; PlotString(\"buy\",\"sk\"+Text(skcjg),high+10); Commentary(\"当前价格卖出开仓合约为\"+hy); } //PlotBool(\"buy\",True); } //卖出开仓结束 //买入平空仓止损或者止盈开始 if((MarketPosition==-1) and (High>e)){ BuyToCover(shou,Open);//买入平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); Commentary(\"当前价格平仓\"); } if(Low<skcjg) //盈利之后的策略 { if((distincts>offset5) and (distincts<offset6)) { if(MarketPosition==-1 and High>b){ BuyToCover(shou,Open);//买入平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); Commentary(\"当前价格平仓\"); } Else If(Abs(distincts)>offset6){ if(((Low>low[2]) or (Low>Low[1])) /*and ((close[1]-Open[1])>0) and ((close[2]-Open[2])>0)*/ and MarketPosition==-1){ BuyToCover(shou,Open);//买入平仓 //卖出平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); commentary(\"当前价格平仓\"); } } Else{ //卖出平仓开始 pdsellp1[1]=High>e;//5分钟发出买入平仓信号 pdsellp=pdsellp1[1];//买入平仓条件 If(pdsellp){ If(MarketPosition==-1){ BuyToCover(shou,Open);//买入平仓 PlotString(\"shell\",\"mp\"+Text(Open),low-10); Commentary(\"当前价格平仓\"); } } } } } if(close>skcjg) //止损 { if(distincts>offset5) { if((MarketPosition==-1) and (High>b)){ BuyToCover(shou,Open);//买入平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); Commentary(\"当前价格平仓\"); } } Else{ if((MACDValue5>0) and (MarketPosition==-1)){ BuyToCover(shou,Open);//买入平仓 PlotString(\"shell\",\"sp\"+Text(Open),High+10); Commentary(\"当前价格平仓\"); } } } //买入平空仓结束 }/*但是我的条件是有仓位的时候不开仓呀,这块就算平仓不生效也不应该开仓呀我 12:53:56您看看我的代码我 12:54:17这块应该是保持开仓一次,而且不连续开仓呀我 12:55:14信号闪烁的问题昨天我解决了一些,比如用open画的均线系统,这块应该不会信号闪烁了我 12:56:01close一般都改成了小于low和大于high,也应该屏蔽了*///------------------------------------------------------------------------// 编译版本 2023/10/02 112948// 版权所有 kaituozhe8888// 更改声明 TradeBlazer Software保留对TradeBlazer平台// 每一版本的TradeBlazer公式修改和重写的权利//------------------------------------------------------------------------