金字塔公式 金字塔模型策略源码:
VARIABLE: MAE=0,MFE=0;
INPUT:DAYLONG(40,4,400,4);//DAYLONG个周期后平仓
//简单模型
UP:HHV(H,40);
LONG:=REF(UP,1);
IF HOLDING<>0 THEN
BEGIN
IF ENTERBARS>=DAYLONG AND HOLDING>0 THEN SELL(1,1,thisclose);
END
ELSE THEN
BEGIN
IF H>=LONG AND HOLDING=0 THEN BUY(1,1,STOPR,LONG);
END
//开始取MAE和MFE
IF REF(HOLDING,1)=0 THEN GOTO DONE;
PP:=OPENPROFIT,LINETHICK0;
浮动盈亏:PP,LINETHICK0;
IF PP>0 AND HOLDING<>0 THEN
BEGIN
IF PP>MAE THEN MAE:=PP;
END
ELSE THEN
BEGIN
IF PP<MFE THEN MFE:=PP;
END
DONE@ AA:=IFELSE(EXITBARS=0,MAE,0),LINETHICK0;
BB:=IFELSE(EXITBARS=0,MFE,0),LINETHICK0;
当笔交易MAE:AA,LINETHICK0;
当笔交易MFE:BB,LINETHICK0;
IF EXITBARS=0 THEN
BEGIN
MAE:=0;
MFE:=0;
END
SMAE:=SUM(AA,0),LINETHICK0;
SMFE:=SUM(BB,0),LINETHICK0;
RATIO:=ABS(SMAE/SMFE),LINETHICK0;
MAE/MFE比率:RATIO,NODRAW,COLORRED;
//TT:TOTALTRADE,LINETHICK0;
//SS:SUM(RATIO,0),LINETHICK0;
//ARATIO:SS/TT,LINETHICK0;
源码解析:
输出VARIABLE: MAE=0,MFE=0
输出 INPUT:DAYLONG(40,4,400,4)
输出//DAYLONG个周期后平仓 //简单模型 UP:40日内最高价的最高值
LONG赋值:昨日UP
逻辑判断 HOLDING<>0 THEN BEGIN 逻辑判断 ENTERBARS>=DAYLONG AND HOLDING>0 THEN SELL(1,1,THISCLOSE)
END ELSE THEN BEGIN 逻辑判断 H>=LONG AND HOLDING=0 THEN BUY(1,1,STOPR,LONG)
END //开始取MAE和MFE 逻辑判断 昨日HOLDING=0 THEN GOTO DONE
PP赋值:OPENPROFIT,线宽为0
输出 浮动盈亏:PP,线宽为0
MAE赋值:PP
MFE赋值:PP
AA赋值:IFELSE(EXITBARS=0,MAE,0),线宽为0
BB赋值:IFELSE(EXITBARS=0,MFE,0),线宽为0
输出 当笔交易MAE:AA,线宽为0
输出 当笔交易MFE:BB,线宽为0
MAE赋值:0
MFE赋值:0
SMAE赋值:AA的历史累和,线宽为0
SMFE赋值:BB的历史累和,线宽为0
RATIO赋值:SMAE/SMFE的绝对值,线宽为0
输出 MAE/MFE比率:RATIO,NODRAW,画红色
输出 //TT:TOTALTRADE,线宽为0
输出 //SS:RATIO的历史累和,线宽为0
输出 //ARATIO:SS/TT,线宽为0