universe 发表于 2014-10-16 18:06:13

求哪位大哥将此用mql4编写的KDJ指标用mql5编写

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 8

#property indicator_color1 LightSlateGray
#property indicator_color2 0x00ff00
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 0Xffccff
#property indicator_color6 MediumSlateBlue

//---- input parameters
extern int       M1=3;
extern int       M2=6;
extern int       KdjPeriod=30;
//---- buffers
double RsvBuffer[],RSV[],K[],D[],J[],KDC[];
double MaxHigh=0,MinLow=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
    //---- name for DataWindow and indicator subwindow label
    string short_name;
   short_name="KDJ("+KdjPeriod+","+M1+","+M2+") ";
   IndicatorShortName(short_name);
   SetIndexLabel(0,NULL);
   SetIndexLabel(1,"RSV:");
   SetIndexLabel(2,"K");
   SetIndexLabel(3,"D:");
   SetIndexLabel(4,"J");
   SetIndexLabel(5,"KDC");
//----
//---- indicators
//---- drawing settings
   IndicatorDigits(Digits-2);       //set小数精度两位
   //SetIndexStyle(0,DRAW_NONE);
   //SetIndexLabel(0,NULL);
   SetIndexShift(0,100);
   SetIndexStyle(0,DRAW_LINE,2,0);
   SetIndexBuffer(0,RsvBuffer);
   //----
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,RSV);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,K);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,D);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,J);
   SetIndexStyle(5,DRAW_HISTOGRAM);
   SetIndexBuffer(5,KDC);
   return(0);
}

int start()
{
   int    counted_bars=IndicatorCounted();
//----
   int i;
   if(Bars<=KdjPeriod) return(0);
//----
   i=Bars-counted_bars-1;
   while(i>=0)
   {
      MaxHigh=High;
      MinLow=Low;
      RSV=(Close-MinLow)/(MaxHigh-MinLow)*100;
      if(i/2)
      RsvBuffer=50.0;
      i--;
   }
      Ksma(RSV,M1,2);                     //get K value
      Dsma(K,M2,3);                     //get D value
//---- //
if(counted_bars>0) counted_bars--;
for(i=Bars-counted_bars-1;i>=0;i--)
   {
   RsvBuffer=50.0;
      J=3*K-2*D;
      if(J<0) J=0;
      if(J>100) J=100;
           KDC=K-D;
      }   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Simple Moving Average                                          |
//+------------------------------------------------------------------+
double Dsma(double ArrPara[],int MA_Period,int flag)
{
   double sum=0;
   int ExtCountedBars=IndicatorCounted();
   int    i,pos=Bars-IndicatorCounted()-1;
//---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
   sum+=K;
//---- main calculation loop
   while(pos>=0)
   {
      sum+=K;                   //加上最新的K值
      switch(flag)
           {
           case 3: D=sum/MA_Period;break;
           }
           sum-=K;
           pos--;
   }
   }
//+------------------------------------------------------------------+
//| Simple Moving Average                                          |
//+------------------------------------------------------------------+
double Ksma(double ArrPara[],int MA_Period,int flag)
{
   double sum=0;
   int ExtCountedBars=IndicatorCounted();
   int    i,pos=Bars-IndicatorCounted()-1;
   //---- initial accumulation
   if(pos<MA_Period) pos=MA_Period;
   for(i=1;i<MA_Period;i++,pos--)
       sum+=RSV;
   //---- main calculation loop
   while(pos>=0)
   {
   sum+=RSV;                  //加上最新的RSV[]的值
          switch(flag)
           {
           case 2: K=sum/MA_Period;break;
           }
      sum-=RSV;
           pos--;
   }
}

KSXJM 发表于 2014-10-16 18:30:13

qq3475483 发表于 2014-10-16 18:39:11

iexielo哦哦哦

liu218 发表于 2014-10-16 19:57:46


Powered by 交易策略分享社区 All Rights Reserved

永痕 发表于 2014-10-17 16:37:50


路过看看学学

永痕 发表于 2014-10-19 19:23:32

路过看看学学

ajfy666 发表于 2014-10-25 18:29:12

新手学习 多多关照

kuangren90 发表于 2017-3-14 13:02:40

谢谢分享,学编程,学交易,实现程序化交易。
页: [1]
查看完整版本: 求哪位大哥将此用mql4编写的KDJ指标用mql5编写