MACD顶底背离通达信指标公式源码
自动画MACD背离线通达信指标公式源码
自动画MACD背离的指标:一共两个指标,一个是通达信用的,一个是大智慧用的{通达信自动划MACD指标背离线}DIFF:EMA(CLOSE,12) - EMA(CLOSE,26);DEA:EMA(DIFF,9);MACD:2*(DIFF-DEA), COLORSTICK;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.1,8,0),COLORRED;DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,LINETHICK2;A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF); DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,LINETHICK2;{大智慧自动划MACD指标背离线(适用于大智慧新一代)}DIF:EMA(CLOSE,12)-EMA(CLOSE,26);DEA:EMA(DIF,9);MACD:(DIF-DEA)*2,COLORSTICK;A:=SUMBARS(CROSS(DEA,DIF),2);B:=SUMBARS(CROSS(DEA,DIF),1);E:=REF(DIF,LLVBARS(DIF,A))<REF(DIF,LLVBARS(DIF,B)) AND LLVBARS(DIF,B)<LLVBARS(DIF,A) ANDCROSS(DIF,DEA);F:=COUNT(BACKSET(E,LLVBARS(DIF,A)+1),LLVBARS(DIF,A)+1)=1; G:=COUNT(BACKSET(E,LLVBARS(DIF,B)+1),LLVBARS(DIF,B)+1)=1; DRAWLINE(F,DIF,G,DIF,0),COLOERED;。
MACD顶底背离通达信指标公式源码
MACD顶底背离通达信指标公式源码/*头文件引用*/#include "stdafx.h"#include "SetIndexData.h"/*背离判断函数*/BOOL BackwardJudge(int n, float *dd, float *top, float *bottom)int i, t_pos = 0;float maxval = 0, minval = 0;for(i=0;i<n;i++)if(maxval < dd[i])maxval = dd[i];t_pos = i;}}maxval = dd[t_pos];minval = dd[t_pos];for(i=t_pos;i>=0;i--)if(maxval < dd[i])maxval = dd[i];if(minval > dd[i])minval = dd[i];}*top = maxval;*bottom = minval;if(maxval == dd[0])return TRUE;else if(minval == dd[0])return FALSE;elsereturn FALSE;/*MACD顶底背离判断函数*/Export int MACDBackward(int n)int i;float *DIFF, *DEA, *MACD, *dd;float top = 0, bottom = 0;BOOL bType = FALSE;SetEmptyBarCount(FALSE); /*不跳过空记录*/DIFF = GetDiff(;DEA = GetDea(;MACD = GetMacd(;malloc(dd, sizeof(float)*n);bType = BackwardJudge(n, DEA, &top, &bottom);if(bType)for(i=0;i<n;i++)dd[i] = DIFF[i];bType = BackwardJudge(n, dd, &top, &bottom);if(bType)return 1; /*底背离*/elsereturn 2; /*顶背离*/}elsereturn 0; /*无背离*/上述代码是通达信公式语言的源码。
通达信指标公式源码好厉害的MACD背离(通达信副图指标)
好厉害的MACD背离(通达信副图指标)DIF:EMA(CLOSE,12)-EMA(CLOSE,26),COLORRED,LINETHICK2;DEA:EMA(DIF,9),COLORWHITE,LINETHICK2;持仓段:=0,COLOR00CFFF;空仓段:=0,COLORFFCCFF;STICKLINE(DIF>DEA,-0.5,-0.6,10,1),COLOR00CFFF;STICKLINE(DIF<DEA,-0.5,-0.6,10,1),COLORFFCCFF;MACD:(DIF-DEA)*2,COLORSTICK;STICKLINE(((MACD<REF(MACD,1)) AND(MACD>0)),0,MACD,1,0),COLORLIBLUE,LINETHICK2;STICKLINE(((MACD>REF(MACD,1)) AND(MACD<0)),0,MACD,1,0),COLORFF00FF,LINETHICK2;建仓:IF(DIF<0,DIF,0),COLORYELLOW,LINETHICK2;加仓:IF(DIF<0,0,DIF),COLORRED,LINETHICK2;白线破仓:IF(DIF<DEA,DIF,DEA),COLORWHITE,LINETHICK2;趋势强弱:IF(DIF>DEA,DEA,DEA),COLORFF937F,LINETHICK2;AA:=COUNT(CROSS(DIF,DEA),BARSLAST(DEA>=0));二次金叉:=CROSS(DIF,DEA) AND DEA<0 AND COUNT(AA=2,21)=1; DRAWTEXT(二次金叉,0.2,' 二次金叉'),COLORYELLOW;A1:=BARSLAST(REF(CROSS(DIF,DEA),1));底背离:=REF(CLOSE,A1+1)>CLOSE AND DIF>REF(DIF,A1+1) AND CROSS(DIF,DEA); STICKLINE(底背离,0,0.03,6,0),COLOR00FF00;底背:DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,LINETHICK4; DRAWTEXT(底背离,0.12,' 底背离'),COLORFF00FF;A2:=BARSLAST(REF(CROSS(DEA,DIF),1));顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIF,A2+1)>DIF AND CROSS(DEA,DIF); 顶背:DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,LINETHICK4;。
【通达信】极品变色MACD(低位金叉、底背离、顶背离)-指标公式
【通达信】极品变色MACD(低位金叉、底背离、顶背离)-指标公式DIFF:EMA(CLOSE,12)-EMA(CLOSE,27);DEA:EMA(DIFF,9);MACD:=2*(DIFF-DEA);STICKLINE(MACD>=0,MACD,0,2,1),COLORF00FF0;STICKLINE(MACD<0,MACD,0,2,1),COLORWHITE;STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00AAFF; STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00BBFF; STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00CCFF; STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00DDFF; STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00EEFF; STICKLINE(MACD<REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR00FFFF; STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0000AA; STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0011BB; STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0022CC; STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0033DD; STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0044EE; STICKLINE(MACD>=REF(MACD,1)AND MACD>0,0,MACD,2,0 ),COLOR0055FF; STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORAA00BB; STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORBB11BB; STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORCC22BB; STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORDD33BB; STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLOREE44BB; STICKLINE(MACD>REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFF55BB; STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFAA00; STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFBB11; STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFCC22; STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFDD33; STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFEE44; STICKLINE(MACD<=REF(MACD,1)AND MACD<0,0,MACD,2,0 ),COLORFFFF55; IF(DIFF<0,DIFF,0),COLORRED,LINETHICK1;IF(DIFF<0,0,DIFF),COLORYELLOW,LINETHICK1;IF(DIFF<DEA,DIFF,DEA),COLOR00FF00,LINETHICK1;IF(DIFF>DEA,DEA,DEA),COLORWHITE,LINETHICK1;低位金叉:=CROSS(DIFF,DEA) AND DIFF<-0.1;STICKLINE(低位金叉,0,-0.18,2,0),COLORYELLOW;DRAWTEXT(低位金叉,-0.1,' 低位金叉'),COLORYELLOW;JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));二次金叉:=CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1; STICKLINE(二次金叉,0,-0.18,2,0),COLORFF00FF;DRAWICON(二次金叉,DEA*1.04,13) ;DRAWTEXT(二次金叉,-0.1,' 二次金叉'),COLORFF00FF;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.13,2,0),COLOR00FF00;DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,LINETHICK2; DRAWTEXT(底背离,0.1,' 底背离'),COLOR00FF00;A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF);DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,LINETHICK2;。
MACD顶底背离通达信指标公式源码
MACD顶底背离通达信指标公式源码```text/*MACD顶底背离指标*//*输入参数说明:bsPeriod: 顶底背离周期,默认为9macdFastPeriod: MACD快线周期,默认为12macdSlowPeriod: MACD慢线周期,默认为26macdSignalPeriod: MACD信号线周期,默认为9*/_VAR1:=BSPeriod;_VAR2:=MACDSPERIOD;_VAR3:=MACDPERIOD;_VAR4:=MACDFPARRAY[1];_VAR5:=CLOSE>REF(HHV(HIGH,_VAR2),1);_VAR6:=CLOSE<REF(LLV(LOW,_VAR2),1);_VAR7:=HHV(HIGH,_VAR3)<HHV(HIGH,_VAR3+1)&&REF(HHV(HIGH,_VAR3 +1),1)<REF(HHV(HIGH,HHV(_VAR3,_VAR3)),-1);_VAR8:=LLV(LOW,_VAR3)>LLV(LOW,_VAR3+1)&&REF(LLV(LOW,_VAR3+1) ,1)>REF(LLV(LOW,LLV(_VAR3,_VAR3)),-1);_VAR9:=IF(_VAR4<0,(_VAR4-CLOSE),IF(_VAR4>0,(_VAR4+CLOSE),CLOSE));_VAR10:=REF(_VAR9,1);_TR:=IF(_VAR5,_VAR1,IF(_VAR6,-_VAR1,0));_IF9:=IF(_VAR7,_VAR9,IF(_VAR8,-_VAR9,0));VAR11:=IF(_TR>BARSCOUNT,_TR,IF(_TR<BARSCOUNT,-_TR,0));_VAR12:=ABS(_IF9);_VAR13:=IF(_VAR12>BARSCOUNT,0,_VAR12);VAR14:EMA(IF(_TR>0,_TR,IF(_TR<0,ABS(_TR),0)),_VAR1*2-1);VAR15:EMA(_IF9,_VAR1*2-1);VAR16:EMA(VAR14,2);VAR17:EMA(VAR15,2);SWING:IF((_TR>VAR14&&VAR14>VAR16),(_TR<VAR14&&VAR14<VAR16),VAR14,IF((_TR<_IF9&&_IF9<VAR15),(_TR>_IF9&&_IF9>VAR15),_IF9,0));DVB:IF(VAR14<1,VAR15,0);DVS:IF(VAR14>1,VAR15,0);DVFH:IF(VAR15>VAR17&&VAR15!=MAX,VAR15,0);DVFL:IF(VAR15<VAR17&&VAR15!=MIN,VAR15,0);DVFHB:=IF(VAR15>VAR17&&VAR15>REF(VAR15,1),VAR15,0);DVFHS:=IF(VAR15>VAR17&&VAR15<REF(VAR15,1),VAR15,0);DVFLB:=IF(VAR15<VAR17&&VAR15<REF(VAR15,1),VAR15,0);DVFHS:CCOLOR==VOLUME?COLORBLUE:IF(CC:,COLORFF0000,0);DVFHB:DVFLB:CCOLOR==VOLUME?COLORBLUE:IF(CC:,COLOR00AAFF,0);FORMULA:=0;```以上是通达信公式语言的源码,用于计算MACD顶底背离指标。
MACD背离自动画线通达信指标公式源码
MACD背离自动画线通达信指标公式源码MACD(Moving Average Convergence Divergence)是一种常用的股票技术指标,用于分析股票的趋势和交易信号。
MACD背离是一种常见的技术分析方法,用于判断趋势的反转点,即价格走势与MACD指标走势不一致的情况。
下面是使用通达信编写MACD背离自动画线指标的源码。
```c/*MACD背离自动画线指标*功能:自动识别MACD背离点并在图表中标注出来*/#include "stdafx.h"#include "stdio.h"#include "string.h"#include "windows.h"//确定最低点、最高点时使用的价格周期数#define MIN_PRICE_DURATION 9#define MAX_PRICE_DURATION 10/**输入参数:*MACD:一个包含MACD数据的数组* price:一个包含价格数据的数组*返回值:*0:没有背离*1:向上背离*-1:向下背离*/int CheckDivergence(float *MACD, float *price) int i, j, k;int start, end;int low_index, high_index;float min_price, max_price;int MACD_bottom, MACD_top;int price_bottom, price_top;float MACD_bottom_value, MACD_top_value;float price_bottom_value, price_top_value;/**阶段1:寻找MACD底背离*/start = MAX_PRICE_DURATION + 1;end = start + MIN_PRICE_DURATION;low_index = -1;high_index = -1;min_price = price[start];max_price = price[start];for (i = start; i < end; i++)//查找最低点if (price[i] < min_price)low_index = i;min_price = price[i];}//查找最高点if (price[i] > max_price)high_index = i;max_price = price[i];}}//无法找到底背离点if (low_index == -1 , high_index == -1)}MACD_bottom = 0;price_bottom = 0;//寻找MACD底背离for (i = start; i < end; i++)if (i == low_index)//找到最低点对应的MACD数值MACD_bottom = i;MACD_bottom_value = MACD[i];}if (i == high_index)//找到最高点对应的MACD数值price_bottom = i;price_bottom_value = price[i];}}//如果最低点出现在最高点之后,则没有底背离if (MACD_bottom > price_bottom)}/**阶段2:寻找MACD顶背离*/start = MAX_PRICE_DURATION + 1; end = start + MIN_PRICE_DURATION; low_index = -1;high_index = -1;min_price = price[start];max_price = price[start];for (i = start; i < end; i++)//查找最低点if (price[i] < min_price)low_index = i;min_price = price[i];}//查找最高点if (price[i] > max_price)max_price = price[i];}}//无法找到顶背离点if (low_index == -1 , high_index == -1) return 0;}MACD_top = 0;price_top = 0;//寻找MACD顶背离for (i = start; i < end; i++)if (i == low_index)//找到最低点对应的MACD数值MACD_top = i;MACD_top_value = MACD[i];}if (i == high_index)//找到最高点对应的MACD数值price_top_value = price[i];}}//如果最高点出现在最低点之后,则没有顶背离if (MACD_top > price_top)return 0;}//判断背离类型if (price_bottom_value < price_top_value && MACD_bottom_value > MACD_top_value)return 1; // 向上背离}if (price_bottom_value > price_top_value && MACD_bottom_value < MACD_top_value)return -1; // 向下背离}return 0;int mainfloat MACD[100] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 3.0, 2.0, 1.0};float price[100] = {1.0, 2.0, 3.0, 4.0, 3.0, 2.0, 1.0, 0.0, -1.0, -2.0};int result = CheckDivergence(MACD, price);printf("Result: %d\n", result);return 0;```该源码实现了一个简单的MACD背离自动画线指标。
MACD顶底背离通达信指标公式源码
MACD顶底背离通达信指标公式源码```pascal{MACD指标的顶底背离}{参数:N(计算的周期)}MA1:=MA(CLOSE,5);MA2:=MA(CLOSE,35);DIF:EMA1-EMA2;DEA:EMA(DIF,5);MACD:(DIF-DEA);TopSignal:(REF(HIGH<N,1) AND HIGH[1]>HIGH[2] ANDHIGH[1]>HIGH) AND REF(DEA,1)<0 AND DEA>0;BottomSignal:(REF(LOW<N,1) AND LOW[1]<LOW[2] AND LOW[1]<LOW) AND REF(DEA,1)>0 AND DEA<0;{ 在图表上画出TopSignal和BottomSignal的信号 }IF TopSignal THEN DRAWICON(TopSignal,'↑');IF BottomSignal THEN DRAWICON(BottomSignal,'↓');```源码的主要部分如下所示:-首先定义了两个移动平均线MA1和MA2,分别计算了收盘价的5日和35日均线。
-然后计算了MACD指标的快线(DIF)和慢线(DEA),采用了指数平滑移动平均线(EMA)的计算方法。
-最后根据顶底背离的条件判断,通过比较前一日和当前日的最高价和最低价,以及前一日和当前日的DEA值,来确定顶底背离的信号。
在图表上,通过DRAWICON函数可以绘制出顶底背离的箭头标志,上箭头表示顶背离,下箭头表示底背离。
请注意,这只是一个简化版的MACD顶底背离指标公式,具体的实现还需要根据具体的需求和市场情况进行调整和优化。
对于股票投资和分析,建议综合考虑多个指标和因素,进行综合分析和判断。
通达信MACDKDJRSIDMI顶底背离
通达信MACDKDJRSIDMI顶底背离因为版本不同,指标中如果有双引号问题的,换为单引号即可。
MACD/KDJ/RSI/DMI顶底背离+选股公式。
DIFF1:=EMA(CLOSE,12)-EMA(CLOSE,26);DEA1:=EMA(DIFF1,9);DRAWBAND(DEA1,DRAWNULL,DIFF1,RGB(250,0,0));DIFF:EMA(CLOSE,12)-EMA(CLOSE,26),COLORYELLOW;DEA:EMA(DIFF,9),COLORCYAN;量化MACD:2*(DIFF-DEA),COLORSTICK;TR1:=SUM(MAX(MAX(HIGH-LOW,ABS(HIGH-REF(CLOSE,1))),ABS(LOW-REF(CLOSE,1))),14);量化HD:=HIGH-REF(HIGH,1);量化LD:=REF(LOW,1)-LOW;量化PDM:=SUM(IF(量化HD>0 AND 量化HD>量化LD,量化HD,0),14);量化MDM:=SUM(IF(量化LD>0 AND 量化LD>量化HD,量化LD,0),14);量化PDI:=量化PDM*100/TR;量化MDI:=量化MDM*100/TR;A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));B1:=REF(C,A1+1)>C AND REF(DIFF,A1+1)<DIFF AND CROSS(DIFF,DEA);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));A3:=BARSLAST(REF(CROSS('RSI.RSI1'(6,12,24),'RSI.RSI2'(6,12 ,24)),1));B3:=REF(C,A3+1)>C ANDREF('RSI.RSI1'(6,12,24),A3+1)<'RSI.RSI1'(6,12,24) AND CROSS('RSI.RSI1'(6,12,24),'RSI.RSI2'(6,12,24));C1:=BARSLAST(REF(CROSS(DEA,DIFF),1));D1:=REF(C,C1+1)<C AND REF(DIFF,C1+1)>DIFF AND CROSS(DEA,DIFF);C2:=BARSLAST(REF(CROSS('KDJ.D'(9,3,3),'KDJ.K'(9,3,3)),1));D2:=REF(C,C2+1)<C AND REF('KDJ.K'(9,3,3),C2+1)>'KDJ.K'(9,3,3) AND CROSS('KDJ.D'(9,3,3),'KDJ.K'(9,3,3));C3:=BARSLAST(REF(CROSS('RSI.RSI2'(6,12,24),'RSI.RSI1'(6,12 ,24)),1));D3:=REF(C,C3+1)<C AND REF('RSI.RSI1'(6,12,24),C3+1)>'RSI.RSI1'(6,12,24) AND CROSS('RSI.RSI2'(6,12,24),'RSI.RSI1'(6,12,24));C4:=BARSLAST(REF(CROSS(量化MDI,量化PDI),1));D4:=REF(C,C+1)<C AND REF(量化MDI,C4+1)>量化MDI AND CROSS(量化MDI,量化PDI);A4:=BARSLAST(REF(CROSS(量化PDI,量化MDI),1));B4:=REF(C,A4+1)>C AND REF(量化PDI,A4+1)<量化PDI AND CROSS(量化PDI,量化MDI);量化MACD底背:IF(B1>0,1,0),COLORRED,NODRAW;KDJ底背:IF(B2>0,1,0),COLORFF00FF,NODRAW;RSI底背:IF(B3>0,1,0),COLORYELLOW,NODRAW;DMI底背:IF(B4>0,1,0),COLORBROWN,NODRAW;量化MACD顶背:IF(D1>0,1,0),COLOR00FF00,NODRAW;KDJ顶背:IF(D2>0,1,0),COLORFFCC66,NODRAW;RSI顶背:IF(D3>0,1,0),COLORWHITE,NODRAW;DMI顶背:IF(D4>0,1,0),COLORLIRED,NODRAW;{DRAWLINE(A1=0,DEA,量化MACD底背,DEA,0),COLORRED,LINETHICK2;DRAWLINE(A2=0,DEA,量化MACD顶背,DEA,0),COLOR00FF00,LINETHICK2;}STICKLINE(B1>0,-0.1,0,2,0),COLORRED;STICKLINE(B2>0,-0.1,-0.2,2,0),COLORFF00FF;STICKLINE(B3>0,-0.1,0,2,0),COLORYELLOW;STICKLINE(B4>0,-0.1,-0.2,2,0),COLORBROWN;STICKLINE(D1>0,0.1,0,2,0),COLOR00FF00;STICKLINE(D2>0,0.1,0.2,2,0),COLORFFCC66;STICKLINE(D3>0,0.1,0,2,0),COLORWHITE;STICKLINE(D4>0,0.1,0.2,2,0),COLORLIRED;选股公式:DIFF:=EMA(CLOSE,12)-EMA(CLOSE,26);DEA:=EMA(DIFF,9),;A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));XG:REF(C,A1+1)>C AND REF(DIFF,A1+1)<DIFF AND CROSS(DIFF,DEA);。
MACD背离副图指标 贴图 源码通达信指标公式
MACD2:=2*(MACD.DIF-MACD.DEA);STICKLINE(MACD2>=0 AND MACD2>REF(MACD2,1),0,MACD2,1.2,0),COLOR0000A5; STICKLINE(MACD2>=0 AND MACD2<REF(MACD2,1),0,MACD2,1.2,0),COLORAA7800; STICKLINE(MACD2<0 AND MACD2<REF(MACD2,1),0,MACD2,1.2,0),COLOR00A500; STICKLINE(MACD2<0 AND MACD2>REF(MACD2,1),0,MACD2,1.2,0),COLORA500A5; DIF:EMA(CLOSE,12)-EMA(CLOSE,26);DEA:EMA(DIF,9);MACD:(DIF-DEA)*2,NODRAW;{MACD日线二次金叉}JCCOUNT:=COUNT(CROSS(DIF,DEA),BARSLAST(DEA>=0));二次金叉:=CROSS(DIF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1; DRAWTEXT(二次金叉,DEA*1.25,'零下二金'),COLORWHITE;{MACD日线底背离}A1:=BARSLAST(REF(CROSS(DIF,DEA),1));底背离:=REF(CLOSE,A1+1)>CLOSE AND DIF>REF(DIF,A1+1) AND CROSS(DIF,DEA); DRAWTEXT(底背离,DIF*0.5,'日底背'),COLORRED;{日底背画线:DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,DOTLINE;}{MACD日线顶背离}A2:=BARSLAST(REF(CROSS(DEA,DIF),1));顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIF,A2+1)>DIF AND CROSS(DEA,DIF); DRAWTEXT(顶背离,DIF*1.12,'日顶背'),COLORGREEN;{日顶背画线:DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,DOTLINE;}{MACD_KDJ的金叉共振}{DIF:EMA(CLOSE,12)-EMA(CLOSE,26);DEA:EMA(DIF,9);}RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9));K:=SMA(RSV,9,3),NODRAW;D:=SMA(K,9,3),NODRAW;J:=3*K-2*D,NODRAW;M&K金共:=CROSS(DIF,DEA) AND CROSS(K,D) AND CROSS(J,D);DRAWTEXT(M&K金共,DEA*1.12,'金叉共振'),COLORYELLOW;{MACD柱背离}MACD高:=HHV(MACD,5);C1:=BARSLAST(REF(CROSS(DEA,DIF),1));E:=REF(C,C1+1)>C AND DEA>0 AND REF(MACD高,C1+1)<MACD高AND CROSS(DEA,DIF) ;DRAWTEXT(E>0,-0.5,'柱顶背'),COLORCYAN;F:=REF(C,A1+1)>C AND DEA<0 AND REF(MACD高,A1+1)<MACD高AND CROSS(DIF,DEA);DRAWTEXT(F>0,0.5,'柱底背'),COLORLIRED;{MACD积背离}JC:= DEA-DIF;绿柱面积:=IF(MACD<0,SUM(MACD,BARSLAST(JC<0)),0);红柱面积:=IF(MACD>0,SUM(MACD,BARSLAST(JC>0)),0);本次最低价:=LLV(L,BARSLAST(JC<0));本次最高价:=HHV(H,BARSLAST(JC>0));X1:=IF (MACD<0,BARSLAST(CROSS(DIF,DEA)),0);前次绿柱面积:=REF(绿柱面积,X1+1);前次最低价:=REF(本次最低价,X1+1);Y1:=IF((绿柱面积<0 AND ABS(绿柱面积)<ABS(前次绿柱面积) AND 本次最低价<前次最低价),1,0);RS1:= MACD<0 AND REF(MACD,1)<0 AND C<前次最低价AND ABS(绿柱面积)<ABS(前次绿柱面积) AND ABS(MACD)<ABS(REF(MACD,1));底背驰:= IF (CROSS(DIF,DEA),REF(Y1,1),0);DRAWTEXT(底背驰,DEA*0.8,'积底背'),COLORFF80FF;X2:=IF (MACD>0,BARSLAST(CROSS(DEA,DIF)),0);前次红柱面积:=REF(红柱面积,X2+1);前次最高价:=REF(本次最高价,X2+1);Y2:=IF((红柱面积>0 AND 红柱面积<前次红柱面积AND 本次最高价>前次最高价),1,0); RS2:= MACD>0 AND REF(MACD,1)>0 AND C>前次最高价AND ABS(红柱面积)<ABS(前次红柱面积) AND ABS(MACD)<ABS(REF(MACD,1));顶背驰:= IF (CROSS(DEA,DIF),REF(Y2,1),0);DRAWTEXT(顶背驰,DEA*0.8,'积顶背'),COLORCYAN;。
MACD双背离通达信指标公式源码
macd双背离DIFF: EMA(CLOSE,12) - EMA(CLOSE,26);DEA: EMA(DIFF,9);MACD: 2*(DIFF-DEA),COLORSTICK;JC:=DEA-DIFF;绿柱面积:=IF(MACD<0,SUM(MACD,BARSLAST(JC<0)),0);红柱面积:=IF(MACD>0,SUM(MACD,BARSLAST(JC>0)),0);本次最低价:=LLV(L,BARSLAST(JC<0));本次最高价:=HHV(H,BARSLAST(JC>0));X1:=IF (MACD<0,BARSLAST(CROSS(DIFF,DEA)),0);前次绿柱面积:=REF(绿柱面积,X1+1);前次最低价:=REF(本次最低价,X1+1);Y1:=IF((绿柱面积<0 AND ABS(绿柱面积)<ABS(前次绿柱面积)AND 本次最低价<前次最低价),1,0);RS1:= MACD<0 AND REF(MACD,1)<0 AND C<前次最低价AND ABS(绿柱面积)<ABS(前次绿柱面积) AND ABS(MACD)<ABS(REF(MACD,1)); 底背驰:= IF (CROSS(DIFF,DEA),REF(Y1,1),0);DRAWTEXT(底背驰,-0.01,'积底'),COLORRED;{DRAWBAND(DIFF,RGB(200,50,55),DEA,RGB(50,100,10));}X2:=IF (MACD>0,BARSLAST(CROSS(DEA,DIFF)),0);前次红柱面积:=REF(红柱面积,X2+1);前次最高价:=REF(本次最高价,X2+1);Y2:=IF((红柱面积>0 AND 红柱面积<前次红柱面积AND 本次最高价>前次最高价),1,0); RS2:= MACD>0 AND REF(MACD,1)>0 AND C>前次最高价AND ABS(红柱面积)<ABS(前次红柱面积) AND ABS(MACD)<ABS(REF(MACD,1));顶背驰:= IF (CROSS(DEA,DIFF),REF(Y2,1),0);DRAWTEXT(顶背驰,0.01,'积顶'),COLORGREEN;A11:=BARSLAST(REF(CROSS(DIFF,DEA),1));JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));底背离:=REF(CLOSE,A11+1)>CLOSE AND DIFF>REF(DIFF,A11+1) ANDCROSS(DIFF,DEA);DRAWTEXT(底背离,DEA,' 线底'),COLORRED;A22:=BARSLAST(REF(CROSS(DEA,DIFF),1));顶背离:=REF(CLOSE,A22+1)<CLOSE AND REF(DIFF,A22+1)>DIFF ANDCROSS(DEA,DIFF);DRAWTEXT(顶背离,DEA,'线顶'),COLORGREEN;A1:=DIFF<0 AND DEA<0;A2:=A1>REF(A1,1);A3:=BARSLAST(A2);。
【股票指标公式下载】-【通达信】真正背离(底背离、顶背离、macd、kdj、rsi)
【通达信】真正背离(底背离、顶背离、macd、kdj、rsi)-指标公式源码{参数N为5,10,5}DIFIF1:=EMA(CLOSE,12) - EMA(CLOSE,26);DEAEA1:=EMA(DIFIF1,9);MACD1:=2*(DIFIF1-DEAEA1),STICK;MACD2:=EMA(MACD1,3);STICKLINE(MACD1>MACD2 AND MACD1>0,0,MACD1,1,0),COLORRED; STICKLINE(MACD1>MACD2 AND MACD1<0,0,MACD1,1,0),COLORGREEN; STICKLINE(MACD1<MACD2,0,MACD1,1,0),COLORCBCBC0;STICKLINE(MACD1>=0 OR MACD1<=0,0,0,50,1),COLORWHITE;DIFIF1,COLOR33FF33,LINETHICK2;DEAEA1,COLORYELLOW,LINETHICK2;MACD:MACD1,NODRAW,COLORMAGENTA;强:IF(DIFIF1>=DEAEA1,DIFIF1,DRAWNULL),COLORRED,LINETHICK2;弱:=IF(DEAEA1>=DIFIF1,DEAEA1,DRAWNULL),COLORFF9900,LINETHICK2; DRAWICON(CROSS(DIFIF1,DEAEA1),DIFIF1+0.1,1);DRAWICON(CROSS(DEAEA1,DIFIF1),0.4,2);A1:=BARSLAST(REF(CROSS("MACD.DIF","MACD.DEA"),1));B1:=REF(C,A1+1)>C AND REF("MACD.DIF",A1+1)<"MACD.DIF" ANDCROSS("MACD.DIF","MACD.DEA");DRAWTEXT(B1>0,-0.8,'MACD底背'),COLORFF00FF;A2:=BARSLAST(REF(CROSS("KDJ.K","KDJ.D"),1));B2:=REF(C,A2+1)>C AND REF("KDJ.K",A2+1)<"KDJ.K" ANDCROSS("KDJ.K","KDJ.D");DRAWTEXT(B2,-0.6,'KDJ底离'),COLORYELLOW;{KDJ底背离};A3:=BARSLAST(REF(CROSS("RSI.RSI1","RSI.RSI2"),1));B3:=REF(C,A3+1)>C AND REF("RSI.RSI1",A3+1)<"RSI.RSI1" ANDCROSS("RSI.RSI1","RSI.RSI2");DRAWTEXT(B3>0,-0.3,'RSI底离'),COLORCYAN;{RSI底背离};C1:=BARSLAST(REF(CROSS("MACD.DEA","MACD.DIF"),1));D1:=REF(C,C1+1)<C AND REF("MACD.DIF",C1+1)>"MACD.DIF" ANDCROSS("MACD.DEA","MACD.DIF");DRAWTEXT(D1>0,0.4,'MACD顶离'),COLORBLUE;{MACD顶背离}C2:=BARSLAST(REF(CROSS("KDJ.D","KDJ.K"),1));D2:=REF(C,C2+1)<C AND REF("KDJ.K",C2+1)>"KDJ.K" ANDCROSS("KDJ.D","KDJ.K");DRAWTEXT(D2>0,0.6,'KDJ顶离'),COLORLIGRAY;{KDJ顶背离}C3:=BARSLAST(REF(CROSS("RSI.RSI2","RSI.RSI1"),1));D3:=REF(C,C3+1)<C AND REF("RSI.RSI1",C3+1)>"RSI.RSI1" ANDCROSS("RSI.RSI2","RSI.RSI1");DRAWTEXT(D3>0,0.8,'RSI顶离'),COLORGREEN;{RSI顶背离};【通达信】真正背离(底背离、顶背离、macd、kdj、rsi)-指标公式效果图(文档来源:若水财经社区)。
MACD背离自动画线通达信指标公式源码
DIF:MACD.DIF(12,26,9),LINETHICK2;DEA:MACD.DEA(12,26,9);MACD:(DIF-DEA)*2,COLORSTICK;DRAWICON(REF(DIF,1)>REF(DIF,2) AND DIF<REF(DIF,1) AND DIF>0 AND DIF>DEA,DIF*1.1,2),COLORGREEN;DRAWICON(CROSS(DEA,DIF) AND DIF>0,DIF,37),COLORGREEN;DRAWICON(REF(DIF,1)<REF(DIF,2) AND DIF>REF(DIF,1) AND DIF<0 AND DIF<DEA,DIF*1.1,1),COLORRED;DRAWICON(CROSS(DIF,DEA) AND DIF<0,DIF,36),COLORRED;XA_1:=MACD<0 AND MACD>REF(MACD,1) AND REF(MACD,1)<REF(MACD,2) AND REF(MACD,2)<REF(MACD,3) AND REF(MACD,3)<REF(MACD,4);STICKLINE(XA_1,0,MACD,0.3,0),COLORRED;XA_2:=MACD>0 AND MACD<REF(MACD,1) AND REF(MACD,1)>REF(MACD,2) AND REF(MACD,2)>REF(MACD,3) AND REF(MACD,3)>REF(MACD,4);STICKLINE(XA_2,0,MACD,0.3,0),COLORGREEN;XA_3:=100-100*(HHV(HIGH,34)-CLOSE)/(HHV(HIGH,34)-LLV(LOW,34))-50;XA_4:=EMA(XA_3,3);NOTEXTLU:IF(XA_4>24.99,DIF,DRAWNULL),COLORRED,LINETHICK2;NOTEXTLU2:IF(XA_4<(-40.009998),DIF,DRAWNULL),COLORGREEN,LINETHICK2; NOTEXT0:0,DOTLINE,COLORLIGRAY;XA_5:=IF(PERIOD=0,0.7,IF(PERIOD=1,1.2,IF(PERIOD=2,2,IF(PERIOD=3,2.5,IF(PERIOD =4,3,IF(PERIOD=5,5.5,IF(PERIOD=6,6,IF(PERIOD=7,7,IF(PERIOD=8,3.5,4)))))))));XA_6:=BARSLAST(CROSS(MACD,0));XA_7:=REF(XA_6,1)>0 AND XA_6=0;XA_8:=BARSLAST(XA_7);XA_9:=REF(XA_6,XA_8+1);XA_10:=HHVBARS(MACD,XA_8+XA_9);XA_11:=IF(XA_10>XA_8,REF(MACD,XA_10),0);XA_12:=IF(XA_10>XA_8,REF(HIGH,XA_10),0);XA_13:=IF(REF(HIGH,1)=HHV(HIGH,XA_8+XA_9),REF(HIGH,1),0);XA_14:=(XA_13-XA_12)/XA_12*100;XA_15:=COUNT(CROSS(0,MACD),XA_8+XA_9);XA_16:=MACD>0 AND MACD<XA_11 AND HIGH=HHV(HIGH,XA_8+XA_9) AND XA_11>0 AND XA_15=1;XA_17:=REF(XA_16,1) AND HIGH<REF(HIGH,1) AND MACD>0 AND XA_11>0;XA_18:=LLVBARS(MACD,XA_8+XA_9);XA_19:=IF(XA_18>XA_8,REF(MACD,XA_18),0);XA_20:=IF(XA_18>XA_8,REF(LOW,XA_18),0);XA_21:=IF(REF(LOW,1)=LLV(LOW,XA_8+XA_9),REF(LOW,1),0);XA_22:=(XA_20-XA_21)/XA_20*100;XA_23:=COUNT(CROSS(MACD,0),XA_8+XA_9);XA_24:=MACD<0 AND MACD>XA_19 AND LOW=LLV(LOW,XA_8+XA_9) AND XA_19<0 AND COUNT(CROSS(MACD,0),XA_8+XA_9)<=3;XA_25:=REF(XA_24,1) AND LOW>REF(LOW,1) AND MACD<0 AND XA_19<0;前高:IF(XA_17,XA_12,DRAWNULL),NODRAW,COLOR7FFF00;现高:IF(XA_17,XA_13,DRAWNULL),NODRAW,COLORGREEN;幅度_顶:IF(XA_17,XA_14,DRAWNULL),NODRAW,COLORYELLOW;原低:IF(XA_25,XA_20,DRAWNULL),NODRAW,COLORLIMAGENTA;现低:IF(XA_25,XA_21,DRAWNULL),NODRAW,COLORRED;幅度_底:IF(XA_25,XA_22,0),NODRAW,COLORYELLOW;DRAWICON(XA_25,MACD,26);DRAWICON(XA_17,MACD,27);XA_26:=BACKSET(XA_17,XA_10+1);XA_27:=BACKSET(XA_25,XA_18+1);NOTEXTMACDL:DRAWLINE(REF(XA_27,1)=0 AND XA_27=1 AND MACD<0,MACD,XA_25,MACD,0),COLORRED;NOTEXTMACDH:DRAWLINE(REF(XA_26,1)=0 AND XA_26=1 AND MACD>0,MACD,XA_17,MACD,0),COLORGREEN;涨家数:INDEXADV,NODRAW,COLORRED;跌家数:INDEXDEC,NODRAW,COLORGREEN;正量能:涨家数/(涨家数+跌家数)*100,NODRAW,COLORMAGENTA;负量能:跌家数/(涨家数+跌家数)*100,NODRAW,COLORYELLOW;。
背离主图指标通达信指标公式源码
背离指标顶背离出局,底背离入手。
简单实用。
DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);DEA:=EMA(DIFF,9);MACD:=2*(DIFF-DEA),COLORSTICK;A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));B1:=REF(C,A1+1)>C AND REF(DIFF,A1+1)<DIFF AND CROSS(DIFF,DEA);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) ANDCROSS("KDJ.K"(9,3,3),"KDJ.D"(9,3,3));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));C1:=BARSLAST(REF(CROSS(DEA,DIFF),1));D1:=REF(C,C1+1)<C AND REF(DIFF,C1+1)>DIFF AND CROSS(DEA,DIFF);C2:=BARSLAST(REF(CROSS("KDJ.D"(9,3,3),"KDJ.K"(9,3,3)),1));D2:=REF(C,C2+1)<C AND REF("KDJ.K"(9,3,3),C2+1)>"KDJ.K"(9,3,3) ANDCROSS("KDJ.D"(9,3,3),"KDJ.K"(9,3,3));C3:=BARSLAST(REF(CROSS("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24)),1));D3:=REF(C,C3+1)<C AND REF("RSI.RSI1"(6,12,24),C3+1)>"RSI.RSI1"(6,12,24) AND CROSS("RSI.RSI2"(6,12,24),"RSI.RSI1"(6,12,24));MACD底背:=IF(B1>0,-0.1,0),COLORRED,POINTDOT;KDJ底背:=IF(B2>0,-0.1,0),COLORFF00FF,POINTDOT;RSI底背:=IF(B3>0,-0.1,0),COLORYELLOW,POINTDOT;MACD顶背:=IF(D1>0,0.1,0),COLOR00FF00,POINTDOT;KDJ顶背:=IF(D2>0,0.1,0),COLORFFCC66,POINTDOT;RSI顶背:=IF(D3>0,0.1,0),COLORWHITE,POINTDOT;DRAWTEXT(FILTER(B1>0,5),L-0.38,'MACD底背'),COLORGREEN; DRAWTEXT(FILTER(B2>0,5),L-0.39,'KDJ底背'),COLORYELLOW; DRAWTEXT(FILTER(B3>0,5),L,'RSI底背'),COLORCYAN;DRAWTEXT(FILTER(D1>0,5),L+0.08,'MACD顶背'),COLORWHITE; DRAWTEXT(FILTER(D2>0,5),L+0.32,'KDJ顶背'),COLORWHITE; DRAWTEXT(FILTER(D3>0,5),L+0.1,'RSI顶背'),COLORMAGENTA; DRAWBAND(MA(CLOSE,3),RGB(200,50,160),MA(CLOSE,5),RGB(0,120,0));。
通达信指标公式源码 顶底背离MACD副图指标
VAR1:=EMA(SLOPE(C,21)+C,55);VAR2:=EMA(SLOPE(O,21)+O,55);VAR3:=EMA(SLOPE(H,21)+H,55);VAR4:=EMA(SLOPE(L,21)+L,55);VAR5:=EMA(C,3);VAR6:=EMA(O,3);VAR7:=EMA(H,3);VAR8:=EMA(L,3);VAR9:=VAR1-VAR5,LINETHICK2;VAR10:=VAR2-VAR6,LINETHICK2;VAR11:=VAR3-VAR7,LINETHICK2;VAR12:=VAR4-VAR8,LINETHICK2;ZJC:=REVERSE(VAR9);ZJO:=REVERSE(VAR10);ZJH:=REVERSE(VAR11);ZJL:=REVERSE(VAR12);DIF:EMA(ZJC*5,12)-EMA(ZJC*5,26);DEA:EMA(DIF,9);MACD:(DIF-DEA)*2,COLORSTICK;STICKLINE(MACD>REF(MACD,1) AND MACD>0,0,MACD,0,0),COLORRED; STICKLINE(MACD<REF(MACD,1) AND MACD>0,0,MACD,0,0),COLORMAGENTA;STICKLINE(MACD>REF(MACD,1) AND MACD<0,0,MACD,0,0),COLORYELLOW;STICKLINE(MACD<REF(MACD,1) AND MACD<0,0,MACD,0,0),COLORLIGREEN; STICKLINE(ZJC> ZJO,ZJH,ZJL,0.0,0),COLORFF66FF;STICKLINE(ZJC> ZJO,ZJC,ZJO,2.1,0),COLORAA00AA;STICKLINE(ZJC> ZJO,ZJC,ZJO,1.9,0),COLORCC11CC;STICKLINE(ZJC> ZJO,ZJC,ZJO,1.6,0),COLORFF22FF;STICKLINE(ZJC> ZJO,ZJC,ZJO,1.2,0),COLORFF44FF;STICKLINE(ZJC> ZJO,ZJC,ZJO,0.7,0),COLORFF66FF;STICKLINE(ZJC> ZJO,ZJC,ZJO,0.2,0),COLORFF99FF;STICKLINE(ZJC<=ZJO,ZJL,ZJC,0.0,0),COLORGREEN;STICKLINE(ZJC<=ZJO,ZJO,ZJC,2.1,0),COLOR005500;STICKLINE(ZJC<=ZJO,ZJO,ZJC,1.9,0),COLOR007700;STICKLINE(ZJC<=ZJO,ZJO,ZJC,1.6,0),COLOR009900;STICKLINE(ZJC<=ZJO,ZJO,ZJC,1.2,0),COLOR00BB00;STICKLINE(ZJC<=ZJO,ZJO,ZJC,0.7,0),COLOR00DD00;STICKLINE(ZJC<=ZJO,ZJO,ZJC,0.2,0),COLOR44FF00;ZTB:=(C-REF(C,1))/REF(C,1)*100>9.9;DRAWTEXT(ZTB,IF(ZJC<0,ZJC*0.9,ZJC*1.1),'涨停板')COLORYELLOW; STICKLINE(ZTB,ZJC,ZJO,2.1,0),COLOR006666;STICKLINE(ZTB,ZJC,ZJO,1.9,0),COLOR008888;STICKLINE(ZTB,ZJC,ZJO,1.6,0),COLOR00AAAA;STICKLINE(ZTB,ZJC,ZJO,1.2,0),COLOR00CCCC;STICKLINE(ZTB,ZJC,ZJO,0.7,0),COLOR00EEEE;STICKLINE(ZTB,ZJC,ZJO,0.2,0),COLOR33FFFF;DTB:=(C-REF(C,1))/REF(C,1)*100<-9.9;DRAWTEXT(DTB,IF(ZJC>0,ZJC*0.9,ZJC*1.1),'跌停板')COLORFF8800; STICKLINE(DTB,ZJO,ZJC,2.1,0),COLORFF0000;{蓝色}STICKLINE(DTB,ZJO,ZJC,1.9,0),COLORFF2200;STICKLINE(DTB,ZJO,ZJC,1.6,0),COLORFF4400;STICKLINE(DTB,ZJO,ZJC,1.2,0),COLORFF6600;STICKLINE(DTB,ZJO,ZJC,0.7,0),COLORFF8800;STICKLINE(DTB,ZJO,ZJC,0.2,0),COLORFFAA00;。
通达信顶底背离指标 副图 源码
MA1:MA(C,5);MA2:MA(C,10);MA3:MA(C,30);A1:=BARSLAST(REF(CROSS("MACD.DIF"(12,26,9),"MACD.DEA"(12,26,9)),1));B1:=REF(C,A1+1)>C AND REF("MACD.DIF"(12,26,9),A1+1)<"MACD.DIF"(12,26,9) AND CROSS("MACD.DIF"(12,26,9),"MACD.DEA"(12,26,9));底背离MACD:DRAWTEXT(FILTER(B1>0,5),LOW,'1'),COLORYELLOW;DRAWTEXT(FILTER(B1>0,5),LOW*0.98,'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) ANDCROSS("KDJ.K"(9,3,3),"KDJ.D"(9,3,3));底背离KDJ:DRAWTEXT(FILTER(B2>0,5),LOW,'▲'),COLORYELLOW;DRAWTEXT(FILTER(B2>0,5),LOW*0.98,'KDJ底背离'),COLORRED;A3:=BARSLAST(REF(CROSS("RSI.RSI1"(8,55,55),"RSI.RSI2"(8,55,55)),1));B3:=REF(C,A3+1)>C AND REF("RSI.RSI1"(8,55,55),A3+1)<"RSI.RSI1"(8,55,55) AND CROSS("RSI.RSI1"(8,55,55),"RSI.RSI2"(8,55,55));底背离RSI:DRAWTEXT(FILTER(B3>0,5),LOW,'▲'),COLORYELLOW;DRAWTEXT(FILTER(B3>0,5),LOW*0.98,'RSI底背离'),COLORF0F000;A4:=BARSLAST(REF(CROSS("DMI.PDI"(14,6),"DMI.MDI"(14,6)),1));B4:=REF(C,A4+1)>C AND REF("DMI.PDI"(14,6),A4+1)<"DMI.PDI"(14,6) AND CROSS("DMI.PDI"(14,6),"DMI.MDI"(14,6));底背离DMI:DRAWTEXT(FILTER(B4>0,5),LOW,'▲'),COLORYELLOW;DRAWTEXT(FILTER(B4>0,5),LOW*0.98,'DMI底背离'),COLORF00FF0;C1:=BARSLAST(REF(CROSS("MACD.DEA"(12,26,9),"MACD.DIF"(12,26,9)),1));D1:=REF(C,C1+1)<C AND REF("MACD.DIF"(12,26,9),C1+1)>"MACD.DIF"(12,26,9) AND CROSS("MACD.DEA"(12,26,9),"MACD.DIF"(12,26,9));顶背离MACD:DRAWTEXT(FILTER(D1>0,5),HIGH*1.02,'▲'),COLOR00FF00; DRAWTEXT(FILTER(D1>0,5),HIGH*1.04,'MACD顶背离'),COLORRED;C2:=BARSLAST(REF(CROSS("KDJ.D"(9,3,3),"KDJ.K"(9,3,3)),1));D2:=REF(C,C2+1)<C AND REF("KDJ.K"(9,3,3),C2+1)>"KDJ.K"(9,3,3) ANDCROSS("KDJ.D"(9,3,3),"KDJ.K"(9,3,3));顶背离KDJ:DRAWTEXT(FILTER(D2>0,5),HIGH*1.02,'▲'),COLOR00FF00; DRAWTEXT(FILTER(D2>0,5),HIGH*1.04,'KDJ顶背离'),COLORF00FF0;C3:=BARSLAST(REF(CROSS("RSI.RSI2"(8,55,55),"RSI.RSI1"(8,55,55)),1));D3:=REF(C,C3+1)<C AND REF("RSI.RSI1"(8,55,55),C3+1)>"RSI.RSI1"(8,55,55) AND CROSS("RSI.RSI2"(8,55,55),"RSI.RSI1"(8,55,55));顶背离RSI:DRAWTEXT(FILTER(D3>0,5),HIGH*1.02,'▲'),COLOR00FF00;DRAWTEXT(FILTER(D3>0,5),HIGH*1.04,'RSI顶背离'),COLORYELLOW;C4:=BARSLAST(REF(CROSS("DMI.MDI"(14,6),"DMI.PDI"(14,6)),1));D4:=REF(C,C4+1)<C AND REF("DMI.PDI"(14,6),C4+1)>"DMI.PDI"(14,6) AND CROSS("DMI.MDI"(14,6),"DMI.PDI"(14,6));顶背离DMI:DRAWTEXT(FILTER(D4>0,5),HIGH*1.02,'▲'),COLOR00FF00; DRAWTEXT(FILTER(D4>0,5),HIGH*1.04,'DMI顶背离'),COLORF0F000;。
MACD背离自动画线通达信指标公式源码
MACD背离自动画线通达信指标公式源码通达信(MetaStock)是一种常用的股票分析软件,提供了丰富的指标库。
在通达信中编写指标公式可以使用通达信自带的公式语言-支持C语言语法。
为了实现MACD背离自动画线指标,我们首先要计算MACD指标的数值,并判断是否出现背离。
接下来,我们可以使用通达信的画线函数实现在背离点位置上自动画线。
下面是该指标的示例源码:```javascript/*时间:2024-01-01*/#include "stdio.h"#include "stdlib.h"#include "string.h"#include "windows.h"/*定义MACD指标相应变量*/double EMA_SHORT;double EMA_LONG;double DIFF;double DEA;double MACD;/*初始化操作,在指标开始计算之前调用*/void InitEMA_SHORT=0;EMA_LONG=0;DIFF=0;DEA=0;MACD=0;/*计算MACD指标的数值*/void CalculateMACD(double close[], int n, int shortPeriod, int longPeriod, int signalPeriod)double EMA_SHORT_SMOOTH = 2.0 / (shortPeriod + 1);double EMA_LONG_SMOOTH = 2.0 / (longPeriod + 1);//计算短期EMAdouble emaShortPrev = close[0];for (int i = 0; i < shortPeriod; i++)emaShortPrev = emaShortPrev * (1 - EMA_SHORT_SMOOTH) +close[i] * EMA_SHORT_SMOOTH;}//计算长期EMAdouble emaLongPrev = close[0];for (int i = 0; i < longPeriod; i++)emaLongPrev = emaLongPrev * (1 - EMA_LONG_SMOOTH) + close[i] * EMA_LONG_SMOOTH;}//计算DIFF和DEADIFF = emaShortPrev - emaLongPrev;DEA=0;double DEA_SMOOTH = 2.0 / (signalPeriod + 1);for (int i = 0; i < signalPeriod; i++)DEA=DEA*(1-DEA_SMOOTH)+DIFF*DEA_SMOOTH;}//计算MACDMACD=(DIFF-DEA)*2;/*判断是否出现背离*/int IsDivergence(double close[], int n, int direction)for (int i = 2; i < n; i++)double prevClose1 = close[i - 2];double prevClose2 = close[i - 1];double currentClose = close[i];if (direction == 1) // 上涨背离:前两个低点价格下降,当前高点价格上升if (prevClose1 > prevClose2 && prevClose2 > currentClose) return i;}}else if (direction == -1) // 下跌背离:前两个高点价格上升,当前低点价格下降if (prevClose1 < prevClose2 && prevClose2 < currentClose)return i;}}}return -1;/*自动画线函数,在背离位置上自动画线*/void AutoDrawLine(int barIndex, int direction)//自动画线的相关处理,这里仅做示例printf("在第 %d 根K线上画上涨背离线。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MACD顶底背离通达信指标公式源码
MACD顶底背离通达信指标公式源码
软件介绍
本公式在日线,小时线,半小时线等周期中根据MACD红柱的缩小都能及时给我们的操作做出风险提示,尤其是在短周期中提示更有效。
此公式不是万能的,还需要结合其他操盘指标才更有效。
DIF:EMA(CLOSE,12)-EMA(CLOSE,26);
DEA:EMA(DIF,9);
MACD:(DIF-DEA)*2,COLORSTICK;
H1:=REF(MACD,1)<0 AND MACD>0,NODRAW;
H1T:=BARSLAST(H1)+1,NODRAW;
H2:=IF(MACD>0,H1T,0),NODRAW;
H3:=HHV(MACD,H2),NODRAW;
L1:=REF(MACD,1)>0 AND MACD<0,NODRAW;
L1T:=BARSLAST(L1)+1,NODRAW;
HJ:=(H1T+L1T),NODRAW;
H4:=REF(H3,HJ),NODRAW;
顶背离:H3<H4 AND C>REF(C,HJ) AND MACD>0 AND MACD<REF(MACD,1),COLORGREEN,NODRAW; STICKLINE(顶背离,0,MACD,2,0),COLORGREEN;
下载地址。