第八讲:函数的综合运用
第一部分:引用已有公式中的数据
基本引用例一
"macd. diff", "macd.dea";
基本格式: 指标名称 语句名称 (注意:必须用双引号引上)
加入参数例二
"kdj. k" (9,3,3) ;
基本格式:指标名称 语句名称 参数 (指标名称和语句名称之间用隔点.隔开)
加入参数例三
周m:"macd. diff #WEEK";
引用周线:指标名称 语句名称 周函数 (注意:周函数前加#字号)
月K:"kdj.k#MONTH";
引用月线同上,只是换成月函数。
-
应用实例:主图 顶底背离
A1:=BARSLAST(ref(cross("macd.diff"(12,26,9),"macd.dea"(12,26,9)),1));
B1:=ref(c,A1+1)>c and ref("macd.diff"(12,26,9),A1+1)<"macd.diff"(12,26,9) and cross("macd.diff"(12,26,9),"macd.dea"(12,26,9));
MACD底背离:STICKLINE(FILTER(B1>0,5),0,0.75,3,0),COLOR00FF00;
DRAWTEXT(FILTER(B1>0,5),0.57,'MACD底背离'),COLOR00FF00;
A2:=BARSLAST(ref(cross("kdj.k"(9,3,3),"kdj.d"(9,3,3)),1));
B2:=ref(c,A2+1)>c and ref("kdj.k"(9,3,3),A2+1)<"kdj.k"(9,3,3) and cross("kdj.k"(9,3,3),"kdj.d"(9,3,3));
KDJ底背离:STICKLINE(FILTER(B2>0,5),0,1,3,0),COLORYELLOW;
DRAWTEXT(FILTER(B2>0,5),0.80,'KDJ底背离'),COLORYELLOW;
A3:=BARSLAST(ref(cross("RSI.RSI1"(6,12,24),"RSI.RSI2"(6,12,24)),1));
B3:=ref(c,A3+1)>c and ref("RSI.RSI1"(6,12,24),A3+1)<"RSI.RSI1"(6,12,24) and cross("RSI.RSI1"(6,12,24),"RSI.RSI2"(6,12,24));
RSI底背离:STICKLINE(FILTER(B3>0,5),0,0.5,3,0),COLORFFCC66;
DRAWTEXT(FILTER(B3>0,5),0.25,'RSI底背离'),COLORFFCC66;
DRAWTEXT(FILTER(D1>0,5),1.47,'MACD顶背离'),COLOR0066FF;
C2:=BARSLAST(ref(cross("kdj.d"(9,3,3),"kdj.k"(9,3,3)),1));
D2:=ref(c,C2+1)"kdj.k"(9,3,3) and cross("kdj.d"(9,3,3),"kdj.k"(9,3,3));
KDJ顶背离:STICKLINE(FILTER(D2>0,5),2,1,3,0),COLORRED;
DRAWTEXT(FILTER(D2>0,5),1.2,'KDJ顶背离'),COLORRED;
C3:=BARSLAST(ref(cross("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24)),1));
D3:=ref(c,C3+1)"RSI.RSI1"(6,12,24) and cross("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24));
RSI顶背离:STICKLINE(FILTER(D3>0,5),2,1.5,3,0),COLORFF00FF;
DRAWTEXT(FILTER(D3>0,5),1.75,'RSI顶背离'),COLORFF00FF;
第二部分 逐步增加函数