大智慧公式教程——逻辑函数与统计函数的应用1、IF条件函数根据条件求不同的值。用法:IF(X,A,B)若X不为0则返回A,否则返回B。例如:IF(CLOSEOPEN,HIGH,LOW),表示该周期收阳则返回最高值,否则返回最低值。2、CROSS交叉函数CROSS(A,B)A:变量或常量,判断交叉的第一条线。B:变量或常量,判断交叉的第二条线。例如:CROSS(MA(CLOSE,5),MA(CLOSE,10)),5日均线与10日均线金叉;CROSS(CLOSE,12),价格由下向上突破12元。上面这两个函数我们在前面已经讲过,在此就不做介绍了。讲一讲下面几个逻辑函数。这几个逻辑函数比较好理解,用法简单,只是用的很少。3、ISDOWN当日下跌该周期是否收阴。用法:ISDOWN当收盘开盘时,返回值为1,否则为0。4、ISEQUAL当日平盘该周期是否平盘。用法:ISEQUAL当收盘=开盘时,返回值为1,否则为0。5、ISUP该周期是否收阳。用法:ISUP当收盘开盘时,返回值为1,否则为0。请看指标:Var1:=EMA(CLOSE,3);Var2:=EMA(CLOSE,21);Var3:=BARSLAST(CROSS(Var2,Var1))15;Var4:=VOLMA(VOL,5)*2ANDVOLMA(VOL,5)*5;Var5:=CROSS(Var1,Var2)ANDISUPANDVar4ANDVar3;{交叉(var1,var2)并且当日上涨并且VAR4并且VAR3}:if(Var5,80,0),stick,linethick4,colorf00ff0;drawtext(Var5,70,’!’),colorf00ff0;6、NOT求逻辑非NOT(X)求逻辑非,返回非X,即当X=0时返回1,否则返回0。例如:NOT(ISUP),是否平盘或收阴。请看指标:XX2:=(MA(CLOSE,80)-MA(CLOSE,13)/3);神奇线:MA((CLOSE-XX2)/XX2,1);买点1:IF(CROSS(神奇线,0)ANDLOW/REF(HIGH,1)1.012,0.5,0),STICK,COLORWHITE;稳赚:IF(COUNT(神奇线REF(神奇线,1),3)=3ANDCOUNT(神奇线0,10)=10ANDREF(神奇线,3)=LLV(神奇线,10),0.5,0);买点2:IF(REF(神奇线,2)=LLV(神奇线,20)ANDREF(神奇线,2)0.071ANDREF(神奇线,2)REF(神奇线,1)ANDNOT(REF(LOW,1)REF(HIGH,2)ANDLOWREF(HIGH,1))ANDCLOSEREF(CLOSE,1),0.5,0),COLORRED;{这段语句NOT(REF(LOW,1)REF(HIGH,2)的意思,是否昨天最低价大于前天最高价,这几个条件都满足显示脉冲信号,否则不显示}DRAWTEXT(买点10,0.2,’★神奇线’),COLORWHITE;DRAWTEXT(买点20,0.4,’★神奇线’),COLORRED;大智慧统计函数(1)、AVEDEV平均绝对偏差用法:AVEDEV(X,N)含义:平均绝对偏差,求X的N日平均绝对偏差。请看指标:TYP:=(HIGH+LOW+CLOSE)/(3);{最高+最底+收盘价/3}趋势线:(TYP-MA(TYP,100))/((0.015)*(AVEDEV(TYP,100))),Color00FFFF;{(AVEDEV(TYP,100)求TYP的100日平均绝对偏差.}(2)、DEVSQ数据偏差平方和用法:DEVSQ(X,N)含义:数据偏差平方和,求X的N日数据偏差平方和。数据偏差平方和除以N,即为方差。比较一下这2句在图上的区别:a1:DEVSQ(C,5)/5;{0.025}a2:DEVSQ(C,5);{0.126}(3)、FORCAST线性回归预测值用法:FORCAST(X,N)为X的N周期线性回归预测值。示例:FORCAST(CLOSE,10)表示求10周期线性回归预测。用最小二乘法求出N周期内X的一元线性回归线上的当天的值。请看指标:平均价:=(HIGH+4*LOW+OPEN+CLOSE)/7;均价差:=EMA(平均价,13)-EMA(平均价,34);移动均价:=EMA(均价差,5);差:=(均价差-移动均价)*5;A:=IF(差=1000,1000,IF(差=平均价,平均价,差));分水岭:=forcast(forcast(A,31),10),linethick3,COLORYELLOW;{求出31日内A的线性回归预测和10日线性回归预测}上涨:if(A分水岭,A,分水岭),LINETHICK2,colorred;下跌:if(A分水岭,A,分水岭),LINETHICK2,COLORGREEN;分水岭1:forcast(forcast(A,31),10),linethick2,COLORYELLOW;{求出31日内A的线性回归预测和10日线性回归预测}(4)、SLOPE线性回归斜率用法:SLOPE(X,N)为X的N周期线性回归线的斜率。例如:SLOPE(CLOSE,10)表示求10周期线性回归线的斜率。请看指标:XLB:forcast(V,8)/EMA(forcast(V,36),7);{forcast(V,8)求8周期线性回归预测}XLL:if(slope(XLB,2)0,slope(XLB,2)*XLB,0),linethick2;{slope(XLB,2)求2周期线性回归线的斜率}drawicon(XLL0.8,0,11);drawicon(XLL=0.8,0,10);{排序,用于抓住量比放大,正在快速上涨的股。}(5)、STD估算标准差用法:STD(X,N)为X的N日估算标准差。例如:STD(CLOSE,10),求10周期收盘价的估算标准差。请看指标:var1:=ema((high+low+close)/3,3);重心:var1,colorwhite;varb:=amount/(100*vol);varc:=ma(varb,34);vard:=ma(close,26);通道:(vard+varc)/2,coloryellow;压力l:vard+2*std(close,49),colorred;{求49周期收盘价的估算标准差}支持l:(vard-2*std(close,26)),colorgreen;{求26周期收盘价的估算标准差}通道*1.062,colorff00ff;通道*0.938,colorff00ff;vare:=ma(winner(close),5)*100;顶:drawtext(vare60andhigh压力l,high,’卖’),color00ff00;底:drawtext(vare15andcross(var1,通道),low,’买’),colorwhite;(6)、STDP总体标准差用法:STDP(X,N)为X的N日总体标准差。例如:STDP(CLOSE,10),求10周期收盘价的总体标准差。请看指标:VAR1:=AMOUNT/VOL/100;VAR2:=(3*HIGH+LOW+OPEN+2*CLOSE)/7;VAR3:=SUM(AMOUNT,34)/VAR1/100;VAR4:=DMA(VAR2,VOL/VAR3);VAR5:=100*(C-VAR4)/VAR4;次强上轨:(MA(VAR5,20)+STDP(VAR5,20)),COLORRED;{STDP(VAR5,20)求20周期var5的总体标准差}次强下轨:(MA(VAR5,20)-STDP(VAR5,20)),COLORRED;{STDP(VAR5,20)求20周期var5的总体标准差}强弱线:(次强上轨+次强下轨)/2,POINTDOT,COLORYELLOW;强势区上轨:(MA(VAR5,20)+1.7*STDP(VAR5,20)),COLOR10FFFF;{STDP(VAR5,20)求20周期var5的总体标准差}强势区下轨:(MA(VAR5,20)-1.7*STDP(VAR5,20)),COLOR10FFFF;{STDP(VAR5,20)求20周期var5的总体标准差}标准线:VAR5,COLORWHITE;下面这2个函数用的比较少,略做简单介绍:(7)、VAR估算样本方差用法:VAR(X,N)为X的N日估算样本差。(8)、VARP总体样本方差用法:VARP(X,N)为X的N日总体样本方差。{牛熊先知}VAR1:=EMA(EMA(EMA(CLOSE,5),2),1);牛熊先知:(VAR1-REF(VAR1,1))/REF(VAR1,1)*1,COLORRED,COLORSTICK;牛熊神经:EMA(牛熊先知,13),COLORYELLOW;牛熊界线:0,COLORFF00FF;VAR2:=AMOUNT/VOL/100;VAR3:=MAX(ABS(HIGH-VAR2),ABS(VAR2-LOW));VAR4:=ABS((OPEN+CLOSE)/2-VAR2);VAR5:=5;VAR6:=(VAR3+VAR4)/VAR2*50;牛熊变换:IF(CROSS(VAR6,VAR5),0.008,0),COLORFFCC66;下面是一个飞狐的组合指标:Var2:=(H+L+O+2*C)/5;{与下面赋值VAR2重名}CHH低吸线:EMA(SLOPE(Var2,21)*20+Var2,55),circledot;DrawIcon(Ref(C,1)CHH低吸线andCCHH低吸线,0.98*L,1);DrawIcon(Ref(C,1)CHH低吸线andCCHH低吸线,1.02*H,2);bb:=llV(H,1);神顶抄底逃顶线:FORCAST(FORCAST(bb,15),15),COLORyellow,LINETHICK2;神顶逃顶抄底线:FORCAST(FORCAST(bb,25),25),COLORred,LINETHICK2;If(Slope(神顶抄底逃顶线,2)0,CHH低吸线,C),circledot,ColorMagenta;C,circledot,ColorBlack;{K线}Var2:=(C*2+H+L)/4;{与上面赋值VAR2重名}Var3:=EMA(Var2,3);Var4:=EMA(Var3,6);L1:=EMA(Var2,3);L2:=EMA(Var3,4);L3:=EMA(Var4,5);Var5:=REF(L1,1)L1ANDL1L2;STICKLINE(L1=L2,H,L,1,0),COLORRED;STICKLINE(L1L2,H,L,1,0),COLORGREEN;STICKLINE(L1=L2,C,O,6,0),COLORRED;STICKLINE(L1L2,C,O,6,0),COLORGREEN;STICKLINE(Var5,H,L,1,0)COLORYellow;{缺少逗号}STICKLINE(Var5,C,O,6,0)COLORYellow;{缺少逗号}第五步:我们看到最后2条语句与颜色代码之间没有逗号,在编辑器里画黑线处见图:好,再把这两句再加上逗号,点测试通过,到此指标修改结束。下面是修改后的指标(可做主副图):Var2:=(H+L+O+2*C)/5;CHH低吸线:EMA(SLOPE(Var2,21)*20+Var2,55),circledot;DrawIcon(Ref(C,1)CHH低吸线andCCHH低吸线,0.98*L,1);DrawIcon(Ref(C,1)CHH低吸线andCCHH低吸线,1.02*H,2);bb:=llV(H,1);神顶抄底逃顶线:FORCAST(FORCAST(bb,15),15),COLORyellow,LINETHICK2;神顶逃顶抄底线:FORCAST(FORCAST(bb,25),25),CO