[PEL] 复制代码
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),NODRAW;
INPUT:N(10,1,200,1),X(2,0.1,100,0.1),ss(1,1,100,1);
tcd:not(time>=185500 or (time>=025500 and time<130000));//开仓时间限制
NH:HHV(MACD1,N);//N周期最大macd1
kk:NH>=X*ref(macd1,1);//N周期macd最大值大于前一周期macd值的X倍
zsp:ref(h,ENTERBARS);
jc:if(holding<>0,abs(zsp-AVGENTERPRICE),DRAWNULL);//价差=止损价-持仓均价 这里取绝对值数值.有持仓时候 值有效
pk1:macd1<ref(macd1,1) and macd1>0;//红柱前提下,macd大于前一周期macd
pk2:c>ref(h,1);//最新价大于前一周期最高价,注意这里用的c不是H.
pk3:AVGENTERPRICE-c>2*jc;
平仓1:sellshort(pk1,holding,LIMIT,c);//macd红柱变短平仓
平仓2:sellshort(pk2,holding,LIMIT,zsp+1*MINDIFF),IGNORECHECKPRICE;//最新价大于前一周期最高价平仓,但是这个平仓价格有时候会超出K线范围,因此加一个IGNORECHECKPRICE处理下
平仓3:sellshort(pk3,holding,market);//盈利2倍价差平仓
收盘平仓:sellshort(time>=185900 or (time>=025900 and time<130000),holding,market);
buyshort(kk and holding=0 and tcd,ss,market);
持仓:holding;