There will be a code in 5 mins. Keep in mind that RSI uses Wilder smoothing, which is the same as exponential smoothing but with a longer period, so there may be a noticeable mismatch.
What is there to prepare? We throw out the main buffer from RSI and put the existing two buffers in its place:
//+------------------------------------------------------------------+//| 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_buffers2#property indicator_color1 clrBlue#property indicator_color2 clrRed//--- input parametersinputint InpRSIPeriod=14; // RSI Period//--- buffersdouble ExtPosBuffer[];
double ExtNegBuffer[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit(void)
{
string short_name;
//--- 2 additional buffers are used for counting.SetIndexBuffer(0,ExtPosBuffer);
SetIndexBuffer(1,ExtNegBuffer);
//--- indicator lineSetIndexStyle(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 inputif(InpRSIPeriod<2)
{
Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod);
return(INIT_FAILED);
}
//---SetIndexDrawBegin(0,InpRSIPeriod);
//--- initialization donereturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Relative Strength Index |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
int i,pos;
double diff;
//---if(Bars<=InpRSIPeriod || InpRSIPeriod<2)
return(0);
//--- counting from 0 to rates_totalArraySetAsSeries(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 calculationsfor(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);
}
//+------------------------------------------------------------------+
There is no smoothing there. And the calculation is different in that the strength of the bears includes the doji. That is the difference. The DA takes this into account.
There will be a code in 5 mins. Keep in mind that RSI uses Wilder smoothing, which is the same as exponential but with a longer period, so there may be a noticeable mismatch.
c_x - as for RSI, but division not by period, but by actual number of increments.
Smooth - smooth method:
s_wilder - Wilder method
s_ema - exponential smoothing.
Keep in mind that RSI components are smoothed by Wilder, while ADX components are smoothed by the conventional exponential method (i.e. period 14 for RSI corresponds to period 27 for ADX).
Power - the way the final line is calculated:
f_off - not displayed to better see the components
f_rsi - as for RSI
f_adx - as ADX.
For information: final line of RSI is not smoothed, ADX is smoothed.
***
You can get RSI and ADX and various hybrids by this indicator through settings.
To get RSI:
Components - c_rsi
Smooth - s_wilder
Power - f_rsi;
To get ADX:
Components - c_adx
Smooth - s_ema
Power - f_adx
Power - enable/disable to keep components out of the way.
***
Template with two indicators as in the image from this post is also attached.
Yousufkhodja Sultonov: There is no smoothing in DA and it is not required. What do you think about it?
It is possible not to smooth as in RSI, but the components themselves, it is a simple average. It is possible to refine my above universal indicator to enable/disable smoothing. But conceptually nothing changes.
Besides, you'd better show it before you speak. Why do you ask me so severely, and you blah blah blah
Where's the back story? Is 5 minutes to write a post a lot?
What I meant was this: "Keep in mind that RSI uses Wilder smoothing, it's the same as exponential but with a larger period, there can be a noticeable mismatch from that. "
Any conventions with longer or shorter periods, exponential or regular smoothing - what's the point of all this? DA takes the Bull by the horns and the Bear by the paws and feet.
Dmitry Fedoseev: It is possible not to smooth as in RSI, but the components themselves, it is a simple average. It is possible to refine my above universal indicator to enable/disable smoothing. But conceptually nothing changes.
Dmitry Fedoseev: It is possible not to smooth as in RSI, but the components themselves, it is a simple average. You can refine my above universal indicator to enable/disable smoothing. But conceptually nothing changes.
You are trying to argue with formulas with someone who speaks the language of poetry.
There will be a code in 5 mins. Keep in mind that RSI uses Wilder smoothing, which is the same as exponential smoothing but with a longer period, so there may be a noticeable mismatch.
What is there to prepare? We throw out the main buffer from RSI and put the existing two buffers in its place:
There is no smoothing there. And the calculation is different in that the strength of the bears includes the doji. That is the difference. The DA takes this into account.There will be a code in 5 mins. Keep in mind that RSI uses Wilder smoothing, which is the same as exponential but with a longer period, so there may be a noticeable mismatch.
Attached is an indicator.
Parameters:
period - period in bars;
Components - component calculation option:
Smooth - smooth method:
Power - the way the final line is calculated:
For information: final line of RSI is not smoothed, ADX is smoothed.
***
You can get RSI and ADX and various hybrids by this indicator through settings.
To get RSI:
To get ADX:
Power - enable/disable to keep components out of the way.
***
Template with two indicators as in the image from this post is also attached.
Are you backing up now?
Where's the back story? Five minutes to write a post is a lot?
...
There's no antialiasing in there....What's that? -
It's wilder smoothing. It's essentially identical to the exponential, but slower.Where's the back story? Is 5 minutes to write a post a lot?
There is no smoothing in DA and it is not required. What do you think about it?
It is possible not to smooth as in RSI, but the components themselves, it is a simple average. It is possible to refine my above universal indicator to enable/disable smoothing. But conceptually nothing changes.
Besides, you'd better show it before you speak. Why do you ask me so severely, and you blah blah blah
Where's the back story? Is 5 minutes to write a post a lot?
Any conventions with longer or shorter periods, exponential or regular smoothing - what's the point of all this? DA takes the Bull by the horns and the Bear by the paws and feet.
It is possible not to smooth as in RSI, but the components themselves, it is a simple average. It is possible to refine my above universal indicator to enable/disable smoothing. But conceptually nothing changes.
It is possible not to smooth as in RSI, but the components themselves, it is a simple average. You can refine my above universal indicator to enable/disable smoothing. But conceptually nothing changes.
You are trying to argue with formulas with someone who speaks the language of poetry.