公式网-网站导航


网站搜索:  

公式指标网 发表于2015/10/25 7:24:54

金字塔趋势跟踪交易系统

金字塔公式 金字塔模型策略源码:input:period(60,5,120,5);
input:length(20,5,40,5);
input:trailingstop(3,1,6,1);
variable:stopline=0;
topband:=ref(hhv(high,period),1)+mindiff;
botband:=ref(llv(low,20),1)-mindiff;
atr:=ref(ma(tr,length),1);
trailingstopnum:=trimprice(trailingstop*atr);
if holding=0 then begin
if barpos>period and high>=topband then
buy(1,100%,limitr,close);
end
if holding>0 then begin
if high-trailingstopnum>stopline then
stopline:=high-trailingstopnum;
if enterbars>=2 and low<=stopline then begin
sell(1,holding,limitr,close);
stopline:=0;
end
end
partline(holding>0 and enterbars>=2,stopline,coloryellow,1);
盈亏:asset,noaxis,colormagenta;
收益:(asset-500000)/500000,linethick0;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;

复制上述代码粘贴到到公式管理器

源码解析:

输出INPUT:周期
 输出INPUT:LENGTH(20,5,40,5)
输出INPUT:TRAILINGSTOP(3,1,6,1)
输出VARIABLE:STOPLINE=0
 TOPBAND赋值:昨日周期日内最高价的最高值+MINDIFF
 BOTBAND赋值:昨日20日内最低价的最低值-MINDIFF
 ATR赋值:昨日真实波幅的LENGTH日简单移动平均
 赋值:TRIMPRICE(TRAILINGSTOP*ATR)
逻辑判断 HOLDING=0 THEN BEGIN 逻辑判断 BARPOS>周期 AND 最高价>=TOPBAND THEN  BUY(1,100%,LIMITR,收盘价)
STOPLINE赋值:最高价-TRAILINGSTOPNUM
   逻辑判断 ENTERBARS>=2 AND 最低价<=STOPLINE THEN BEGIN  SELL(1,HOLDING,LIMITR,收盘价)
STOPLINE赋值:0
  END ENDPARTLINE(HOLDING>0 AND ENTERBARS>=2,STOPLINE,画黄色,1)
输出盈亏:ASSET,NOAXIS,画洋红色
 输出      收益:(ASSET-500000)/500000,线宽为0
输出次数:TOTALTRADE,线宽为0
输出胜率:PERCENTWIN,线宽为0
输出连亏:MAXSEQLOSS,线宽为0
输出连赢:MAXSEQWIN,线宽为0
 

 



网站搜索:  



Copyright © 2009-2010 gszb.com ™,All Rights Reserved. 
公式网-www.gszx.com.cn-股票指标公式网