金字塔公式 金字塔模型策略源码:runmode:0;
input:n(20,5,100,5);
a:=close-ref(close,n);
mi:=sma(a,n,1);
longcond:=cross(a,mi);
shortcond:=cross(mi,a);
if holding=0 then begin
if longcond then
buy(1,1,limitr,close);
end
if holding=0 then begin
if shortcond then
buyshort(1,1,limitr,close);
end
if holding>0 then begin
if shortcond then begin
sell(1,holding,limitr,close);
buyshort(1,1,limitr,close);
end
end
if holding<0 then begin
if longcond then begin
sellshort(1,holding,limitr,close);
buy(1,1,limitr,close);
end
end
盈亏:asset,noaxis,colormagenta;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;
复制上述代码粘贴到到公式管理器
源码解的:
输出RUNMODE:0
输出INPUT:N(20,5,100,5)
A赋值:收盘价-N日前的收盘价
MI赋值:A的N日[1日权重]移动平均
LONGCOND赋值:A上穿MI
SHORTCOND赋值:MI上穿A
逻辑判断 HOLDING=0 THEN BEGIN 逻辑判断 LONGCOND THEN BUY(1,1,LIMITR,收盘价)
ENDIF HOLDING=0 THEN BEGIN 逻辑判断 SHORTCOND THEN BUYSHORT(1,1,LIMITR,收盘价)
ENDIF HOLDING>0 THEN BEGIN 逻辑判断 SHORTCOND THEN BEGIN SELL(1,HOLDING,LIMITR,收盘价)
BUYSHORT(1,1,LIMITR,收盘价)
ENDENDIF HOLDING<0 THEN BEGIN 逻辑判断 LONGCOND THEN BEGIN SELLSHORT(1,HOLDING,LIMITR,收盘价)
BUY(1,1,LIMITR,收盘价)
输出 ENDEND盈亏:ASSET,NOAXIS,画洋红色
输出次数:TOTALTRADE,线宽为0
输出胜率:PERCENTWIN,线宽为0
输出连亏:MAXSEQLOSS,线宽为0
输出连赢:MAXSEQWIN,线宽为0