等级: 免费版
- 注册:
- 2021-6-1
- 曾用名:
|
楼主 |
发表于 2021-12-10 11:01
|
显示全部楼层
agreenleaf 发表于 2021-12-10 09:45
好的
我贴一个简单策略,发现还是有出入,我把代码贴上来,你帮我看看
//*******************************策略变量定义参数设置****************************
variable:CC1=0,CP1=0; //变量-持仓量 入场价
//*********************************趋势策略模块***********************************
M1:=MA(C,5); M2:=MA(C,30);
//平仓1---固定宽止损-防止黑天鹅意外
JSKDZSD:=ENTERPRICE*0.95;JSKDZSJ:=IF(OPEN<JSKDZSD-MINDIFF,OPEN,JSKDZSD-MINDIFF);
JSKKZSD:=ENTERPRICE*1.05;JSKKZSJ:=IF(OPEN>JSKKZSD+MINDIFF,OPEN,JSKKZSD+MINDIFF);
IF L<JSKDZSD AND ENTERBARS>0 AND HOLDING>0 THEN BEGIN
TSELL(HOLDING>0,0,LMT,JSKDZSJ);
止多:SELL(HOLDING>0,0,LIMITR,JSKDZSJ);
CC1:=0;CP1:=0;
END
IF H>JSKKZSD AND ENTERBARS>0 AND HOLDING<0 THEN BEGIN
TSELLSHORT(HOLDING<0,0,LMT,JSKKZSJ);
止空:SELLSHORT(HOLDING<0,0,LIMITR,JSKKZSJ);
CC1:=0;CP1:=0;
END
//**************************K线走完前3秒内运行判断以下部分*************************
abb:=(time0-timetot0(dynainfo(207)))<=3 OR NOT(ISLASTBAR);
IF NOT(abb) THEN GOTO Skip1;
//*******************************策略模型部分**************************************
//多单条件
KDTJ:cross(m1,m2) AND H>L AND BARPOS>30;
PDTJ:=cross(m2,m1) AND H>L;
//空单条件
KKTJ:=cross(m2,m1) AND H>L AND BARPOS>30;
PKTJ:=cross(m1,m2) AND H>L;
//仓位--平仓
IF CC1>0 AND PDTJ THEN BEGIN
TSELL(CC1>0,CC1,MKT);
平多:SELL(CC1>0,CC1,THISCLOSE);
CC1:=0;CP1:=0;
END
IF CC1<0 AND PKTJ THEN BEGIN
TSELLSHORT(CC1<0,ABS(CC1),MKT);
平空:SELLSHORT(CC1<0,ABS(CC1),THISCLOSE);
CC1:=0;CP1:=0;
END
//仓位--开仓
IF CC1=0 AND KDTJ THEN BEGIN
TN:=MAX(1,INTPART(24000/(O*MULTIPLIER*0.1)+0.3)); //使用资金计算仓位手数,最少1手
TBUY(CC1=0,TN,MKT);
开多:BUY(CC1=0,TN,THISCLOSE);
CC1:=TN;CP1:=C;
END
IF CC1=0 AND KKTJ THEN BEGIN
TN:=MAX(1,INTPART(24000/(O*MULTIPLIER*0.1)+0.3)); //使用资金计算仓位手数,最少1手
TBUYSHORT(CC1=0,TN,MKT);
开空:BUYSHORT(CC1=0,TN,THISCLOSE);
CC1:=-TN;CP1:=C;
END
skip1@ ;
//********************************策略输出信息**************************************
资产:ASSET,NOAXIS,COLORMAGENTA,PRECISION0;
持仓:CC1,nodraw,COLORYELLOW,PRECISION0;
持价:trimprice(CP1),nodraw,COLORRED;
次数:totaltrade,NODRAW;
胜率:percentwin,NODRAW; |
|