N:=12;M:=26;
BG:=BARSCOUNT(OPEN)+1;
T:=BG<=2;
MIDR:=SQRT(N*M);
DIF:=((EMA(C,N)-EMA(C,M))/EMA(C,MIDR));{不取绝对值式,推荐}
JD:=MIDR*EMA(1+DIF,MIDR);
{DIF:=Abs((EMA(C,N)-EMA(C,M))/EMA(C,MIDR))*8;};{取绝对值式}
{JD:=MIDR*EMA(1/2+DIF,MIDR);}
Q:=IF(BG<=JD,BG,JD);
MA_S:=EMA(C,Q);
CQ:=LN(ABS(C)+1);{取绝对值及加1都为防“负”}
SD:=SQRT(EMA((C-MA_S)*(C-MA_S)*CQ/MA(CQ,Q),Q));
顶线:IF(T,H*1.03,MA_S+2*SD);
强线:IF(T,(3*H+L)/4,MA_S+SD);
中线:MA_S,LINETHICK1;
弱线:IF(T,(3*L+H)/4,MA_S-SD);
底线:IF(T,L*0.98,MA_S-2*SD);
;动态周期:Q,NODRAW;
{- }
{CQ1=C*C;二阶原点矩做“权”用}
{CQ2:=ABS(C);一阶原点矩做“权”用}
{CQ3:=LONG(ABS(C)+10);对数矩做“权”用(近似原点矩),比较适合股市,LN函数最好}
{SD1:=SQRT(MA((C-MA_S)*(C-MA_S)*CQ/MA(CQ,Q),Q));}
{SD3:=SQRT(SUM((C-MA_S)*(C-MA_S)*CQ/SUM(CQ,Q),Q));}
{SD4:=SQRT(EMA((C-MA(C,Q))*(C-MA(C,Q))*CQ/MA(CQ,Q),Q));股市用标准式}
{SD5:=SQRT(SMA((C-MA(C,Q))*(C-MA(C,Q))*CQ/MA(CQ,Q),Q,2));}
{SD6:=SQRT(expma((C-MA(C,Q))*(C-MA(C,Q))*CQ/MA(CQ,Q),Q));}
{注2:EXPMA()、MEMA()等指数平滑函数对“变周期”有限制}
{注3:非标运用时,均方差的变量不一定用 C,也可用 (H+L)/2;(C+H+L)/3,等等}