[PEL] 复制代码
//声明变量
input:s(12,5,40,4),p(26,20,100,8),m(9,1,100,10);
input:n(2,1,10,1),m1(20,1,1000,1);
input:m2(14,1,50,1);
input:amounts(1);
input:s1(0.02,0,0.2,0.01);
input:s2(0.95,0.5,1,0.01),s3(1.05,1,1.5,0.01);
variable:mark:=0;
//中间变量
diff:=ema(close,s) - ema(close,p);
dea:=ema(diff,m);
macd1:=2*(diff-dea), colorstick;
bbi:(ma(close,3)+ma(close,6)+ma(close,12)+ma(close,24))/4;
upr:bbi+n*std(bbi,m1);
dwn:bbi-n*std(bbi,m1);
tr1:=max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr:=ma(tr1,m2);
//交易条件
cond_buy1:=cross(diff,dea); //macd金叉
cond_buy3:=close/bbi>s2 and close/bbi<s3; //0.95<最新价/bbi<1.05
cond_sell1:=cross(dea,diff); //macd死叉
cond_sell2:=cross(close,upr) or cross(close,dwn); // 最新价穿过boll上轨或下轨
cond_stop:=enterprice-close>=2*atr; //两倍atr止损
cond_buy4:=close>=enterprice-2*atr; //止损后反弹至止损位时重新开入订单
//执行交易
if holding=0 and mark=0 then buy(cond_buy1 and cond_buy3,amounts,market); //买入条件1且条件3
if holding>0 and cond_stop and enterbars>0 then begin
止损:sell(1,holding,market); //当买入后触发2倍atr止损
mark:=1;//标记下 当前触发了止损了
end
if holding=0 and mark=1 and cond_buy4 then
begin
反弹开仓:buy(1,amounts,market); //止损后反弹至2倍atr后重新买入
mark:=0;
end
if holding>0 and enterbars>0 then sell(cond_sell1 or cond_sell2,holding,market); //卖出条件1或条件2