个股引用创业板指数
买入条件:当创业板的dea >=0时, DD1为创业板指数的DIFF ,DD2为创业板指数的DEA,DD3为 创业板指数的MACD,
DD1>=DD2&&DD3>REF(DD3,1)&&REF(DD3,1)>REF(DD3,2); 买 。
或者 当创业板的dea <0时 ,DD1上穿DD2时买。
卖出条件:
创业板的的macd<=0时,卖出;
或者个股的macd<=0时,卖出;
要求:第二天个股才卖。
首先新建一个指标A,把需要调用的东西都定义好。:
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;
macdjc:cross(diff,dea),NODRAW;//macd金叉
macdsc:cross(dea,diff),NODRAW;
然后交易的模型代码,以图表模型为例:
//dd1-dd4都是创业板指数
dd1:STKINDI('399006','A.diff',0,-1,0);
dd2:STKINDI('399006','A.dea',0,-1,0);
dd3:STKINDI('399006','A.macd1',0,-1,0);
dd4:STKINDI('399006','A.macdjc',0,-1,0);//diff 上传dea
//dd5 是当前品种的macd值
dd5:STKINDI('','A.macd1',0,-1,0);
cd1:dd2>0 and DD1>=DD2 and DD3>REF(DD3,1) and REF(DD3,1)>REF(DD3,2);
cd2:dd2<0 and dd4;
if (cd1 or cd2) and DAYHOLDING=0 then buy(1,500,market);
if (dd5<0 or dd3<0) and HOLDING-DAYHOLDING>0 then sell(1,HOLDING-DAYHOLDING,market);
持仓:holding;
可用持仓:HOLDING-DAYHOLDING;