Download MetaTrader 5

Definition of "indicator buffer"

To add comments, please log in or register
mstroth
12
mstroth  

Hello,

I am currently working on scripting an EA. I came to the point, where I need to know, what exactly the indicator buffer stands for.

Here is an example:

double  iMA(
   string       symbol,           // symbol
   int          timeframe,        // timeframe
   int          ma_period,        // MA averaging period
   int          ma_shift,         // MA shift
   int          ma_method,        // averaging method
   int          applied_price,    // applied price
   int          shift             // shift

   );

The last variable "shift" indicates the indicator buffer. I couldn't find a proper definition yet.  

I would be very happy, if you could help me.

Thanks a lot in advance! 

 

Regards, 

Marko 

honest_knave
Moderator
2342
honest_knave  

shift is not the indicator buffer. They are totally different things and unrelated in this context.

shift is the bar index. 

So, for MQL4:

shift 0 = the current bar

shift 1 = the previous bar

shift 2 = the bar before that 

and so on.

 

You may be getting confused with iCustom. 

mstroth
12
mstroth  
honest_knave:

shift is not the indicator buffer. They are totally different things and unrelated in this context.

shift is the bar index. 

So, for MQL4:

shift 0 = the current bar

shift 1 = the previous bar

shift 2 = the bar before that 

and so on.

 

You may be getting confused with iCustom. 

Thanks a lot honest_knave!

 I was confused because of the explanation of this variable:

[in]  Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).

 

That means then, I can pick up all the single values within an (e.g.) 20 day EMA using this shift function?  

honest_knave
Moderator
2342
honest_knave  

OK, I see what they have done there in the documentation, and I can see why it is confusing if you then read up on indicator_buffers.

This may help:

[in]  Index of the value taken from the iMA buffer (shift relative to the current bar the given amount of periods ago). 

To cut straight to your answer: Yes, you can e.g. the last 3 bars' 20 EMA values

double MA0 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE,0);
double MA1 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE,1);
double MA2 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE,2);
mstroth
12
mstroth  
honest_knave:

OK, I see what they have done there in the documentation, and I can see why it is confusing if you then read up on indicator_buffers.

This may help:

[in]  Index of the value taken from the iMA buffer (shift relative to the current bar the given amount of periods ago). 

To cut straight to your answer: Yes, you can e.g. the last 3 bars' 20 EMA values

double MA0 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE,0);
double MA1 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE,1);
double MA2 = iMA(_Symbol,0,20,0,MODE_EMA,PRICE_CLOSE,2);

Hello honest_knave,

thanks for your quick reply. That helps a lot!

 

Regards,

Marko 

To add comments, please log in or register