[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), COLORSTICK;
macdjc:cross(diff,dea),NODRAW;//macd金叉
macdsc:cross(dea,diff),NODRAW;
MA1:=MA(CLOSE,5);
MA2:=MA(CLOSE,30);
kd:cross(MA1,MA2) or (c>MA2 and macdjc);
pd:cross(MA2,MA1);
variable:maxprofit=0;//有仓位时最大获利幅度
//开仓
IF kd and holding=0 THEN
BEGIN
BUY(1,1,market);
maxprofit:=0;
END
//平仓
SELL(pd,holding,market);
//判断当前持仓状态下的最大盈利
win:=0;
win2:=0;
if holding > 0 and enterbars > 0 then
begin
win:=(h-enterprice)/enterprice*100; //记录最大盈利
if win>maxprofit then
maxprofit:=win;
win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度
end
zs:(AVGENTERPRICE-c)>=30*MINDIFF;
//出现浮动亏损比如2%平仓
止损:SELL(zs,holding,market);
//出现最高盈利后,回落到盈利的60%平仓出场
止赢:SELL(win2 >= 80 and openprofit > 0, 0,limit,c);
以多头为例,空头你可以参照这个 尝试自行实现下。 |