[PEL] 复制代码 //适用于日内小周期
input:手数(1,1,300,1);
variable:k_atr:=0;//记录开仓时候的atr
//macd指标模块
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;
con1:=macd1>ref(macd1,1) and diff>ref(diff,1);
con2:=h>=ref(hhv(h,todaybar),1)+1*mindiff;//日内创1个点位的新高
atr:stkindi('','atr.atr',0,-1,0);
if con1 and con2 and holding=0 and valid(atr) then
begin
buy(1,1,market);
k_atr:=atr;
end
//开仓后最大的收盘价 大于开仓价+1*开仓时候的atr,当前收盘价小于开仓价-0.2*开仓时候的atr
if hhv(c,enterbars+1)>enterprice+k_atr and c<enterprice-0.2*k_atr then 回撤止损:sell(1,holding,market);
//收盘价小于开仓价-1.2*开仓时候的atr
if c<enterprice-1.2*k_atr then 止损1:sell(1,holding,market);
//开仓后历时6个交易日,且价格小于 “开仓价-0.2*开仓时候的atr”
if count(time=closetime(0),enterbars+1)>=6 and c<enterprice-0.2*k_atr then 止损2:sell(1,holding,market); |