Momentum - why the difference?

 

Hi!


I'm using MetaTrader 4 (229).


I've noticed a difference of the values between the indicator Momentum which I would like to know the reason for (if anyone could explain).


For instance, using Alpari UK, downloaded historical data for EURUSD for Strategy Tester, opening a new chart for EURUSD M1 and applying Momentum with default values (period = 14; Apply to = Close). When I put the cursor over the following times it shows the values as follows:


4 Feb 2011 00.00 = 100.0191

4 Feb 2011 00.01 = 100.0147

4 Feb 2011 00.02 = 100.0073

4 Feb 2011 00.03 = 100.0007

4 Feb 2011 00.04 = 99.9919


But when I use the following line of code in the EA...


Print ("Momentum: ", iMomentum (NULL,0,14,PRICE_CLOSE,0));


...I get the following printed values...


11:40:31 2011.02.04 00:00 TestEA EURUSD,M1: 100.0154

11:40:31 2011.02.04 00:01 TestEA EURUSD,M1: 100.0161

11:40:31 2011.02.04 00:02 TestEA EURUSD,M1: 100.0169

11:40:31 2011.02.04 00:03 TestEA EURUSD,M1: 99.9993

11:40:31 2011.02.04 00:04 TestEA EURUSD,M1: 100.0007


Can anyone explain this?


Thanks in advance.

 

try to check if there is a difference @ bar 1 or 2 .......

 
qjol:

try to check if there is a difference @ bar 1 or 2 .......

Hmmm... I'm not sure what you mean. The first values comes from the indicator attached to the EURUSD chart and by placing the cursot over each bar. The second values comes from the printout. If I change 0 to 1 at the end of the Print, it only shows the previous bar values. It is as if they are calculated differently - the Momentum indicator and the iMomentum, which is very frustrating.


Please give it a try:


Compare the values from the indicator Momentum with the printed values from iMomentum, using the same applied price constanst with the same currency pair av period. The values differs! And why do they differ?

 

What you see when hovering cursor over indicator window is the value corresponding to the last tick (Close) of the respective bar.

What you see in your printout are values corresponding to different ticks of the current bar, as they (ticks) come in.

To print times and values for the last 10 bars:

for (i=10;i>=0;i--) {
Print(Time[i]," - ",iMomentum(NULL,0,14,PRICE_CLOSE,i));
}

(hope I got the syntax right, I'm on Linux atm :)

 
I've noticed that the 'hovering box with info at cursor location' is often 1 bar out, and that the Data Window is actually displaying the correct value.
 

Drave: I'm not convinced about that since I let the program code await for new bars as follows...

if (NewBar()) // Wait for new bar to close

Print ("Momentum (PRICE_CLOSE): ", iMomentum(NULL,0,14,PRICE_CLOSE,0));

...

bool NewBar ()
{

static datetime LastTime = 0;
if (Time[0] != LastTime)
{
LastTime = Time[0];
return (true);
}
else
return (false);

}


...and if I remove the NewBar call it will printout the same value for iMomentum, but as many times as there are tics (and this is because the historical data does not caintin tic data, but if I would run it on live data then I would expect to get printouts corresponding to each tic).



Drave:

What you see when hovering cursor over indicator window is the value corresponding to the last tick (Close) of the respective bar.

What you see in your printout are values corresponding to different ticks of the current bar, as they (ticks) come in.

To print times and values for the last 10 bars:

(hope I got the syntax right, I'm on Linux atm :)

Reason: