data for bars not what it seems

 

hi,

i am a complete newby to mql and, in fact, trading in general. trying to make some sense of how this all works. i am trying my hand at writing an expert advisor script. the idea is to look at 5 minute . at present the script dumps the time, closing price and 7/21 period averages. a sample of the output i get is:

2008.07.03 16:25:09 test 4 GBPUSDm,M5: Close [210] 2008.07.03 14:25 1.9832 IMA-7 1.9836 IMA-21 1.9839
2008.07.03 16:25:05 test 4 GBPUSDm,M5: Close [209] 2008.07.03 14:25 1.9831 IMA-7 1.9836 IMA-21 1.9839
2008.07.03 16:25:04 test 4 GBPUSDm,M5: Close [208] 2008.07.03 14:25 1.9832 IMA-7 1.9836 IMA-21 1.9839
2008.07.03 16:25:04 test 4 GBPUSDm,M5: Close [207] 2008.07.03 14:25 1.983 IMA-7 1.9836 IMA-21 1.9839
2008.07.03 16:24:52 test 4 GBPUSDm,M5: Close [206] 2008.07.03 14:20 1.9831 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:24:51 test 4 GBPUSDm,M5: Close [205] 2008.07.03 14:20 1.9832 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:24:50 test 4 GBPUSDm,M5: Close [204] 2008.07.03 14:20 1.9833 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:24:44 test 4 GBPUSDm,M5: Close [203] 2008.07.03 14:20 1.9832 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:24:40 test 4 GBPUSDm,M5: Close [202] 2008.07.03 14:20 1.9834 IMA-7 1.9839 IMA-21 1.984
2008.07.03 16:24:37 test 4 GBPUSDm,M5: Close [201] 2008.07.03 14:20 1.9835 IMA-7 1.9839 IMA-21 1.984
2008.07.03 16:24:29 test 4 GBPUSDm,M5: Close [200] 2008.07.03 14:20 1.9834 IMA-7 1.9839 IMA-21 1.984

<clip>

2008.07.03 16:23:42 test 4 GBPUSDm,M5: Close [190] 2008.07.03 14:20 1.9833 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:23:38 test 4 GBPUSDm,M5: Close [189] 2008.07.03 14:20 1.9833 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:23:30 test 4 GBPUSDm,M5: Close [188] 2008.07.03 14:20 1.9832 IMA-7 1.9838 IMA-21 1.984

<clip>

2008.07.03 16:21:32 test 4 GBPUSDm,M5: Close [132] 2008.07.03 14:20 1.9833 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:21:31 test 4 GBPUSDm,M5: Close [131] 2008.07.03 14:20 1.9833 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:21:22 test 4 GBPUSDm,M5: Close [130] 2008.07.03 14:20 1.9834 IMA-7 1.9839 IMA-21 1.984
2008.07.03 16:21:21 test 4 GBPUSDm,M5: Close [129] 2008.07.03 14:20 1.9834 IMA-7 1.9839 IMA-21 1.984
2008.07.03 16:21:20 test 4 GBPUSDm,M5: Close [128] 2008.07.03 14:20 1.9834 IMA-7 1.9839 IMA-21 1.984
2008.07.03 16:21:16 test 4 GBPUSDm,M5: Close [127] 2008.07.03 14:20 1.9833 IMA-7 1.9838 IMA-21 1.984
2008.07.03 16:21:15 test 4 GBPUSDm,M5: Close [126] 2008.07.03 14:20 1.9834 IMA-7 1.9839 IMA-21 1.984

now, since i am using a 5 minute average, i am happy that i only have data at 5 minute intervals (ie. 14:20, 14:25, ...), however, what puzzles me is that the data is presented more frequently than every five minutes. i guess this is since the advisor is run roughly once every second. but what really worries me is that the closing values (from Close[]) and the moving average values calculated using something like

double SEma = iMA(Symbol(), PERIOD_M5, 7, 0, MODE_EMA, PRICE_CLOSE, 0);

change all the time. i would have thought that the (1) closing price and (2) the moving average over the last, say 7, periods should not change within a single bin. certainly the closing price changes more than the averages, but the latter do still change to some degree.

my expectation was that when i requested a 7-periods moving average using five minute data, that i would get a value based on the data for the last 35 minutes. but, since the data is based on a 5 minute chart, i thought that this value should only update every five minutes.

i would really appreciate it if somebody could set me right on this. and apologies for my naivete.

best regards,

andrew.

 

AB

> double SEma = iMA(Symbol(), PERIOD_M5, 7, 0, MODE_EMA, PRICE_CLOSE, 0);

You are going for the current position of the leading edge of this indicator line which will indeed wag up & down with current price movement.

If you want the 'snapshot' position every 5 minutes, use

double SEma = iMA(Symbol(), PERIOD_M5, 7, 0, MODE_EMA, PRICE_CLOSE, 1);

which gives the (now) fixed position of the indicator at the end of the last complete M5 period

Hope this helps

-BB-

 

thanks. i'll give that a try.

Reason: