Download MetaTrader 5

Ema of Previous Bar

To add comments, please log in or register
chua le
235
chua le  
2016.08.02 13:00  Indicator USDCAD,H1: USDCAD H1 Ema20:Ema201= 1.3105:1.3108
2016.08.02 12:00  Indicator USDCAD,H1: USDCAD H1 Ema20:Ema201= 1.3110:1.3110
2016.08.02 11:00  Indicator USDCAD,H1: USDCAD H1 Ema20:Ema201= 1.3111:1.3110



Dear All,

Above show the  EMA 20 (Ema20 is current bar and EMA201 is previous bar) from time 10.00 to 13.00.

I would like to know why the value of the ema previous bar (1.3108) for time 13:00 is different from the ema current bar for time 12:00 (1.3110). Also compare 1.3110(Ema201) to 1.3111(Ema20). I have other output which different by 0.009. Because of the minor different in value it affect my results tremendously.

By right both the ema for previous bar of the current time (EMA201) shall be exactly the same for the current bar for the previous time (EMA20).

Please help to explain or did I assume the wrong meaning of SHIFT of 1 in Ema201 = iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,1)?

Does it mean that   iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,1) at time 13:00 is SAME AS   iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,0) at tme 12.00?

 

Thanks 

Fernando Carreiro
3381
Fernando Carreiro  

When obtaining the EMA (or any other indicator value), for the current bar, the value will always be in flux and constantly changing because the bar is still incomplete and the Close price constantly updates to reflect the latest incoming tick price. It is only when the current bar finally ends with a final closing price that the EMA for that bar becomes stable.

So at the very beginning of an H1 Bar (current bar), the Open, High, Low and Close are all the same price, because there is only one tick of volume. As time goes by and more ticks come in, you will get more differentiated prices and the High and Low will diverge and the Close will update the latest price (and the EMA changes). Finally the Bar ends and a new one is formed, thus the current becomes the previous bar, and the whole cycle begins again.

That is why the EMA of the Previous Bar at 13:00 will almost never be the same as the EMA of the same bar at 12:00 when it was first opened. This is also the reason why you should always try to trade based on Indicator values of the previous bar and never based on the current bar.

chua le
235
chua le  

Thank you for the repy.

 

But I am using MODE_EMA,PRICE_CLOSE, which is the close price so since the value of EMA base on close price it shall not change again right ? 

Fernando Carreiro
3381
Fernando Carreiro  
chuale: But I am using MODE_EMA,PRICE_CLOSE, which is the close price so since the value of EMA base on close price it shall not change again right ? 

NO, that is NOT right!

Did you not read what I just wrote? I purposely explained it in very simple terms so you would understand.

On current Bar [CLOSE Price] = [Current Price]. Thus CLOSE price is continually changing on the current Bar, so the EMA of current bar is also constantly changing!

The ONLY price that does NOT CHANGE on the current bar, is the OPEN price.

chua le
235
chua le  
2016.08.02 13:00  Indicator USDCAD H1 Ema51= 1.3105
2016.08.02 12:00  Indicator USDCAD H1 Ema51= 1.3115
2016.08.02 11:00  Indicator USDCAD H1 Ema51= 1.3117

2016.08.02 13:00  Indicator USDCAD H1 Ema5= 1.3098
2016.08.02 12:00  Indicator USDCAD H1 Ema5= 1.3114
2016.08.02 11:00  Indicator USDCAD H1 Ema5= 1.3117

For time 12:00, value obtained using iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0)=1.3114
For time 12:00, value obtained using iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)=1.3105 (At time 13:00 Ema for previous bar is Ema for time 12:00)

For time 11:00, value obtained using iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0)=1.3117
For time 11:00, value obtained using iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)=1.3115 (At time 13:00 Ema for previous bar is Ema for time 12:00)

Thank you for the reply.

My question is why the value obtained using  iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,0) and iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,1) giving different values? As shown above, at 12.00, the value shall be 1.3114 not 1.3105 which different by 9 pips?

Logically Ema value for iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0) at 12:00 shall be exactly the same as the Ema of previous bar iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) at 13:00. 

Regards

CH 

Keith Watford
Moderator
10570
Keith Watford  
chuale:

Thank you for the reply.

My question is why the value obtained using  iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,0) and iMA(NULL,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,1) giving different values? As shown above, at 12.00, the value shall be 1.3114 not 1.3105 which different by 9 pips?

Logically Ema value for iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0) at 12:00 shall be exactly the same as the Ema of previous bar iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) at 13:00. 

Regards

CH 

 

It has already been explained to you, but you are not taking notice

Look at any ema on any chart and you will see the value of the ema on the current bar change until the bar closes.

chua le
235
chua le  
GumRai:

It has already been explained to you, but you are not taking notice

Look at any ema on any chart and you will see the value of the ema on the current bar change until the bar closes.

chua le
235
chua le  

Dear Sirs,

I try to figure it out. Thanks 

Fernando Carreiro
3381
Fernando Carreiro  
chuale: I try to figure it out. Thanks

I suggest you first to some research into the basics of Forex trading, specially OHLC Bar or Candlestick charts, before attempting to code your own EA or Indicator.

Carl Schreiber
7464
Carl Schreiber  

What about:

   prevEMA = (actEMA - c*actPrice)/ (1 - c); // ;)
chua le
235
chua le  

Dear Sirs,

 

I have done the research.   

Does iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)  means EMA for the recent 5 bars up to previous bar? 

Does iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0) means EMA for the recent 5 bars up to present bar?

Regards

123
To add comments, please log in or register