收盘价下穿今日开盘价做空,亏损2%止损,盈利20%止盈。空单止损后最高价N周期小于今日开盘价再次开空;收盘价上穿今日开盘价做多,亏损2%止损,盈利20%止盈。多单止损后最低价N周期大于今日开盘价再次开多;当日亏损总额大于等于20%,不再开仓,收盘前10分钟全平;
仅供参考,建议客户理解代码思路后再次基础上进行修改和完善即可。
VARIABLE:mark:=0;//全局变量标记止损
N:=10;
dayOpen:CALLSTOCK('',vtOPEN,6,0);//当日开盘价
zyk:=(ASSET-ref(ASSET,TODAYBAR))/ASSET;//总资产变化幅度,如果亏损大于20%不再开仓
abb:=timetot0(CLOSETIME(0))-time0,NODRAW;//当前K线时间距离收盘K线结束倒计时
abb3:=timetot0(CLOSETIME(0))-timetot0(dynainfo(207)),NODRAW;//当前时间距离收盘K时间
收盘平仓:(abb<10*60 and abb>=0 and (not(ISLASTBAR))) or (ISLASTBAR and abb3>=0 and abb3<10*60);
if cross(dayOpen,c) and holding=0 and zyk>=-0.02 and not(收盘平仓) then //空头开仓
begin
buyshort(1,1,market);
mark:=0;
end
ktyk:=(AVGENTERPRICE-c)/AVGENTERPRICE;
if ktyk>=0.2 or ktyk<=-0.02 and holding<0 then //空头止盈止损
begin
if ktyk<0 then mark:=-1;
sellshort(1,holding,market);
end
if mark=-1 and llv(l,N)<dayOpen and zyk>=-0.02 and not(收盘平仓) then buyshort(holding=0,1,market);//空头止损后开仓
if cross(c,dayOpen) and holding=0 and zyk>=-0.02 and not(收盘平仓) then //多头开仓
begin
buy(1,1,market);
mark:=0;
end
dtyk:=(c-AVGENTERPRICE)/AVGENTERPRICE;
if dtyk>=0.2 or dtyk<=-0.02 and holding>0 then //多头止盈止损
begin
if dtyk<0 then mark:=1;
sell(holding>0,holding,market);
end
if mark=1 and llv(l,N)>dayOpen and zyk>=-0.02 and not(收盘平仓) then buy(holding=0,1,market);//多头止损后开仓
IF 收盘平仓 THEN
BEGIN
sell(holding>0,holding,market);
sellshort(1,holding,market);
mark:=0;
END