遵循开仓之前先平反手仓位的原则。所以你平空要在开多之前
[PEL] 复制代码
INPUT:M(14,1,300,30);
VARIABLE:ct:=0,atrValue:=0;
ma20:ma(c,20);
ma60:ma(c,60);
TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR:MA(TR1,m);
majc:=cross(ma20,ma60);
masc:=cross(ma60,ma20);
if majc and holding<0 then
begin
sellshort(1,holding,market);
ct:=0;
atrValue:=0;
end
// 开多
if majc and holding=0 then
begin
buy(majc and holding=0,1,market);
atrValue:=ATR;
end
if holding>0 and ct<=4 and (c-ENTERPRICE)>=atrValue and atrValue<>0 then //每次最新价较上次开仓价上涨一个atr 加仓一次
begin
buy(1,1,market);
ct:=ct+1;
atrValue:=ATR;
end
if masc and holding>0 then
begin
sell(1,holding,market);
ct:=0;
atrValue:=0;
end
// 开空
if masc and holding=0 then
begin
buyshort(masc and holding=0,1,market);
atrValue:=ATR;
end
if holding<0 and ct<=4 and (ENTERPRICE-c)>=atrValue and atrValue<>0 then //每次最新价较上次开仓价下跌一个atr 加仓一次
begin
buyshort(1,1,market);
ct:=ct+1;
atrValue:=ATR;
end
|