苏尔托诺夫差分指标 - 页 41

 
Dmitry Fedoseev:

5分钟后将会有一个代码。请记住,RSI使用Wilder平滑法,与指数平滑法相同,但周期更长,所以可能有明显的不匹配。


有什么需要准备的呢?我们把RSI的主缓冲区扔掉,把现有的两个缓冲区放在它的位置上。

//+------------------------------------------------------------------+
//|                                                          RSI.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "https://www.mql4.com"
#property description "Relative Strength Index"
#property strict

#property indicator_separate_window
#property indicator_buffers    2
#property  indicator_color1     clrBlue
#property  indicator_color2     clrRed

//--- input parameters
input int InpRSIPeriod=14; // RSI Period
//--- buffers
double ExtPosBuffer[];
double ExtNegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
//--- 2 additional buffers are used for counting.
   SetIndexBuffer(0,ExtPosBuffer);
   SetIndexBuffer(1,ExtNegBuffer);
//--- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
//--- name for DataWindow and indicator subwindow label
   short_name="RSI("+string(InpRSIPeriod)+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- check for input
   if(InpRSIPeriod<2)
     {
      Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(0,InpRSIPeriod);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
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,pos;
   double diff;
//---
   if(Bars<=InpRSIPeriod || InpRSIPeriod<2)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtPosBuffer,false);
   ArraySetAsSeries(ExtNegBuffer,false);
   ArraySetAsSeries(close,false);
//--- preliminary calculations
   pos=prev_calculated-1;
   if(pos<=InpRSIPeriod)
     {
      //--- first RSIPeriod values of the indicator are not calculated
      ExtPosBuffer[0]=0.0;
      ExtNegBuffer[0]=0.0;
      double sump=0.0;
      double sumn=0.0;
      for(i=1; i<=InpRSIPeriod; i++)
        {
         ExtPosBuffer[i]=0.0;
         ExtNegBuffer[i]=0.0;
         diff=close[i]-close[i-1];
         if(diff>0)
            sump+=diff;
         else
            sumn-=diff;
        }
      //--- calculate first visible value
      ExtPosBuffer[InpRSIPeriod] = sump / InpRSIPeriod;
      ExtNegBuffer[InpRSIPeriod] = sumn / InpRSIPeriod;
      //--- prepare the position value for main calculation
      pos=InpRSIPeriod+1;
     }
//--- the main loop of calculations
   for(i=pos; i<rates_total && !IsStopped(); i++)
     {
      diff=close[i]-close[i-1];
      ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod;
      ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod;
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
那里没有平滑。而计算方法不同的是,熊市的力量 包括了斗鸡。这就是区别。检察院考虑到了这一点。
 
Dmitry Fedoseev:

5分钟后将会有一个代码。请记住,RSI使用Wilder平滑法,与指数法相同,但周期更长,所以可能会有明显的不匹配。

你现在退缩了吗?
 

附上一个指标。

参数。

period - 以小节为单位的周期。

组件- 组件计算选项。

  • c_rsi - 和RSI一样
  • c_adx - 如同ADX的情况
  • c_x - 和RSI一样,但不是按周期划分,而是按实际增量划分。

平稳--平稳法。

  • s_wilder - Wilder方法
  • s_ema - 指数平滑法。
请记住,RSI成分是由Wilder平滑的,而ADX成分是由传统的指数法平滑的(即RSI的14期对应于ADX的27期)。

权力--最终线的计算方式。

  • f_off - 不显示,以便更好地查看组件。
  • f_rsi - 和RSI一样
  • f_adx - 作为ADX。

供参考:RSI的最终线没有平滑,ADX是平滑的。

***

通过设置,你可以通过这个指标获得RSI和ADX以及各种混合指标。

为了得到RSI。

  • 组件 - c_rsi
  • 顺利 - s_wilder
  • 功率 - f_rsi;

为了获得ADX。

  • 组件 - c_adx
  • 顺利 - s_ema
  • 功率 - f_adx

电源 - 启用/禁用,以保持组件不受影响。

***

还附上了本帖 图片中带有两个指标的模板。

附加的文件:
qwerty.mq5  6 kb
2ind.tpl  201 kb
 
Yousufkhodja Sultonov:
你现在在备份吗?

背景故事在哪里?五分钟写一篇文章是很多吗?

 
Ihor Herasko:

...

There's no antialiasing in there....

那是什么?-

ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod;
ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod;
这是更狂野的平滑。它在本质上与指数相同,但速度较慢。
 
Dmitry Fedoseev:

背景故事在哪里?5分钟写一篇文章是不是很多?

DA中没有平滑,也不需要平滑。你对此怎么说?
 
Yousufkhodja Sultonov:
DA中没有平滑,也不需要平滑。你怎么看这个问题?

有可能不像RSI那样平滑,而是成分本身,它是一个简单的平均值。可以细化我上述的通用指标,以启用/禁用平滑处理。但从概念上讲,没有任何变化。

此外,你最好在说话之前表现出来。为什么你这么严厉地要求我,而你却胡说八道?

 
Dmitry Fedoseev:

背景故事在哪里?5分钟写一篇文章是不是很多?

我的意思是这样。 "请记住,RSI使用Wilder平滑,它与指数 相同,但周期更大,由此可能会出现明显的不匹配。"

任何具有较长或较短周期的公约,指数或定期平滑 - 这一切有什么意义?检察官抓住公牛的角,抓住熊的爪子和脚。

 
Dmitry Fedoseev:
有可能不像RSI那样平滑,而是成分本身,这是一个简单的平均值。可以细化我上述的通用指标,以启用/禁用平滑处理。但从概念上讲,没有任何变化。
现在你当然可以了。
 
Dmitry Fedoseev:
有可能不像RSI那样平滑,而是成分本身,它是一个简单的平均值。你可以细化我上面的通用指标,启用/禁用平滑。但从概念上讲,没有任何变化。

你试图用公式与讲诗歌语言的人争论。