请求:
增加一个过滤模块;长阴不开多,等待下一次信号。例如下图
棉花(1205)5分钟,07月20日09:05 开多仓,我需要是(长阴不开多仓;等待下一次信号)10:40 开空仓。
上图代码
{棉花5分钟--日内交易}
runmode:0;
VARIABLE:ated=0; {开仓次数}
jysj:=time >=090000 and time <=145500;
DIR:=ABS(CLOSE-REF(CLOSE,12));
VIR:=SUM(ABS(CLOSE-REF(CLOSE,1)),12);
ER:=DIR/VIR;
FASTC:=(2 / (2 + 1));
SLOWC:=(2 / (27 + 1));
CS:=((ER * (FASTC - SLOWC)) + SLOWC);
CQ:=CS*CS;
AMA:EMA(DMA(CLOSE,CQ),2) ,COLORBLUE;
AA:AMA/ref(AMA,1)*1000,LINETHICK0;
A1:=AA>1000+0.01*27,LINETHICK0;
A3:=AA<999.9-0.01*5,LINETHICK0; //均线弯头,趋势开始形成,跟市开仓
PARTLINE(A1,AMA),COLORRED,LINETHICK2;
PARTLINE(A3,AMA),COLORGREEN,LINETHICK2;
buycond:=jysj and A1;
buyshortcond:=jysj and A3;
////////低开高走长阳,不开空。高开低走长阴,不开多//////////
yangx:=(C-O)/O*1000,LINETHICK0;//阳线长
yinx:=(O-C)/C*1000,LINETHICK0;//阴线长 //风险控制一种,高开低走长阴,不开多;等待下一次交易信号。
BKK:NOT(yangx>=3),LINETHICK0;//0为不开空;
BKD:NOT(yinx>=3),LINETHICK0; //0为不开多;等待下一次交易信号。
if holding=0 and buycond then begin
buy(1,3,limitr,close);
end
if holding=0 and buyshortcond then begin
buyshort(1,3,limitr,close);
end
if holding>0 and A3 then begin
sell(1,holding,limitr,close);
end
if holding<0 and A1 then begin
sellshort(1,holding,limitr,close);
end
//收盘前5分钟平仓
if time > 145500 then
begin
sell(holding > 0, 0, thisclose);
sellshort(holding < 0, 0, thisclose);
end
if time >=150000 then
myasset:=asset;
资产:myasset,noaxis,colormagenta,LINETHICK0;
胜率:percentwin,linethick0;
持仓:HOLDING,LINETHICK0;
次数:totaltrade,linethick0;
何为 “长阴”? 量化一下,然后在开仓条件中加一个not(长阴)
何为 “长阴”? 量化一下,然后在开仓条件中加一个not(长阴)
if holding=0 and buycond and NOT(yinx>=3) then begin
buy(1,3,limitr,close);
end
if holding=0 and buyshortcond and NOT(yangx>=3) then begin
buyshort(1,3,limitr,close);
end
结果只是下一个周期又开仓了,我需要的是(下一次开仓信号)10:40 开空仓
又开多是因为条件依然成立
可以用全局变量纪录一下 variable:var=0;
if holding=0 and buycond and var<>-1 then begin
if yinx>=3 then var:=-1;
buy(1,3,limitr,close);
end
if holding=0 and buyshortcond and var<>1 then begin
var:=0;
buyshort(1,3,limitr,c);
end