need help mq4

 

Hello guys, i am new to mql4 and trying to learn the basics. i was checking the code of Laguerre RSI(given below). But when i tried to test the code, by taking values manually, then i am not getting the value shown by the indicator.

i went to 1 hour chart of EU. Took 5 bars.

The current bar as L0[901].

The closing price(in formula) as Close[901] (same bar as above i.e. L0[901])

L1[901] as one bar previous to L0[901].

L2[901] as one bar previous to L1[901].

L3[901] as one bar previous to L2[901].

Then considered one more bar previous to L3[901], for taking the value L3[902] from it.


+++++++++++++++++++++++++++++++++++++++++++

e.g.
16th May 2011, EURUSD, 1 hour chart, time = 21pm bar.


L0[901] = 1.4142 (current bar)
L1[901]= 1.4158 (previous to above bar)
L2[901]= 1.4144 (previous to above bar)
L3[901]= 1.4158 (previous to above bar)
one more value = 1.4160 (previous to above bar)


calculated these values(after manually putting above values in the for loop given in code):
L0= 1.4154
L1= 1.4150
L2= 1.4150

L3= 1.4165


But i am getting a wrong answer via manual calculations. Where am i going wrong? Can someone please explain?


i took BARS = 1000 and counted_bars = 99.

i did only one iteration(which i think will give me Laguerre RSI value for current bar). But as i was getting it wrong(via manual calculations), i stopped going further.

+++++++++++++++++++++++++++++++++++++++++++




Here is the code:


#property indicator_separate_window
#property indicator_level2 0.75
#property indicator_level3 0.45
#property indicator_level4 0.15
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 MediumPurple

//---- input parameters
extern double gamma=0.55;

//---- buffers
double RSI[];
double L0[];
double L1[];
double L2[];
double L3[];

int init()
{
IndicatorBuffers(5);
//---- indicators
SetIndexStyle(0, DRAW_LINE);
SetIndexDrawBegin(0, 1);
SetIndexLabel(0, "Laguerre RSI");
SetIndexEmptyValue(0, -0.01);
SetIndexBuffer(0, RSI);
SetIndexBuffer(1, L0);
SetIndexBuffer(2, L1);
SetIndexBuffer(3, L2);
SetIndexBuffer(4, L3);
//----
string short_name="LaguerreRSI(" + DoubleToStr(gamma, 2) + ")";
IndicatorShortName(short_name);
return(0);
}


int deinit()
{
return(0);
}

//+------------------------------------------------------------------+
//| iteration
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
double CU, CD;
//---- last counted bar will be recounted
if (counted_bars>0)
counted_bars--;
else
counted_bars = 1;
limit = Bars - counted_bars;
//---- computations for RSI
for (int i=limit; i>=0; i--)
{
L0[i] = (1.0 - gamma)*Close[i] + gamma*L0[i+1];
L1[i] = -gamma*L0[i] + L0[i+1] + gamma*L1[i+1];
L2[i] = -gamma*L1[i] + L1[i+1] + gamma*L2[i+1];
L3[i] = -gamma*L2[i] + L2[i+1] + gamma*L3[i+1];
//Print(i," Close[i]=",Close[i],", (1.0 - gamma)*Close[i]=",(1.0 - gamma)*Close[i],", gamma*L0[i+1]=",gamma*L0[i+1]);
//Print(i," L0=",L0[i],",L1=",L1[i],",L2=",L2[i],",L3=",L3[i]);

CU = 0;
CD = 0;
if (L0[i] >= L1[i])
CU = L0[i] - L1[i];
else
CD = L1[i] - L0[i];
if (L1[i] >= L2[i])
CU = CU + L1[i] - L2[i];
else
CD = CD + L2[i] - L1[i];
if (L2[i] >= L3[i])
CU = CU + L2[i] - L3[i];
else
CD = CD + L3[i] - L2[i];

if (CU + CD != 0)
RSI[i] = CU / (CU + CD);
}
return(0);
}






 

There are so many great coders in this forum. Can someone guide me as to where am i going wrong?


Is my bar selection correct? L0,L1,L2,L3

 
Plz can someone reply, i really need your guidance! There are so many great coders on this forum, plz do reply to my querry
 

  1. limit = Bars - counted_bars;
    //---- computations for RSI
    for (int i=limit; i>=0; i--)
    {
        L0[i] = (1.0 - gamma)*Close[i] + gamma*L0[i+1];
    On the initial start counted_bars is zero so limit = Bars and the code updates L0[Bars] and references L0[Bars+1] neither of which exist. Only L0[0]..L0[Bars-1]
  2. Don't know if the rest of the code is correct since you didn't point to any reference to "Laguerre RSI"
 

The code is same as here:

https://www.mql5.com/en/code/mt4


is it not the right code for Laguerre RSI?

 

"On the initial start counted_bars is zero so limit = Bars and the code updates L0[Bars] and references L0[Bars+1] neither of which exist. Only L0[0]..L0[Bars-1]"

So it means initially the counted_bars =0. Limit = bars..

L0[0] exists (i.e. current bar).

L0[bars - 1] exists (i.e. previous bar to current bar).


So does it mean the above code calculates in reverse direction in this case? That is from current bar to first bar?

 
thestockbull:So does it mean the above code calculates in reverse direction in this case? That is from current bar to first bar?
No the loop is counting down. The earliest bars are garbage, how quickly it converges to valid values I don't know.
thestockbull 2011.05.25 07:49

The code is same as here: https://www.mql5.com/zh/code/7834

is it not the right code for Laguerre RSI?
Pointing at the same code from a different location doesn't say whither the code is correct. Only comparing the code to the corresponding MATH can answer the question.
 

guys help!! how to count bars in Laguerre RSI?