金字塔Dual Thrust交易系统源码 [金字塔模型]

模型策略源码:
input:k(0.7,0.1,1,0.1);

dist1:=barslast(day>ref(day,1))+1;

dist2:=ref(dist1,dist1);

predayhigh:=ref(hhv(high,dist2),dist1);

predaylow:=ref(llv(low,dist2),dist1);

predayclose:=ref(close,dist1);

predayrange:=max(predayhigh-predayclose,predayclose-predaylow);

dayopen:=ref(open,dist1-1);

upperband:=dayopen+k*predayrange;

lowerband:=dayopen-k*predayrange;

if holding=0 then begin

 if high>=upperband then

  buy(1,volunit,limitr,max(open,upperband));

end

if holding=0 then begin

 if low<=lowerband then

  buyshort(1,volunit,limitr,min(open,lowerband));

end

if holding>0 then begin

 if low<=lowerband then begin

  sell(1,holding,limitr,min(open,lowerband));

  buyshort(1,volunit,limitr,min(open,lowerband));

 end

 if time>=closetime(0) then

  sell(1,holding,limitr,close);

end

if holding<0 then begin

 if high>=upperband then begin

  sellshort(1,holding,limitr,max(open,upperband));

  buy(1,volunit,limitr,max(open,upperband));

 end

 if time>=closetime(0) then

  sellshort(1,holding,limitr,close);

end

资产:asset,noaxis,colorred,linethick2;

点击复制上述代码粘贴到公示管理器

源码解析:

输出INPUT:K(0.7,0.1,1,0.1)
DIST1赋值:上次日>昨日日距今天数+1
DIST2赋值:DIST1日前的DIST1
PREDAYHIGH赋值:DIST1日前的DIST2日内最高价的最高值
PREDAYLOW赋值:DIST1日前的DIST2日内最低价的最低值
PREDAYCLOSE赋值:DIST1日前的收盘价
PREDAYRANGE赋值:PREDAYHIGH-PREDAYCLOSE和PREDAYCLOSE-PREDAYLOW的较大值
DAYOPEN赋值:DIST1-1日前的开盘价
UPPERBAND赋值:DAYOPEN+K*PREDAYRANGE
LOWERBAND赋值:DAYOPEN-K*PREDAYRANGE
逻辑判断 HOLDING=0 THEN BEGIN 逻辑判断 最高价>=UPPERBAND THEN  BUY(1,VOLUNIT,LIMITR,开盘价和UPPERBAND的较大值)
ENDIF HOLDING=0 THEN BEGIN 逻辑判断 最低价<=LOWERBAND THEN  BUYSHORT(1,VOLUNIT,LIMITR,开盘价和LOWERBAND的较小值)
ENDIF HOLDING>0 THEN BEGIN 逻辑判断 最低价<=LOWERBAND THEN BEGIN  SELL(1,HOLDING,LIMITR,开盘价和LOWERBAND的较小值)
  BUYSHORT(1,VOLUNIT,LIMITR,开盘价和LOWERBAND的较小值)
 END  逻辑判断 时间>=CLOSETIME(0) THEN   SELL(1,HOLDING,LIMITR,收盘价)
ENDIF HOLDING<0 THEN BEGIN 逻辑判断 最高价>=UPPERBAND THEN BEGIN  SELLSHORT(1,HOLDING,LIMITR,开盘价和UPPERBAND的较大值)
  BUY(1,VOLUNIT,LIMITR,开盘价和UPPERBAND的较大值)
 END  逻辑判断 时间>=CLOSETIME(0) THEN  SELLSHORT(1,HOLDING,LIMITR,收盘价)
输出END资产:ASSET,NOAXIS,画红色,线宽为2


---「相关文章 」---
1:程序化交易的优点与缺点   网页链接
2:全球十大程序化交易系统 (源码) 网页链接
3:详解程序化交易Dual Thrust策略 网页链接
4:金字塔Dual Thrust交易系统源码 网页链接
雪球转发:2回复:1喜欢:25

全部评论

小生_林2016-10-15 23:22

是不是写错了,贴上去说:limitr 控制符只能用在交易系统控制语句中