difference between iRSI result and it's indicator?

 

Hello

Why are there some differences between iRSI result and it's indicator where all parameters are same ?

of course I have same issue with other i-Functions specially iCustom


Thanks in advanced


Indicator Code

 lengthRSI=14;



OnCalculate(...){

 for(int i=(rates_total-prev_calculated-1);i>=0;i--)
   {  
    rsi1[i]=iRSI(Symbol(),Period(),lengthRSI,PRICE_CLOSE,i);
   }

}
Files:
Differ.jpg  30 kb
 

its happens to me, that if i define 

input int RSI_Timeframe = 15;

double RSI0 = iRSI(NULL,RSI_Timeframe,RSI_Period,PRICE_CLOSE,0);  

i get those differences

but with :

 double RSI0 = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,0);

or

 double RSI0 = iRSI(NULL,PERIOD_XX ,RSI_Period,PRICE_CLOSE,0);

dont

Mql4 anoyances, that brings make profit closer to imposible...

 
Ricardo Andres Moscoloni:

its happens to me, that if i define 

input int RSI_Timeframe = 15;

double RSI0 = iRSI(NULL,RSI_Timeframe,RSI_Period,PRICE_CLOSE,0);  

i get those differences

but with :

 double RSI0 = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,0);

or

 double RSI0 = iRSI(NULL,PERIOD_XX ,RSI_Period,PRICE_CLOSE,0);

dont

Mql4 anoyances, that brings make profit closer to imposible...

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.


Not necessarily related to your problem, but

input int RSI_Timeframe = 15;
double RSI0 = iRSI(NULL,RSI_Timeframe,RSI_Period,PRICE_CLOSE,0);  

ideally, you should not use an int to represent a time-frame. Use the enum.

input ENUM_TIMEFRAMES RSI_Timeframe = PERIOD_M15;

It has the added advantage of giving you a nice drop-down list in the inputs.


As you don't show how you compare the various iRSI results, we can't really help you.

I will address the OP's issue in the next post.

 
BmV:

Hello

Why are there some differences between iRSI result and it's indicator where all parameters are same ?

of course I have same issue with other i-Functions specially iCustom

 lengthRSI=14;

OnCalculate(...){

 for(int i=(rates_total-prev_calculated-1);i>=0;i--)
   {  
    rsi1[i]=iRSI(Symbol(),Period(),lengthRSI,PRICE_CLOSE,i);
   }
}

Thanks in advanced

The problem is here

for(int i=(rates_total-prev_calculated-1);i>=0;i--)

This will not work correctly for new ticks.

After the initial call to OnCalculate() let's say that rates-total=1000 and prev_calculated=1000

rates-total - prev_calculated - 1 

1000 -  1000  - 1 = -1

so the loop will not be executed.

When a new bar opens  rates-total will be increased by 1 but prev_calculated will not be increased until the next tick.

1001 -  1000  - 1 = 0

So, the first tick of a new bar, the current bar will be updated, but not on subsequent ticks.

This means that the iRSI value is actually showing the RSI value at bar open, not close.

 
 for(int i=(rates_total-prev_calculated-1);i>=0;i--)

See How to do your lookbacks correctly #9 - #14 & #19.

Reason: