dm:=4-INTPART(LOG(C));
INPUT:SS(1,1,10000,1),X(1,1,100,1),NMIN(10,1,100,1);
//用全局变量做这种控制次数的操作。然后给所有开仓额外加一个时间条件即可。
VARIABLE:ct1:=0,ct2:=0;//2个全局变量一个控制开仓次数,一个控制平仓次数。
if TODAYBAR=1 then //每日第一个K重置全局变量。
begin
ct1:=0;
ct2:=0;
end
timecd:time<=142000;//时间限制的判断。大于2点不再开仓。
//引入
dm:=4-INTPART(LOG(C));
INPUT:SS(1,1,10000,1),X(1,1,100,1),NMIN(10,1,100,1);
//中间变量
n1:=barslast(DATE<>REF(DATE,1))+1;
JJX:xxxxxxxxxx;//日内均价线
//red:xxxxxxx;
ZS:/xxxxxxxx;//昨收
GD:=xxxxxxxx;//X是参数,自行调整
DD:=xxxxxxxxx;//5k低点
EMA11:xxxxx;
EMA13:xxxxxx;
//通道
大通xx:xxxxx;//X是参数,自行调整
大通xx:JJX*0.995;
//收盘前平仓
T1:=TIME>OPENTIME(1) AND TIME<CLOSETIME(0)-NMIN*100;
T2:=TIME>=CLOSETIME(0)-NMIN*100;
手数:=SS;
//交易条件
KD:=xxxxxxx and holding<=0; //开多条件
PD:=xxxxx ; //x ; //平多条件
KK:=xxxxxx AND holding>=0 ; //开空条件
PK:=xxxxxx; //平空条件
PK:=xxxxxx;//平空条件
if kd and ct1<=1 and timecd and holding=0 then //开多
begin
buy(holding=0,1,market);
ct1:=ct1+1;
end
if PD and ct2<=1 and holding>0 then //平多
begin
sell(holding>0,holding,market);
ct2:=ct2+1;
end
if kk and ct1<=1 and timecd and holding=0 then //开空
begin
buyshort(holding=0,1,market);
ct1:=ct1+1;
end
if pk and ct2<=1 and holding<0 then //平空
begin
sellshort(holding<0,holding,market);
ct2:=ct2+1;
end
平空:SELLSHORT(PK,1,THISCLOSE); //平空信号
开多:BUY(KD AND HOLDING=0,1,THISCLOSE) and TOTALDAYTRADE<2; //开多信号
平多:SELL(PD,1,THISCLOSE); //平多信号
开空:BUYSHORT(KK AND HOLDING=0,1,THISCLOSE)and TOTALDAYTRADE<2 ; //开空信号
收盘平多:SELL(T2 AND HOLDING>0,0,MARKET) ;
收盘平空:SELLSHORT(T2 AND HOLDING<0,0,MARKET) ;
持仓:holding,linethick0;
资产:=asset,noaxis;
可用现金:cash(0),linethick0;
我改成if格式后,测试完,开平仓没有变化呢》、,哪里的错误呢?
谢谢
INPUT:SS(1,1,10000,1),X(1,1,100,1),NMIN(10,1,100,1);
VARIABLE:ct1:=0,ct2:=0;//2个全局变量一个控制开仓次数,一个控制平仓次数。
if TODAYBAR=1 then //每日第一个K重置全局变量。
begin
ct1:=0;
ct2:=0;
end
timecd:time<=180000;//时间限制的判断。大于2点不再开仓。
//收盘前平仓
T1:=TIME>OPENTIME(1) AND TIME<CLOSETIME(0)-NMIN*100;
T2:=TIME>=CLOSETIME(0)-NMIN*100;
手数:=SS;
input:n(9,1,100,10),p1(3,2,40,4),p2(3,2,40,4);//参数设置
RSV:=(CLOSE-LLV(LOW,N))/(HHV(HIGH,N)-LLV(LOW,N))*100;
K:=SMA(RSV,P1,1);
D:=SMA(K,P2,1);
J:=3*K-2*D,NODRAW;
//开平条件1
kdjjc:cross(k,d) and T1 and holding<=0 ,NODRAW;//kdj金叉
kdjsc:cross(d,k) AND T1 AND holding>=0 ,NODRAW;
input:p(26,20,100,8),s(12,5,40,4),m(9,2,60,6);
DIFF :=EMA(CLOSE,S) - EMA(CLOSE,P);
DEA :=EMA(DIFF,M);
MACD1 :=2*(DIFF-DEA), COLORSTICK;
//开平条件2
macdjc:cross(diff,dea)and T1 and holding<=0,NODRAW;//macd金叉
macdsc:cross(dea,diff) AND T1 AND holding>=0,NODRAW;
if kdjjc and ct1<=1 and timecd and holding=0 then //开多
begin
buy(holding=0,1,market);
ct1:=ct1+1;
end
if kdjsc and ct2<=1 and holding>0 then //平多
begin
sell(holding>0,holding,market);
ct2:=ct2+1;
end
if macdsc and ct1<=1 and timecd and holding=0 then //开空
begin
buyshort(holding=0,1,market);
ct1:=ct1+1;
end
if macdjc and ct2<=1 and holding<0 then //平空
begin
sellshort(holding<0,holding,market);
ct2:=ct2+1;
end
平空:SELLSHORT(kdjsc,1,THISCLOSE); //平空信号
开多:BUY(kdjjc AND HOLDING=0,1,THISCLOSE) and TOTALDAYTRADE<2; //开多信号
平多:SELL(macdsc,1,THISCLOSE); //平多信号
开空:BUYSHORT(macdsc AND HOLDING=0,1,THISCLOSE)and TOTALDAYTRADE<2 ; //开空信号
收盘平多:SELL(T2 AND HOLDING>0,0,MARKET) ;
收盘平空:SELLSHORT(T2 AND HOLDING<0,0,MARKET) ;
持仓:holding,linethick0;
资产:=asset,noaxis;
可用现金:cash(0),linethick0;
首先感谢你的回答
以上我在你的KDJ,基础上完成一个模型,测试的结果是,收盘前能平仓,但是没有完成,一天只开仓两次,平仓两次,以后不再开仓的相法。如果开盘到下午只完成一次开平仓,即使下午2点过后也不再开仓的想法也没完成,
哪里编写错了?请帮助编写完成,再次感谢