difference between offset and index

 

can anyone tell me what's difference between:


iMA(NULL, 0, MY_LENGTH, 2, MODE_EMA, PRICE_LOW, i);


iMA(NULL, 0, MY_LENGTH, 0, MODE_EMA, PRICE_LOW, i+2);


dont they return the same value?



why does offset exists at all, as we can just put i+2 in index?

 

In the first, you are retrieving the MA value for bar index i

In the 2nd you are getting the value from 2 bars earlier

This would be for when you require the values for both i and I+2

 
Keith Watford:

In the first, you are retrieving the MA value for bar index i

In the 2nd you are getting the value from 2 bars earlier

This would be for when you require the values for both i and I+2


thannks, but have you read the the codes closely? there are two differences, please re-read.
 
selnomeria:

thannks, but have you read the the codes closely? there are two differences, please re-read.


Oh I see, I didn't notice the 1st MA is shifted 2.

Yes, they should return the same.

I guess that if you are using a shifted EA on your chart, it makes it less likely to make an error in your code if you have the shift in the iMA call.

 
selnomeria: why does offset exists at all, as we can just put i+2 in index?
  1. Makes no difference in iMA
  2. Makes a difference if you put a MA on a chart and want to see it shifted.
Reason: