English

## iStdDev - Understanding the Options

 2 MelesMeles 2015.11.21 12:19   Hi all, I've googled quite a bit on this, and am really struggling to understand the iStdDev inputs while creating an EA.  Help from the brains of the forum would be most appreciated!Here's the way I expected iStdDev to work:For the function call:double StdDevCurrent = iStdDev(NULL,PERIOD_H2,30,30,0,0,0);I thought it would do the following:NULL - On the current symbolPERIOD_H2 - Over the range of the previous two hours30,30,0,0 - Take the value at close every 30 seconds and calculate StdDev using simple arithmetic mean0 - Perform this with 0 offset from the current time But I'm doubting myself, and would really appreciate if someone could tell me whether I've got this line correct?
 2017 gooly 2015.11.21 13:42 #   I think you find what you are looking for in the editors reference - look for iStdDev()
12998
WHRoeder 2015.11.21 13:50 #

1. Mt4 does not support all timeframes, M1, M5, M15, M30, H1, H4, D1, Wk1, M1. Only Mt5 supports H2
2.  Don't hard code numbers. `double StdDevCurrent = iStdDev(NULL,PERIOD_H2,30,30,0,0,0);` Use the enumerations. `double StdDevCurrent = iStdDev(NULL,PERIOD_H2,30,30,MODE_SMA,PRICE_CLOSE,0);`
3. 30,30,0,0 - Take the value at close every 30 seconds and calculate StdDev using simple arithmetic mean
RTFM 30=The period (30 H2 bars). 30 = value shifted 30 periods into the future, 0,0 above.
2
MelesMeles 2015.11.22 14:05 #

WHRoeder:
1. Mt4 does not support all timeframes, M1, M5, M15, M30, H1, H4, D1, Wk1, M1. Only Mt5 supports H2
2.  Don't hard code numbers. Use the enumerations.
3. 30,30,0,0 - Take the value at close every 30 seconds and calculate StdDev using simple arithmetic mean
RTFM 30=The period (30 H2 bars). 30 = value shifted 30 periods into the future, 0,0 above.

Hi WHRoeder,

Thanks for the response, I do appreciate the guidance.  My problem was that I'd Read The Fabulous Manual, but didn't understand what the short two-word description of each option meant.  The lack of examples and guidance was worrying me.

So a few follow-up questions:

In MQL4, is it possible to have the EA look at a 2 Hour timeframe?

If I am trying to have it look at 2 hour's worth of 30-second bars, it seems then that I'm doing this completely wrong.  What would be the right way around?

Also - is there a more detailed documentation of the functions and what they mean?  I fear that as I'm new to MQL, the short explanations in the help guide don't always mean very much to me.

 1324 jjc 2015.11.22 15:20 #   MelesMeles: In MQL4, is it possible to have the EA look at a 2 Hour timeframe? If I am trying to have it look at 2 hour's worth of 30-second bars, it seems then that I'm doing this completely wrong.  What would be the right way around?MT4 doesn't have history data more fine-grained than M1. The timeframes which it supports are those you can see on the toolbar in the user interface: M1, M5, M15, M30, H1, H4, D1, W1, MN1.You can't do any kind of calculation involving 30-second bars because MT4 doesn't have history data of sufficient detail.It would be possible, if cumbersome, to go upwards in terms of timeframes. For example, if you wanted to do a calculation on an unsupported period such as M3 or H2, then you could get the history data for a lower timeframe (e.g. M1 or H1); aggregate the history into the bars you wanted (e.g. combining each three M1 bars into an M3 bar); and then do a calculation such as standard deviation on your own bar data.In some such cases MQL4 would provide a handy function which would do the calculation for you, e.g. iStdDevOnArray() which you could use to calculate standard deviation from your own array of aggregated bar data. In other cases, e.g. ATR, you would have to implement the whole calculation yourself as well because there is no "array-version" of the relevant function which you want to use, e.g. no iATROnArray() function.
 1324 jjc 2015.11.22 15:27 #   jjc: You can't do any kind of calculation involving 30-second bars because MT4 doesn't have history data of sufficient detail. [...]if MT4 did have 30-second bar data, then the syntax for a standard deviation calculation on "two hours' worth" would be as follows:iStdDev(Symbol(), PERIOD_S30, 240, 0, MODE_SMA, PRICE_CLOSE, 0)... where 240 is the number of 30-second bars in a two-hour period.I agree that bare descriptions in the documentation such as "Moving Average period" aren't super-helpful. However, they're perhaps being precise. The documentation could say something like "Number of bars to include" instead of "Moving Average period", but that wouldn't be a strictly accurate description when using a type of moving average such as EMA or SMMA.
 1324 jjc 2015.11.22 15:39 #   jjc: iStdDev(Symbol(), PERIOD_S30, 240, 0, MODE_SMA, PRICE_CLOSE, 0)... and being very pedantic, the above doesn't necessarily mean "the last 2 hours". It would be saying "do a calculation on the last 240 bars of 30-seconds", which isn't guaranteed to be the same thing. If there had been any periods of 30-seconds during the last 2 hours when there had been no ticks, then there would be no S30 bars in the history for those quiet periods. Simply going back 240 bars would then extend beyond the last 2 hours.