KDJ指标就是随机指标,由K线、D线和J线这三条曲线共同构成,通过分析图表,我们可以得出,K、D、J分别用不同的颜色线条来表示,所谓的K线是指快速确认线,D线就是指慢速主干线,而J线则为方向明暗线。K值和D值的浮动范围是0~100,而J值则能够小于0或者大于100,可以波动的范围更广。KDJ是为了判断中短期行情走势而出现的。
KDJ指标的计算公式是:
RSV:=(CLOSE-LLV(LOW,N))/(HHV(HIGH,N)-LLV(LOW,N))100;
K:SMA(RSV,M1,1);
D:SMA(K,M2,1);
J:3K-2*D;
KDJ指标的一般使用:
1.指标>80时,回档机率大;指标<20时,反弹机率大;
2.K在20左右向上交叉D时,视为买进信号;
3.K在80左右向下交叉D时,视为卖出信号;
4.J>100时,股价易反转下跌;J<0时,股价易反转上涨;
5.KDJ波动于50左右的任何信号,其作用不大。
MT4加载KDJ
MT4中KDJ指标源代码
#property copyright "Copyright 2020,fxMeter"
#property link "https://www.mql5.com/zh/users/fxmeter"
#property version "2.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 3
//--- plot KLine
#property indicator_label1 "KLine"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrWhite
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot DLine
#property indicator_label2 "DLine"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrGold
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot JLine
#property indicator_label3 "JLine"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDarkViolet
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1#property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor clrSilver
#property indicator_level1 0
#property indicator_level2 20
#property indicator_level3 50
#property indicator_level4 80
#property indicator_level5 100//---- input parameters
input int N =9;
input int M1=3;
input int M2=3;
//--- indicator buffers
double KBuffer[];
double DBuffer[];
double JBuffer[];
double llv[],hhv[],rsv[];
double p=0,p1=0;
double f=0,f1=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(){
//--- indicator buffers mappingIndicatorBuffers(6);SetIndexBuffer(0,KBuffer);SetIndexBuffer(1,DBuffer);SetIndexBuffer(2,JBuffer);SetIndexBuffer(3,llv,INDICATOR_CALCULATIONS);SetIndexBuffer(4,hhv,INDICATOR_CALCULATIONS);SetIndexBuffer(5,rsv,INDICATOR_CALCULATIONS);for(int i=0;i<6;i++){ SetIndexDrawBegin(i,N+M1+M2);}SetLevelValue(0,0);SetLevelValue(1,20);SetLevelValue(2,50);SetLevelValue(3,80);SetLevelValue(4,100); string name = "KDJ("+ (string)N+","+(string)M1+","+(string)M2+")";IndicatorShortName(name);IndicatorDigits(2);if(N<=0||M1<=0||M2<=0) return(INIT_FAILED);p = 1.0/M1; p1 = 1-p;f = 1.0/M2; f1 = 1-f;//---return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],const double &open[],const double &high[],const double &low[],const double &close[],const long &tick_volume[],const long &volume[],const int &spread[]){
//---int i,limit=0;if(rates_total<=0)return(0);if(prev_calculated<=0)limit=rates_total-1;else limit = rates_total - prev_calculated +1;for(i=limit; i>=0; i--){llv[i]=0; hhv[i]=0;if(i>rates_total-N) continue;int shift = iLowest(NULL,0,MODE_LOW,N,i);llv[i] = low[shift];shift = iHighest(NULL,0,MODE_HIGH,N,i);hhv[i] = high[shift];}for(i=limit; i>=0; i--){rsv[i] = 0;if(hhv[i]>0 && llv[i]>0 && (hhv[i]-llv[i])!=0)rsv[i] = (close[i]-llv[i])/(hhv[i]-llv[i])*100;}for(i=limit; i>=0; i--){if(i==rates_total-1) KBuffer[i]=0;else{KBuffer[i] = rsv[i]*p + KBuffer[i+1]*p1;}}for(i=limit; i>=0; i--){if(i==rates_total-1) DBuffer[i]=0;else{DBuffer[i] = KBuffer[i]*f + DBuffer[i+1]*f1;}}for(i=limit; i>=0; i--){JBuffer[i] = 3*KBuffer[i] - 2*DBuffer[i];}//--- return value of prev_calculated for next callreturn(rates_total);}
//+------------------------------------------------------------------+
工欲善其事,必先利其器,交易最重要的是遵守规则,严格执行。关注公众号,学习MQL入门到精通EA教程,学习更多EA编程,畅写属于自己的EA,锻造属于自己的神兵利器。
KDJ指标下载方式,关注公众号,在资源栏获取下载连接即可。