以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://222.73.7.161/bbs/index.asp)
--  公式模型编写问题提交  (http://222.73.7.161/bbs/list.asp?boardid=4)
----  求策略编写  (http://222.73.7.161/bbs/dispbbs.asp?boardid=4&id=157575)

--  作者:阿汤
--  发布时间:2017/9/4 14:10:19
--  求策略编写
IF CURRENTDATE>1180101 THEN RETURN;
DP:=DATAPERIOD;
NT:= REF(HOUR,1)=15 AND HOUR<>15,NODRAW; 
CNT:= BARSLAST(NT)+1,NODRAW;
天数:COUNT2(NT,DATACOUNT),NODRAW;
CNTTT:=(CNT[CNT]),NODRAW;
//CNTTT:COUNT2(CNTT=CNTT[NODRAW],0),NODRAW;
N:=IF(DP=1,30,IF(DP=13,10,IF(DP=2,6,IF(DP=3,2,IF(DP=4,1, DRAWNULL)))));

DVOL_:= SUM(VOL, CNT);
DVC:= SUM(VOL*(H+O+L+C)/4, CNT);
DMAC:= DVC/DVOL_,COLORFF0000;

M4:=(C-REF(C,4))/5+MA(C,5),COLORFFFFFF;
MA5:MA(C,5),COLORFF80FF;
EMA12:MA(EMA(C,12),2),COLORFF8000,LINETHICK2;
前EMA12:=REF(EMA12,1);
DDEA2:=EMA((EMA(C,24)-EMA(C,52)),18)+EMA(C,52),LINETHICK2;

DDEA4:=EMA(DDEA2,4);
DDEA6:=EMA(DDEA2,6);
DDEA8:=EMA(DDEA2,8);
DDEA16:=EMA(DDEA2,16);
DDEA30:=EMA(DDEA2,30);
DDEA60:=EMA(DDEA2,60);
中轴:IF((DP<3 OR DP=13),DDEA8,IF(DP>2 AND DP<6,DDEA6,IF(DP>6 AND DP<13,DDEA4,DDEA6))),COLORC08080;
DRAWICON(中轴<=DDEA2,中轴,9),ALIGN(1);
DRAWICON(中轴>DDEA2,中轴,10),ALIGN(1),COLOR808040;

昨结:=IF((DP=1 OR DP=13),DYNAINFO(02),DRAWNULL),COLORFFFFFF;
均价:IF((DP<3 OR DP=13),DMAC,DRAWNULL),COLOR00FFFF,LINETHICK2;
今H:=HHV(H,CNT);今L:=LLV(L,CNT);
今H周期数:=BARSLAST(H>REF(今H,1));今L周期数:=BARSLAST(L<REF(今L,1));
今结H:=REF(均价,今H周期数),COLOR8000FF;今结L:=REF(均价,今L周期数),COLOR00FFFF;
时归:=IF((DP<5 OR DP=13) ,2*C/5+STKCALC(\'\',5,\'REF(MA(C,5),1)-(REF(C,4)+REF(C,5))/5\'),DRAWNULL);
时M5:=IF((DP<5 OR DP=13) ,C/5+STKCALC(\'\',5,\'REF(MA(C,5),1)-REF(C,5)/5\'),DRAWNULL);
上叉周期数:=IF(时归>时M5,BARSLAST(CROSS(时归,时M5))+1,DRAWNULL),NODRAW;
下叉周期数:=IF(时归<时M5,BARSLAST(CROSS(时M5,时归))+1,DRAWNULL),NODRAW;

//日EMA12:=IF((DP<6 OR DP=13) ,STKCALC(\'\',6,\'MA(EMA(C,12),2)\'),DRAWNULL);
M12:=EMA((EMA(C,12)-EMA(C,26)),9)+EMA(C,26);
DIFF:=EMA(C,12)-中轴,COLORFFFFFF;
DEA:=M12-中轴,COLOR00FFFF;
金叉周期数:=BARSLAST(CROSS(DIFF,DEA)),NODRAW;
金叉数:=COUNT2(CROSS(DIFF,DEA),0),NODRAW;
前金叉数:=COUNT2(CROSS(DIFF,DEA)AND 金叉数-1,0),NODRAW;
金S:=DATACOUNT-BARPOS+金叉周期数,NODRAW;
前金叉总数:=(前金叉数[DATACOUNT-金S]),NODRAW;
前金叉周期数:=BARSLAST(CROSS(DIFF,DEA) AND 前金叉数<=前金叉总数),NODRAW;
前金叉DIFF:=REF(EMA12,前金叉周期数);金叉DIFF:=REF(EMA12,金叉周期数);
死叉周期数:=BARSLAST(CROSS(DEA,DIFF)),NODRAW;
死叉数:=COUNT2(CROSS(DEA,DIFF),0),NODRAW;
前死叉数:=COUNT2(CROSS(DEA,DIFF)AND 死叉数-1,0),NODRAW;
死S:=DATACOUNT-BARPOS+死叉周期数,NODRAW;
前死叉总数:=(前死叉数[DATACOUNT-死S]),NODRAW;
前死叉周期数:=BARSLAST(CROSS(DEA,DIFF) AND 前死叉数<=前死叉总数),NODRAW;
前死叉DIFF:=REF(EMA12,前死叉周期数);死叉DIFF:=REF(EMA12,死叉周期数);

开多:=100;开空:=200;平多:=0;平空:=0;

多条件:=IF((DP<6 OR DP=13)AND M4>均价 AND EMA12>REF(EMA12,1)AND DDEA2>中轴  AND DEA>0 AND DIFF>DEA AND EMA12>金叉DIFF,100,DRAWNULL),NODRAW;
空条件:=IF((DP<6 OR DP=13)AND M4<均价 AND EMA12<REF(EMA12,1)AND DDEA2<中轴  AND DEA<0 AND DEA>DIFF AND EMA12<死叉DIFF,200,DRAWNULL),NODRAW;
//平多条件:=IF((DP=1 OR DP=13)AND 今结<今结H AND DDEA2<中轴,1,0),NODRAW;
//平空条件:=IF((DP=1 OR DP=13)AND 今结>今结L AND DDEA2>中轴,1,0),NODRAW;
平多条件:=IF(((DP=1 OR DP=13 )AND DIFF<DEA AND DDEA2<中轴 AND EMA12<=中轴)
OR(DP=2 AND DIFF<DEA AND M4<EMA12),1,0),NODRAW;
平空条件:=IF(((DP=1 OR DP=13 )AND DIFF>DEA AND DDEA2>中轴 AND EMA12>=中轴)
OR(DP=2 AND DIFF>DEA AND M4>EMA12),1,0),NODRAW;

开多仓:=BARSLAST(多条件=100 AND REF(多条件,1)<>100),NODRAW;
开空仓:=BARSLAST(空条件=200 AND REF(空条件,1)<>200),NODRAW;
//平空条件1
已平空1:=BARSLAST(平空条件=1 AND REF(平空条件,1)<>1),NODRAW;
已平多1:=BARSLAST(平多条件=1 AND REF(平多条件,1)<>1),NODRAW;

多开仓次数1:=COUNT2(开多仓=0,已平多1),NODRAW;
空开仓次数1:=COUNT2(开空仓=0,已平空1),NODRAW;
已平空:=BARSLAST(空开仓次数1=1 AND REF(空开仓次数1,1)<>1),NODRAW;
已平多:=BARSLAST(多开仓次数1=1 AND REF(多开仓次数1,1)<>1),NODRAW;

多平仓次数:=COUNT2(平多条件=1,已平多),NODRAW;
空平仓次数:=COUNT2(平空条件=1,已平空),NODRAW;
HHH:=HHV(H,60);
LLH:=LLV(H,60);
HHL:=HHV(L,60);
LLL:=LLV(L,60);
DRAWTEXT(开空仓=0 AND 空开仓次数1=1,(HHH+中轴)/2,\'开空\'),FONTSIZE(11),ALIGN(1),VALIGN(2),COLORFFFF80;
DRAWTEXT(开多仓=0 AND 多开仓次数1=1,(LLH+中轴)/2,\'开多\'),FONTSIZE(11),ALIGN(1),VALIGN(0),COLORFF80FF;
//平空条件
DRAWTEXT(平多条件=1 AND 多平仓次数=1,(HHL+中轴)/2,\'多平\'),FONTSIZE(11),ALIGN(1),VALIGN(2),COLORFFFFFF;
DRAWTEXT(平空条件=1 AND 空平仓次数=1,(LLL+中轴)/2,\'空平\'),FONTSIZE(11),ALIGN(1),VALIGN(0),COLORFFFFFF;
已开多周期数:=BARSLAST(开多仓=0 AND 多开仓次数1=1),NODRAW;
已开空周期数:=BARSLAST(开空仓=0 AND 空开仓次数1=1),NODRAW;

已开多仓次数:=COUNT2(开多仓=0 AND 多开仓次数1=1,0),NODRAW;
已开空仓次数:=COUNT2(开空仓=0 AND 空开仓次数1=1,0),NODRAW;
//平空条件
已平多仓次数:=COUNT2(平多条件=1 AND 多平仓次数=1,0),NODRAW;
已平空仓次数:=COUNT2(平空条件=1 AND 空平仓次数=1,0),NODRAW;
开多价:=REF(C,已开多周期数),NODRAW;
开空价:=REF(C,已开空周期数),NODRAW;
平多价:=IF(平多条件=1 AND 多平仓次数=1,C,DRAWNULL),NODRAW;
平空价:=IF(平空条件=1 AND 空平仓次数=1,C,DRAWNULL),NODRAW;
多单盈亏:=IF(平多条件=1 AND 多平仓次数=1,C-开多价,DRAWNULL),NODRAW;
空单盈亏:=IF(平空条件=1 AND 空平仓次数=1,开空价-C,DRAWNULL),NODRAW;
吨多单盈亏计:IF(SUM(多单盈亏, 0)<>DRAWNULL,SUM(多单盈亏, 0),0),NODRAW;
吨空单盈亏计:IF(SUM(空单盈亏, 0)<>DRAWNULL,SUM(空单盈亏, 0),0),NODRAW;
吨总盈亏:(吨多单盈亏计+吨空单盈亏计),NODRAW;RETURN;