--
//该模型为简单示范模型,用户需根据自己交易经验,修改完善后再实际应用!!!
//变量申明
VARIABLE:DAYCOUNT=1,POSITIONCOUNT=1,SELLSIGN=0;//定义常数变量DAYCOUNT并初始化为1,定义常数变量POSITIONCOUNT并初始化为1,定义常数变量SELLSIGN并初始化为0
VARIABLE:ENTANDEXITSIGN=1,ENTPOINT=0,EXITPOINT=0;//定义常数变量ENTANDEXITSIGN并初始化为1,定义常数变量ENTPOINT并初始化为0,定义常数变量EXITPOINT并初始化为0
VARIABLE:N=0;//定义常数变量N并初始化为0
MA1:MA(C,5);//输出5日均价
MA3:MA(C,10);//输出10日均价
M:=MA(TR,20); //真实波幅的20周期均值
BUYHHV:=HHV(H,20);//20日最高价
SELLLLV:=LLV(L,10);//10日最低价
SS:N,LINETHICK0;
//交易系统
IF BARPOS>=21 THEN BEGIN //如果从上市到现在的交易日天数大于等于21天,那么
IF BARPOS=21 THEN //如果从上市到现在的交易日天数等于21,那么
N:=M; //N=M
IF DAYCOUNT=6 OR BARPOS=21 THEN BEGIN{5天调整N值}
N:=(19*N+TR)/20;{计算N值}
DAYCOUNT:=2;
END
DAYCOUNT:=DAYCOUNT+1;
ENTPOINT:=ENTERBARS+1;
IF ENTPOINT=ENTANDEXITSIGN THEN BEGIN{说明STOP指令买进头寸成功}
POSITIONCOUNT:=POSITIONCOUNT+1;{头寸计数}
SELLSIGN:=TRUE;{开始以STOP卖出,如果达到指定的价格}
END
IF POSITIONCOUNT=1 THEN BEGIN{第一头寸}
HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
开1:BUY(H>=BUYHHV,HOW,MARKET);{在20日新高STOP指令买进}
END
IF POSITIONCOUNT=2 THEN BEGIN{如到第二头寸}
HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
开2:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);{在上头寸(即第一头寸)+0.5个N以STOP指令买进}
END
IF POSITIONCOUNT=3 THEN BEGIN{如到第三头寸}
HOW:=CASH(0)*0.01/N;
开3:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);{在上头寸(即第二头寸)+0.5个N以STOP指令买进}
END
IF POSITIONCOUNT=4 THEN BEGIN
HOW:=CASH(0)*0.01/N;
开4:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);
END
IF SELLSIGN=TRUE THEN BEGIN
EXITPOINT:=EXITBARS+1;
IF EXITPOINT=ENTANDEXITSIGN THEN BEGIN {说明卖出成功}
POSITIONCOUNT:=1;{头寸计算复原}
SELLSIGN:=FALSE;
END
IF ENTERPRICE-2*N THEN SELL(L<=SELLLLV,100%,MARKET);{退出离盈利头寸}
ELSE
SELL(L<=ENTERPRICE-2*N,100%,MARKET);{退出亏损头寸}
END
END;
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;