Ema of Previous Bar - page 2

 

Dear Sirs,

For example I use the iMA command to find Ema at Time 1:00,2.00:3:00 and 4:00 to be 1.234,1.334,1.445,1.446 respectively.

So at Time 3:00 I use  iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)  to find the Ema at Time 2:00. Does it mean the value I find using iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) shall be exactly =1.334?

 I am not sure my logic is correct?

 
chuale: 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?

An EMA (Exponential Moving Average), does not have a "real period" per se, but rather a conversion of the "period" into a weight which is exponentially applied along ALL bars up to and including the "bar shift" referenced in the iMA() function. However, for better understanding, please read the referenced documentation:

 

Dear Skrs,

Final Clarification. 

 Ema for H1  at Time 1:00,2.00:3:00 and 4:00 are 1.234,1.334,1.445,1.446 respectively which is value used in the drawing of ema H1 indicator line in the chart window.

My question:

 iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) at time 4:00, 3:00 and 2:00 will it give the value of 1.445,1.334 and 1.234 respectively? 

Hope you can enlightened me.

Thank you. 

 

I don't think that it can be clarified any more than it has been explained to you already.

Why don't you simply print the ema values and compare them to the chart?

 
GumRai:

I don't think that it can be clarified any more than it has been explained to you already.

Why don't you simply print the ema values and compare them to the chart?

Yes, I have printed the value and it is same as the chart.  So I mean the value of these ema values are unchanged. So my reasoning is if I use iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) to find the ema value of one hour earlier  it shall be tally with all these ema value output.

 

Regards 

 
chuale: So my reasoning is if I use iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) to find the ema value of one hour earlier  it shall be tally with all these ema value output.

Is that not what I wrote on my very first post? (and I quote):

... 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.

 

Dear Brothers,

These previous bars is for my indicator coding. You see  if I use iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) to get the value of the ema value of the previous bar, the value simply does not tally witht the output using  iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0).

Simple illustration

Time         iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0)       iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)     

1:00                                   X1                                                                                Y1

2:00                                   X2                                                                                Y2

3:00                                  X3                                                                                 Y3

4:00                                  X4                                                                                 Y4

 

Logically it should be Y4=X3, Y3=X2 , Y2=X1 but it is not, I cannot understand why it is as such? 

 

I don't know if it is possible to explain it more simply than it already has been explained.

At 1:00 the bar has only just opened so an ma(PRICE_CLOSE) referencing shift 0 will return the value  at 1:00 XX seconds.

At 2:00 an ma(PRICE_CLOSE) referencing shift 1 will return the value  at 1:59 XX seconds. ie the final value for when the 1:00 bar closed.

 
chuale: if I use iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) to get the value of the ema value of the previous bar, the value simply does not tally witht the output using  iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0).
  1. if it was equal then you would have a straight line.
  2. It will be close only on the first tick, and continuously move away as the new bar forms.
  3. Time
    IMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0) 
     iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)
    1:00
    ~X1
    X1
    1:59:59
    X2
    X1
    2:00
    ~X2
    X2
    2:59:59
    X3
    X2
    3:00
    ~X3X3
    3:59:59
    X4X3
    4:00
    ~X4X4

 
chuale: You see  if I use iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1) to get the value of the ema value of the previous bar, the value simply does not tally witht the output using  iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0).

Let me make this more clear for you:

Yes, that is correct - It will NEVER "tally" - It will ALWAYS be DIFFERENT.


Do the following experiment - compare the "iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,2)" with the "iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1)" in the same way you did for bar shifts "1" and "0", but now for "2" and "1".

Now, you will see that they will always "tally", because for bar shifts "0", things work differently as already explained.

Here is a graphical explanation, that hopefully you will understand:

Bar Shift "0"
Current Bar

Time: 00:00:02

Open = 1.13911
High = 1.13911
Low = 1.13911
Close = 1.13911
Bar Shift "0"
Current Bar

Time: 00:54:33

Open = 1.13911
High = 1.13961
Low = 1.13784
Close = 1.13811
Bar Shift "1"
Previous Bar

Time: 01:02:30

Open = 1.13911
High = 1.13961
Low = 1.13784
Close = 1.13800