DS指标解析

源码见tommy版本,观察效果跟DS2.1相同,后者使用了四色,更美观些。

ma[_e1] = iMA(NULL,0,1,0,0,0,i);//代表使用收盘价作为数据源。

然后计算(StoPeriod+Smooth+2)默认值5+3+2=10,即用现价与过去1~9柱高低价进行比较,获得最高价和最低价。

double Bulls = DSSmooth(ma[_e1] - low,1,0,i);       

double Bears = DSSmooth(hig - ma[_e1],1,1,i);

代表现价在这个波段中的位置关系,Bulls代表与波谷的距离,Bears代表与波峰的距离。

double BB = (Bulls - Bears)/(Bulls + Bears);

这里分子使用Bulls-Bears差值计算,一般常见的仅用Bulls/(Bulls + Bears)就可以,代表现价在整段波幅中的位置关系,即代表(0,1)信号,而这里意味着归一化目的是(-1,1)。

     double SS = DSSmooth(BB,StoPeriod,2,i);

            SS = MathMin (SS, 0.99);

            SS = MathMax (SS,-0.99);

对BB平坦化,获得SS,同时限制在(-1,1)之间。

接着对SS再度平坦化,获得最终指标计算值。

DSto[i] = DSSmooth(MathLog((1.0 + SS)/(1.0 - SS)),Smooth,3,i);

这里使用了对数函数log(1+x)/(1-x),函数图形如下,

2019-02-06


这是归一化的一种方式,常见的是计算数据的对数,再除以样本数据中最大值的对数,这个叫做Z变换。

最后再次调用DSSmooth()函数,这个函数的特点是,

  • 参数x越大,当前数据的比重越小,x=1代表直接使用当前数据,不做平坦化;

  • 参数y代表做了四次平坦化的个数,用来当数组元素用的。

  • 参数z代表时序偏差。

整体上看,这是个表征位置关系的指标,在负值较大的,上涨概率大,反之下跌概率大。

DS指标只对过去9柱的高低价进行获取,然后进行三次(实际是2次)平坦化运算,获取位置关系,最后指导后续开单.

因此无未来函数.

第一次平坦化,计算现价在最近九根K线波段中,离高低价的幅度,实质未做平坦化修饰;

第二次,归一化数据获得BB,对BB进行平坦化,当前数据权重30%(STO=5)

第三次,对SS先使用对数函数归一化,再平坦化,当前数据权重50%


 

//+------------------------------------------------------------------+

//|                                                  DStochastic.mq4 |

//|                                                            Tommy |

//|                                                       2011.12.26 |

//+------------------------------------------------------------------+

#property copyright "http://www.fxeat.com"

#property link      "http://www.fxeat.com"



#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1  Red

#property indicator_width1  2

#property indicator_level1  0



extern int StoPeriod  = 5;

extern int Smooth     = 3;



double DSto[];



int init()

{

   IndicatorBuffers(1);

   SetIndexBuffer(0, DSto);

   SetIndexLabel (0, "DSto"); 



   SetIndexDrawBegin (0, StoPeriod + Smooth);

   IndicatorShortName("DStochastic_T");



   return(0);

}



int     mpt[];

double  mse[][2];//权重数组

#define _e1 0

#define _e2 1



//DSSmooth(ma[_e1] - low,1,0,i); 

//DSSmooth(MathLog((1.0 + SS)/(1.0 - SS)),Smooth,3,i);



double DSSmooth(double value,int x,int y,int z)

{ 

   if (ArrayRange(mse,0)!= 5) ArrayResize(mse,5);

   if (ArrayRange(mpt,0)!= 5) ArrayResize(mpt,5);

   

   double    reback = 1.0;

   if(y > 2) reback = y + 21;

   if(mpt[y] != Time[z])

   {

    for(int i=0; i<1; i++) 

    for(int j=0; j<1; j++)

    mse[i+j+y][_e2] = mse[i+j+y][_e1];

             mpt[y] = Time[z];

   }

   if(z >= Bars - 2) 

   {

    for(i=0; i<1; i++) 

    for(j=0; j<1; j++)

    mse[i+j+y][_e1] = value; 

   }

   if(z < Bars - 2)  

   {

    for(i=0; i<1; i++)

    for(j=0; j<1; j++)

     {   

      mse[i+j+y][_e1] = mse[i+j+y][_e2]*(1 - 2.0/(x + 1.0)) + 2.0/(x + 1.0)*value; 

      if(j <= 0)value = mse[i+j+y][_e1]*reback; 

      else value += (mse[y+i][_e1] - mse[i+j+y][_e1])*reback;

     }   

   }

  return(value); 

}



int    pt;

double ma[2];



int start()

{

   int i, j, limit;

   int counted_bars = IndicatorCounted();

   if(counted_bars > 0) limit=Bars-counted_bars-1;

   if(counted_bars < 0) return(0);

   if(counted_bars < 1)

   { 

    limit = Bars - 1;   

    for(i=limit; i>=0; i--)DSto[i] = EMPTY_VALUE;

   } 

   

   for(i=limit; i>=0; i--) 

   {  

    ma[_e1] = iMA(NULL,0,1,0,0,0,i);//收盘价

    if(pt != Time[i])

    { 

     ma[_e2] = ma[_e1];

          pt = Time[i];

    } 

    if(i < Bars-2)

    {

     double hig = High[i];      

     double low = Low [i];

     for(j=1; j<StoPeriod+Smooth+2; j++)

     {   

      hig = MathMax(hig,High[i+j]);

      low = MathMin(low,Low [i+j]);

     }

     double Bulls = DSSmooth(ma[_e1] - low,1,0,i);       

     double Bears = DSSmooth(hig - ma[_e1],1,1,i);

     if(Bulls + Bears > 0)

     double BB = (Bulls - Bears)/(Bulls + Bears);

     double SS = DSSmooth(BB,StoPeriod,2,i);

            SS = MathMin (SS, 0.99);

            SS = MathMax (SS,-0.99);

     DSto[i] = DSSmooth(MathLog((1.0 + SS)/(1.0 - SS)),Smooth,3,i);

    }

  }

  return(0);

}



微信公众号:天泓评测


本博客所有文章如无特别注明均为原创。作者:天泓评测
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)