模型策略源码:runmode:0;
variable:stopline=0;
entrylongcond:=ref(high,1)>ref(high,2) and ref(high,2)>ref(high,3) and ref(low,2)entryshortcond:=ref(low,1)ref(high,3) and ref(low,2)
atr:=3*ma(tr,15);
hh:=ref(high,1);
ll:=ref(low,1);
if holding=0 then begin
if entrylongcond then begin
buy(1,1,limitr,open);
stopline=:enterprice-atr;
end
if entryshortcond then begin
buyshort(1,1,limitr,open);
stopline:=enterprice+atr;
end
end
if holding>0 and enterbars>=1 then begin
if hh-atr>stopline then
stopline:=hh-atr;
if low=1 then begin
if ll+atr stopline:=ll+atr;
if high>=stopline then
sellshort(1,holding,limitr,max(open,stopline));
end
盈亏:asset-500000,noaxis,coloryellow,linethick2;
源码解析:
输出RUNMODE:0
输出 VARIABLE:STOPLINE=0
ATR赋值:3*真实波幅的15日简单移动平均
HH赋值:昨日最高价
LL赋值:昨日最低价
逻辑判断 HOLDING=0 THEN BEGIN 逻辑判断 ENTRYLONGCOND THEN BEGIN BUY(1,1,LIMITR,开盘价)
输出 STOPLINE=:ENTERPRICE-ATR
END 逻辑判断 ENTRYSHORTCOND THEN BEGIN BUYSHORT(1,1,LIMITR,开盘价)
STOPLINE赋值:ENTERPRICE+ATR
STOPLINE赋值:HH-ATR
逻辑判断 最低价=STOPLINE THEN SELLSHORT(1,HOLDING,LIMITR,开盘价和STOPLINE的较大值)
输出 END 盈亏:ASSET-500000,NOAXIS,画黄色,线宽为2