金字塔公式 金字塔模型策略源码:runmode:0;
input:p(26,20,100,8);
input:s(12,5,40,4);
input:m(9,2,60,6);
variable:myasset=300000;
diff:=ema(close,s)-ema(close,p);
dea:=ema(diff,m);
macd:=2*(diff-dea);
entertime:=time>=091000 and time<=145500;
exittime:=time>=150000;
buycond:=ref(cross(macd,0),1);
sellcond:=ref(cross(0,macd),1);
if holding=0 then begin
if buycond then
buy(1,1,limitr,open);
end
if holding=0 then begin
if sellcond then
buyshort(1,1,limitr,open);
end
if holding>0 then begin
if exittime then
sell(1,holding,limitr,close);
if sellcond then begin
sell(1,holding,limitr,open),orderqueue;
buyshort(1,1,limitr,open),orderqueue;
end
end
if holding<0 then begin
if exittime then
sellshort(1,holding,limitr,close);
if buycond then begin
sellshort(1,holding,limitr,open),orderqueue;
buy(1,1,limitr,open),orderqueue;
end
end
if exittime then
myasset:=asset;
收益:myasset,noaxis,colormagenta;
次数:totaltrade,linethick0;
胜率:percentwin,linethick0;
连亏:maxseqloss,linethick0;
连赢:maxseqwin,linethick0;
复制上述代码粘贴到到公式管理器
源码解析:
输出RUNMODE:0
输出INPUT:P(26,20,100,8)
输出INPUT:S(12,5,40,4)
输出INPUT:M(9,2,60,6)
输出VARIABLE:MYASSET=300000
DIFF赋值:收盘价的S日指数移动平均-收盘价的P日指数移动平均
DEA赋值:DIFF的M日指数移动平均
MACD赋值:2*(DIFF-DEA)
ENTERTIME赋值:时间>=091000 AND 时间<=145500
EXITTIME赋值:时间>=150000
BUYCOND赋值:昨日MACD上穿0
SELLCOND赋值:昨日0上穿MACD
逻辑判断 HOLDING=0 THEN BEGIN 逻辑判断 BUYCOND THEN BUY(1,1,LIMITR,开盘价)
ENDIF HOLDING=0 THEN BEGIN 逻辑判断 SELLCOND THEN BUYSHORT(1,1,LIMITR,开盘价)
ENDIF HOLDING>0 THEN BEGIN 逻辑判断 EXITTIME THEN SELL(1,HOLDING,LIMITR,收盘价)
逻辑判断 SELLCOND THEN BEGIN SELL(1,HOLDING,LIMITR,开盘价),ORDERQUEUE
BUYSHORT(1,1,LIMITR,开盘价),ORDERQUEUE
END ENDIF HOLDING<0 THEN BEGIN 逻辑判断 EXITTIME THEN SELLSHORT(1,HOLDING,LIMITR,收盘价)
逻辑判断 BUYCOND THEN BEGIN SELLSHORT(1,HOLDING,LIMITR,开盘价),ORDERQUEUE
BUY(1,1,LIMITR,开盘价),ORDERQUEUE
MYASSET赋值:ASSET
输出 收益:MYASSET,NOAXIS,画洋红色
输出次数:TOTALTRADE,线宽为0
输出胜率:PERCENTWIN,线宽为0
输出连亏:MAXSEQLOSS,线宽为0
输出连赢:MAXSEQWIN,线宽为0