[PEL] 复制代码
variable:maxprofit:=0.01;
k:=1;//首次开仓手数;
jk:=1;//加仓手数;
tt:=3;//开仓每个信号之间的间距;
tp:=100;//止盈
lp:=20;//止损;
ma5:=ema((high+low+open+2*close)/5,5);
ma10:=ema((2*high+low+open+2*close)/6,10);
ma55:=ema(ema(c,34),34);
n_jc_ma5_ma10:=sumbars(cross(ma5,ma10),1);//金叉加仓;
n_sc_ma5_ma10:=sumbars(cross(ma10,ma5),1);//死叉减仓;
//中枢线
中枢:ema(ema(c,10),10),colorgreen,linethick2;
aa:=中枢>ref(中枢,1);//多头趋势;
中枢线:if(aa-0.03,中枢,drawnull),colorred,linethick2;
//趋势线
趋势:ema((2*high+low+open+2*close)/6,34),colormagenta,linethick2;
a:=趋势>ref(趋势,1);//多头趋势;
趋势线:if(a-0.03,趋势,drawnull),colorred,linethick2;
//大趋势
多空线:ema(ema(c,34),34),colorwhite,linethick2;
a2:=多空线>ref(多空线,1);//多头趋势;
大趋势:if(a2-0.03,多空线,drawnull),colorred,linethick2;
b:=cross(ma5,趋势);
s:=cross(趋势,ma5);
//引用macd
diff:=ema(close,9)-ema(close,34);
dea:=ema(diff,9);
macd:=(diff-dea)*2,colorstick;
//引用kd;
rsv:=(close-llv(low,21))/(hhv(high,21)-llv(low,21))*100;
k:=sma(rsv,5,1),colorred;
d:=sma(k,5,1),colorgreen;
//多空
xx:=b and diff>dea and k>d and a;
xxx:=s and dea>diff and d>k and not(a);
drawtext(xx,l*0.9998,'多'),colorred,fontszup3;
drawtext(xxx,h+3,'空'),coloryellow,fontszup3;
barsbk:ref(c,typebar(1,1));
barssp:=ref(c,typebar(1,2));
if holding=0 then maxprofit:=0.01;
tcd:time>=091000 and time<145000;
//开仓
kd:=xx;
sellshort(kd and holding<0 ,holding,market);
buy(kd and holding=0 and tcd,k,market);
jd:=min(barsbk,barssp)>=tt and c>=ma55 and n_jc_ma5_ma10=1;//加仓
加多:buy(holding>0 and jd and tcd,tt,market);
pd1:=min(barsbk,barssp)>=tt and c>=ma55 and n_sc_ma5_ma10=1;//减仓
减仓:sell(pd1,tt,market);
pd2:=cross(ema(ema(c,34),34),c);//下穿55日均线时候,平所有仓位;
下穿ema平多:sell(pd2,holding,market);
dzy:=c>avgenterprice+tp*mindiff;//止盈100跳;
多止盈:sell(dzy,holding,market);
dzs:=c<avgenterprice-lp*mindiff;//止损20跳;
多止损:sell(dzs,holding,market);
barssk:ref(c,typebar(1,3));
barssp:=ref(c,typebar(1,4));
kk1:=xxx;
sell(kk1,holding,market);
if holding=0 then maxprofit:=0.01;
buyshort(kk1 and holding=0 and tcd,k,market);
kk2:=min(barssk,barssp)>=tt and c<ma55 and n_sc_ma5_ma10=1;
buyshort(kk2 and holding=0 and tcd,jk,market);
pk1:=min(barssk,barssp)>=tt and c<ma55 and n_jc_ma5_ma10=1;
sellshort(pk1,jk,market);
pk2:=cross(c,ma55);
sellshort(pk2,holding,market);
pk3:=c<avgenterprice-lp*mindiff;
空止盈:sellshort(pk3,holding,market);
if holding=0 then maxprofit:=0.01;
if holding<>0 and maxprofit=0.01 then maxprofit:=openprofit;//如果maxprofit是初始值,直接赋值为最新的浮动盈亏
if openprofit>maxprofit and maxprofit<>0.01 then maxprofit:=openprofit;//更新最大盈利
//最大盈利大于0 当前小于最大盈利80%
if maxprofit>0 and openprofit<=maxprofit*0.8 and holding<>0 then
begin
回撤平多:sell(holding>0,0,market);
回撤平空:sellshort(holding<0,0,market);
maxprofit:=0.01;
end
if time>144500 and time<=150000 then//如果时间在14点45分以后,那么
begin
收盘平多:sell(holding>0,0,market);//如果持有多单,以市价卖出所有持仓量
收盘平空:sellshort(holding<0,0,market);//如果持有空单,以市价空头卖出所有持仓量
maxprofit:=0.01;
end