金字塔Dual Thrust交易系统源码 [金字塔模型]
源码:[code]
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;[/code] [code]
点击复制上述代码粘贴到公示管理器 源码解析: 输出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
作者:量化投资Quant
链接:https://xueqiu.com/5256769224/32429305
来源:雪球
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。[/code]
页:
[1]