Download MetaTrader 5

difference between offset and index

To add comments, please log in or register
selnomeria
254
selnomeria  

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?

Keith Watford
Moderator
8293
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

selnomeria
254
selnomeria  
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.
Keith Watford
Moderator
8293
Keith Watford  
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.

whroeder1
17116
whroeder1  
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.
To add comments, please log in or register