{参数设置:N1:1,99,12 N2:1,99,26 N3:1,99,9}
DIFF:=(EMA(CLOSE,N1) - EMA(CLOSE,N2));
DEA:=EMA(DIFF,N3);
MACD2:=(2 * (DIFF - DEA));
DU0:=CROSS(DIFF,0);
UD0:=CROSS(0,DIFF);
TDU0:=BARSLAST(DU0);
TUD0:=BARSLAST(UD0);
DU3:=REF(DU0,1);
UD3:=REF(UD0,1);
TDU3:=BARSLAST(DU3);
TUD3:=BARSLAST(UD3);
UDGLINE:=IF((TDU3 < TUD3),REF(HHV(HIGH,2),TDU3),REF(LLV(LOW,2),TUD3));
JDU0:=(((REF(CLOSE,1) <= REF(UDGLINE,1)) AND (CLOSE > UDGLINE)) AND (TDU0 < TUD0));
JUD0:=(((REF(CLOSE,1) >= REF(UDGLINE,1)) AND (CLOSE < UDGLINE)) AND (TUD0 < TDU0));
JDU1:=(JDU0 AND (COUNT(JDU0,TDU0) = 1));
JUD1:=(JUD0 AND (COUNT(JUD0,TUD0) = 1));
JDU2:=(JDU1 AND (REF(BARSLAST(JUD1),1) < REF(BARSLAST(JDU1),1)));
JUD2:=(JUD1 AND (REF(BARSLAST(JUD1),1) > REF(BARSLAST(JDU1),1)));
JDU3:=(JDU1 AND (REF(BARSLAST(JUD1),1) > REF(BARSLAST(JDU1),1)));
JUD3:=(JUD1 AND (REF(BARSLAST(JUD1),1) < REF(BARSLAST(JDU1),1)));
BSLINE:=IF((BARSLAST(JDU2) < BARSLAST(JUD2)),IF(REF(CROSS(0,MACD2),1),LLV(LOW,2),REF(LLV(LOW,2),BARSLAST(REF(CROSS(0,MACD2),1)))),IF(REF(CROSS(MACD2,0),1),HHV(HIGH,2),REF(HHV(HIGH,2),BARSLAST(REF(CROSS(MACD2,0),1)))));
STICKLINE((MACD2>=0),0,MACD2,2,0),COLORFF00FF;
STICKLINE(((MACD2>=0) AND (MACD2 < REF(MACD2,1))),0,MACD2,2,1),COLORGREEN;
STICKLINE((MACD2<0),0,MACD2,2,0),COLORFFFF00;
STICKLINE(((MACD2<0) AND (MACD2 > REF(MACD2,1))),0,MACD2,2,0),COLORYELLOW;
DEFUT:=BARSLAST(CROSS(MACD2,0));
DEFDT:=BARSLAST(CROSS(0,MACD2));
DEFUL:=IF((MACD2 >= 0),HHV(MACD2,(DEFUT + 1)),REF(HHV(MACD2,(DEFUT + 1)),(DEFDT + 1)));
DEFDL:=IF((MACD2 < 0),LLV(MACD2,(DEFDT + 1)),REF(LLV(MACD2,(DEFDT + 1)),(DEFUT + 1)));
DEFU2L:=REF(DEFUL,(DEFUT + 1));
DEFD2L:=REF(DEFDL,(DEFDT + 1));
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
底背离:=REF(CLOSE,A1+1)>CLOSE AND DIFF>REF(DIFF,A1+1) AND CROSS(DIFF,DEA);
STICKLINE(底背离,0,0.03,4,0),COLOR00FF00;
DIF2:EMA(SUM(MACD2,2),3),LINETHICK2,COLORYELLOW;
入1:IF(DIF2>REF(DIF2,1),DIF2,DRAWNULL),COLORRED,LINETHICK2;
入2:IF(DIF2<REF(DIF2,1),DIF2,DRAWNULL),COLORGREEN,LINETHICK2;
DEA2:MA(DIF2,5),COLORCYAN;
DRAWICON(((((LLV(MACD2,4) > 0) AND (MACD2 < REF(MACD2,1))) AND (REF(MACD2,1) > REF(MACD2,2))) AND (REF(MACD2,2) > REF(MACD2,3))),MACD2,14);
DRAWICON(((((HHV(MACD2,4) < 0) AND (MACD2 > REF(MACD2,1))) AND (REF(MACD2,1) < REF(MACD2,2))) AND (REF(MACD2,2) < REF(MACD2,3))),MACD2,13);
这个是选股公式
N1:=12; N2:=26; N3:=9;
DIFF:=(EMA(CLOSE,N1) - EMA(CLOSE,N2));
DEA:=EMA(DIFF,N3);
MACD2:=(2 * (DIFF - DEA));
DU0:=CROSS(DIFF,0);
UD0:=CROSS(0,DIFF);
TDU0:=BARSLAST(DU0);
TUD0:=BARSLAST(UD0);
DU3:=REF(DU0,1);
UD3:=REF(UD0,1);
TDU3:=BARSLAST(DU3);
TUD3:=BARSLAST(UD3);
UDGLINE:=IF((TDU3 < TUD3),REF(HHV(HIGH,2),TDU3),REF(LLV(LOW,2),TUD3));
JDU0:=(((REF(CLOSE,1) <= REF(UDGLINE,1)) AND (CLOSE > UDGLINE)) AND (TDU0 < TUD0));
JUD0:=(((REF(CLOSE,1) >= REF(UDGLINE,1)) AND (CLOSE < UDGLINE)) AND (TUD0 < TDU0));
JDU1:=(JDU0 AND (COUNT(JDU0,TDU0) = 1));
JUD1:=(JUD0 AND (COUNT(JUD0,TUD0) = 1));
JDU2:=(JDU1 AND (REF(BARSLAST(JUD1),1) < REF(BARSLAST(JDU1),1)));
JUD2:=(JUD1 AND (REF(BARSLAST(JUD1),1) > REF(BARSLAST(JDU1),1)));
JDU3:=(JDU1 AND (REF(BARSLAST(JUD1),1) > REF(BARSLAST(JDU1),1)));
JUD3:=(JUD1 AND (REF(BARSLAST(JUD1),1) < REF(BARSLAST(JDU1),1)));
BSLINE:=IF((BARSLAST(JDU2) < BARSLAST(JUD2)),IF(REF(CROSS(0,MACD2),1),LLV(LOW,2)
,REF(LLV(LOW,2),BARSLAST(REF(CROSS(0,MACD2),1)))),
IF(REF(CROSS(MACD2,0),1),HHV(HIGH,2),REF(HHV(HIGH,2)
,BARSLAST(REF(CROSS(MACD2,0),1)))));
DEFUT:=BARSLAST(CROSS(MACD2,0));
DEFDT:=BARSLAST(CROSS(0,MACD2));
DEFUL:=IF((MACD2 >= 0),HHV(MACD2,(DEFUT + 1)),REF(HHV(MACD2,(DEFUT + 1)),(DEFDT + 1)));
DEFDL:=IF((MACD2 < 0),LLV(MACD2,(DEFDT + 1)),REF(LLV(MACD2,(DEFDT + 1)),(DEFUT + 1)));
DEFU2L:=REF(DEFUL,(DEFUT + 1));
DEFD2L:=REF(DEFDL,(DEFDT + 1));
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
底背离:=REF(CLOSE,A1+1)>CLOSE AND DIFF>REF(DIFF,A1+1) AND CROSS(DIFF,DEA);
DIF2:=EMA(SUM(MACD2,2),3),LINETHICK2,COLORYELLOW;
入1:=IF(DIF2>REF(DIF2,1),DIF2,DRAWNULL),COLORRED,LINETHICK2;
入2:=IF(DIF2<REF(DIF2,1),DIF2,DRAWNULL),COLORGREEN,LINETHICK2;
DEA2:=MA(DIF2,5),COLORCYAN;
{HQXG:((((LLV(MACD2,4) > 0) AND (MACD2 < REF(MACD2,1))) AND (REF(MACD2,1) > REF(MACD2,2))) AND (REF(MACD2,2) > REF(MACD2,3)));}
MCXG:((((HHV(MACD2,4) < 0) AND (MACD2 > REF(MACD2,1))) AND (REF(MACD2,1) < REF(MACD2,2))) AND (REF(MACD2,2) < REF(MACD2,3)));
上一个是MACD出红点时刻的选股公式
上一个是MACD出红点时刻的选股公式,下一个这个是MACD出现金叉的选股公式,源码来自网络 欢迎高手修改指正。
N1:=12; N2:=26; N3:=9;
DIFF:=(EMA(CLOSE,N1) - EMA(CLOSE,N2));
DEA:=EMA(DIFF,N3);
MACD2:=(2 * (DIFF - DEA));
DU0:=CROSS(DIFF,0);
UD0:=CROSS(0,DIFF);
TDU0:=BARSLAST(DU0);
TUD0:=BARSLAST(UD0);
DU3:=REF(DU0,1);
UD3:=REF(UD0,1);
TDU3:=BARSLAST(DU3);
TUD3:=BARSLAST(UD3);
UDGLINE:=IF((TDU3 < TUD3),REF(HHV(HIGH,2),TDU3),REF(LLV(LOW,2),TUD3));
JDU0:=(((REF(CLOSE,1) <= REF(UDGLINE,1)) AND (CLOSE > UDGLINE)) AND (TDU0 < TUD0));
JUD0:=(((REF(CLOSE,1) >= REF(UDGLINE,1)) AND (CLOSE < UDGLINE)) AND (TUD0 < TDU0));
JDU1:=(JDU0 AND (COUNT(JDU0,TDU0) = 1));
JUD1:=(JUD0 AND (COUNT(JUD0,TUD0) = 1));
JDU2:=(JDU1 AND (REF(BARSLAST(JUD1),1) < REF(BARSLAST(JDU1),1)));
JUD2:=(JUD1 AND (REF(BARSLAST(JUD1),1) > REF(BARSLAST(JDU1),1)));
JDU3:=(JDU1 AND (REF(BARSLAST(JUD1),1) > REF(BARSLAST(JDU1),1)));
JUD3:=(JUD1 AND (REF(BARSLAST(JUD1),1) < REF(BARSLAST(JDU1),1)));
BSLINE:=IF((BARSLAST(JDU2) < BARSLAST(JUD2)),IF(REF(CROSS(0,MACD2),1),LLV(LOW,2)
,REF(LLV(LOW,2),BARSLAST(REF(CROSS(0,MACD2),1)))),
IF(REF(CROSS(MACD2,0),1),HHV(HIGH,2),REF(HHV(HIGH,2)
,BARSLAST(REF(CROSS(MACD2,0),1)))));
DEFUT:=BARSLAST(CROSS(MACD2,0));
DEFDT:=BARSLAST(CROSS(0,MACD2));
DEFUL:=IF((MACD2 >= 0),HHV(MACD2,(DEFUT + 1)),REF(HHV(MACD2,(DEFUT + 1)),(DEFDT + 1)));
DEFDL:=IF((MACD2 < 0),LLV(MACD2,(DEFDT + 1)),REF(LLV(MACD2,(DEFDT + 1)),(DEFUT + 1)));
DEFU2L:=REF(DEFUL,(DEFUT + 1));
DEFD2L:=REF(DEFDL,(DEFDT + 1));
A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
底背离:=REF(CLOSE,A1+1)>CLOSE AND DIFF>REF(DIFF,A1+1) AND CROSS(DIFF,DEA);
DIF2:=EMA(SUM(MACD2,2),3),LINETHICK2,COLORYELLOW;
入1:=IF(DIF2>REF(DIF2,1),DIF2,DRAWNULL),COLORRED,LINETHICK2;
入2:=IF(DIF2<REF(DIF2,1),DIF2,DRAWNULL),COLORGREEN,LINETHICK2;
DEA2:=MA(DIF2,5),COLORCYAN;
CROSS(入1, DEA2);
N1赋值:12
N2赋值:26
N3赋值:9
DIFF赋值:(收盘价的N1日指数移动平均 - 收盘价的N2日指数移动平均)
DEA赋值:DIFF的N3日指数移动平均
MACD2赋值:(2 * (DIFF - DEA))
DU0赋值:DIFF上穿0
UD0赋值:0上穿DIFF
TDU0赋值:上次DU0距今天数
TUD0赋值:上次UD0距今天数
DU3赋值:1日前的DU0
UD3赋值:1日前的UD0
TDU3赋值:上次DU3距今天数
TUD3赋值:上次UD3距今天数
UDGLINE赋值:如果(TDU3<TUD3),返回TDU3日前的2日内最高价的最高值,否则返回TUD3日前的2日内最低价的最低值
JDU0赋值:(((1日前的收盘价 <= 1日前的UDGLINE) AND (收盘价 > UDGLINE)) AND (TDU0 < TUD0))
JUD0赋值:(((1日前的收盘价 >= 1日前的UDGLINE) AND (收盘价 < UDGLINE)) AND (TUD0 < TDU0))
JDU1赋值:(JDU0 AND (统计TDU0日中满足JDU0的天数 = 1))
JUD1赋值:(JUD0 AND (统计TUD0日中满足JUD0的天数 = 1))
JDU2赋值:(JDU1 AND (1日前的上次JUD1距今天数 < 1日前的上次JDU1距今天数))
JUD2赋值:(JUD1 AND (1日前的上次JUD1距今天数 > 1日前的上次JDU1距今天数))
JDU3赋值:(JDU1 AND (1日前的上次JUD1距今天数 > 1日前的上次JDU1距今天数))
JUD3赋值:(JUD1 AND (1日前的上次JUD1距今天数 < 1日前的上次JDU1距今天数))
BSLINE赋值:如果(上次JDU2距今天数<上次JUD2距今天数),返回如果1日前的0上穿MACD2,返回2日内最低价的最低值,否则返回上次1日前的0上穿MACD2距今天数日前的2日内最低价的最低值,否则返回如果1日前的MACD2上穿0,返回2日内最高价的最高值,否则返回上次1日前的MACD2上穿0距今天数日前的2日内最高价的最高值
DEFUT赋值:上次MACD2上穿0距今天数
DEFDT赋值:上次0上穿MACD2距今天数
DEFUL赋值:如果(MACD2>=0),返回(DEFUT+1)日内MACD2的最高值,否则返回(DEFDT+1)日前的(DEFUT+1)日内MACD2的最高值
DEFDL赋值:如果(MACD2<0),返回(DEFDT+1)日内MACD2的最低值,否则返回(DEFUT+1)日前的(DEFDT+1)日内MACD2的最低值
DEFU2L赋值:(DEFUT+1)日前的DEFUL
DEFD2L赋值:(DEFDT+1)日前的DEFDL
A1赋值:上次1日前的DIFF上穿DEA距今天数
底背离赋值:A1+1日前的收盘价>收盘价 AND DIFF>A1+1日前的DIFF AND DIFF上穿DEA
DIF2赋值:MACD2的2日累和的3日指数移动平均,线宽为2,画黄色
入1赋值:如果DIF2>1日前的DIF2,返回DIF2,否则返回无效数,画红色,线宽为2
入2赋值:如果DIF2<1日前的DIF2,返回DIF2,否则返回无效数,画绿色,线宽为2
DEA2赋值:DIF2的5日简单移动平均,画青色
入1上穿DEA2
通达信MACD红点时刻的选股 通达信注解
N1赋值:12
N2赋值:26
N3赋值:9
DIFF赋值:(收盘价的N1日指数移动平均 - 收盘价的N2日指数移动平均)
DEA赋值:DIFF的N3日指数移动平均
MACD2赋值:(2 * (DIFF - DEA))
DU0赋值:DIFF上穿0
UD0赋值:0上穿DIFF
TDU0赋值:上次DU0距今天数
TUD0赋值:上次UD0距今天数
DU3赋值:1日前的DU0
UD3赋值:1日前的UD0
TDU3赋值:上次DU3距今天数
TUD3赋值:上次UD3距今天数
UDGLINE赋值:如果(TDU3<TUD3),返回TDU3日前的2日内最高价的最高值,否则返回TUD3日前的2日内最低价的最低值
JDU0赋值:(((1日前的收盘价 <= 1日前的UDGLINE) AND (收盘价 > UDGLINE)) AND (TDU0 < TUD0))
JUD0赋值:(((1日前的收盘价 >= 1日前的UDGLINE) AND (收盘价 < UDGLINE)) AND (TUD0 < TDU0))
JDU1赋值:(JDU0 AND (统计TDU0日中满足JDU0的天数 = 1))
JUD1赋值:(JUD0 AND (统计TUD0日中满足JUD0的天数 = 1))
JDU2赋值:(JDU1 AND (1日前的上次JUD1距今天数 < 1日前的上次JDU1距今天数))
JUD2赋值:(JUD1 AND (1日前的上次JUD1距今天数 > 1日前的上次JDU1距今天数))
JDU3赋值:(JDU1 AND (1日前的上次JUD1距今天数 > 1日前的上次JDU1距今天数))
JUD3赋值:(JUD1 AND (1日前的上次JUD1距今天数 < 1日前的上次JDU1距今天数))
BSLINE赋值:如果(上次JDU2距今天数<上次JUD2距今天数),返回如果1日前的0上穿MACD2,返回2日内最低价的最低值,否则返回上次1日前的0上穿MACD2距今天数日前的2日内最低价的最低值,否则返回如果1日前的MACD2上穿0,返回2日内最高价的最高值,否则返回上次1日前的MACD2上穿0距今天数日前的2日内最高价的最高值
DEFUT赋值:上次MACD2上穿0距今天数
DEFDT赋值:上次0上穿MACD2距今天数
DEFUL赋值:如果(MACD2>=0),返回(DEFUT+1)日内MACD2的最高值,否则返回(DEFDT+1)日前的(DEFUT+1)日内MACD2的最高值
DEFDL赋值:如果(MACD2<0),返回(DEFDT+1)日内MACD2的最低值,否则返回(DEFUT+1)日前的(DEFDT+1)日内MACD2的最低值
DEFU2L赋值:(DEFUT+1)日前的DEFUL
DEFD2L赋值:(DEFDT+1)日前的DEFDL
A1赋值:上次1日前的DIFF上穿DEA距今天数
底背离赋值:A1+1日前的收盘价>收盘价 AND DIFF>A1+1日前的DIFF AND DIFF上穿DEA
DIF2赋值:MACD2的2日累和的3日指数移动平均,线宽为2,画黄色
入1赋值:如果DIF2>1日前的DIF2,返回DIF2,否则返回无效数,画红色,线宽为2
入2赋值:如果DIF2<1日前的DIF2,返回DIF2,否则返回无效数,画绿色,线宽为2
DEA2赋值:DIF2的5日简单移动平均,画青色
输出MCXG:((((4日内MACD2的最高值 < 0) AND (MACD2 > 1日前的MACD2)) AND (1日前的MACD2 < 2日前的MACD2)) AND (2日前的MACD2 < 3日前的MACD2))