有个范例的,你把里面开平仓的条件换成你自己的就行了。
input:p(26,20,100,8),s(12,5,40,4),m(9,2,60,6);//参数设置
VARIABLE:ct:=0;//全局变量来记录加仓次数
ma5:ma(c,5);
ma13:ma(c,13);
majc:cross(ma5,ma13);
masc:cross(ma13,ma5);
DIFF : EMA(CLOSE,S) - EMA(CLOSE,P);
DEA : EMA(DIFF,M);
MACD1 : 2*(DIFF-DEA), COLORSTICK;
macdjc:cross(diff,dea);//macd金叉
buy(majc and holding=0,1,market);//开仓
if macdjc and ct<=3 and holding>0 then //加仓操作
begin
加仓:buy(holding>0,1,market);
ct:=ct+1;//加仓时增加ct的值
end
if masc and holding>0 then //平仓操作
begin
sell(holding>0,holding,market);
ct:=0; //平仓重置ct的值
end