iMACD shift parameter

 

Hi,

I'm newbie to MQL, and there is something I don't understand in the iMACD function.

It has a "shift" parameter which is, according to the docs, "Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago)." I believe all the indicators have this parameter.

When giving this parameter the value 0, what exactly is its value? The parameter 0 indicates I want the indicator value for the current bar I'm in, but, for example, when calculating the MACD with PRICE_CLOSE, the "close" value of the bar is not known yet. What will it show then?

And just to make sure - when the "shift" is greater than 0, it will show the correct value of the previous bars. Is that correct?

Many thanks!

 

M

You are correct, the shift=0 refers to the current bar thats in progress.

The PRICE_CLOSE refers to the method of calculation - do not worry about that.

As you've guessed the value of the current MACD line waves up & down with price movement during the bar formation.

On close of the bar, the position of the MACD line is fixed & becomes accessible from shift=1, i.e. <the last complete bar>

> when the "shift" is greater than 0, it will show the correct value of the previous bars?

Yes thats it :)

-BB-

 
BarrowBoy:

M

You are correct, the shift=0 refers to the current bar thats in progress.

The PRICE_CLOSE refers to the method of calculation - do not worry about that.

As you've guessed the value of the current MACD line waves up & down with price movement during the bar formation.

On close of the bar, the position of the MACD line is fixed & becomes accessible from shift=1, i.e. <the last complete bar>

> when the "shift" is greater than 0, it will show the correct value of the previous bars?

Yes thats it :)

-BB-

Wow, that was quick!

Many thanks, BB!

 
BarrowBoy:

M

You are correct, the shift=0 refers to the current bar thats in progress.

The PRICE_CLOSE refers to the method of calculation - do not worry about that.

As you've guessed the value of the current MACD line waves up & down with price movement during the bar formation.

On close of the bar, the position of the MACD line is fixed & becomes accessible from shift=1, i.e. <the last complete bar>

> when the "shift" is greater than 0, it will show the correct value of the previous bars?

Yes thats it :)

-BB-

One more question, if you don't mind:

When retrieving the MACD value on new bar opening, if I'm using shift=0 and price applied is PRICE_OPEN, will I get the correct MACD for the current bar (which, I suppose, should be the MACD with the open price of the bar).

 

M

The Applied price enumeration values are part of the method of calculation, and are not an aspect of time-frame, so use PRICE_CLOSE throughout.
Using PRICE_OPEN of the current will not give you the MACD opening position at the start of the bar.
If you really want that, you will have to use the MACD value of the last closed bar (this will be correct 99% of the time).

The snag with MACD on the current bar is that it will wave around during the bar, giving false crossing signals :(

IMHO - use the iOSMA - its easier to program.

And wait for the close of the bar?

-BB-

 
BarrowBoy:

M

The Applied price enumeration values are part of the method of calculation, and are not an aspect of time-frame, so use PRICE_CLOSE throughout.
Using PRICE_OPEN of the current will not give you the MACD opening position at the start of the bar.
If you really want that, you will have to use the MACD value of the last closed bar (this will be correct 99% of the time).

The snag with MACD on the current bar is that it will wave around during the bar, giving false crossing signals :(

IMHO - use the iOSMA - its easier to program.

And wait for the close of the bar?

-BB-

Mmm... Never used the iOSMA. I'll give it a shot.

Thanks for the info!

Reason: