- for (iPeriod=h1, iPeriod <=mn1, iPeriod++){
You can’t do that because Chart Timeframesare not consecutive. Incrementing PERIOD_H1 (60) give 61 not PERIOD_H2 (120). You need to create appropriate functions.
MT$ Code:
/** @defgroup tf Time Frames
* A simple enumeration of time frames and related functions.
* @{ */
/** Whereas `ENUM_TIMEFRAMES` is all timeframes (supported and unsupported,) but
* it can't be incremented because it's values is number of minutes,
* (incrementing M30 would be M31 not H1.) This is a simple enumeration
* (incrementing this results in the next one.) */
enum Timeframe{ TF_CURRENT, ///< Place holder for the EA attached chart.
TF_M1, TF_M2, TF_M3, TF_M4, TF_M5, TF_M6,
TF_M10, TF_M12, TF_M15, TF_M20, TF_M30, TF_H1,
TF_H2, TF_H3, TF_H4, TF_H6, TF_H8, TF_H12,
TF_D1, TF_W1, TF_MN1};
const Timeframe TF_FIRST = TF_M1; ///< Smallest supported Timeframe.
const Timeframe TF_Last = TF_MN1; ///< Largest supported Timeframe.
#define TF_COUNT TF_MN1 /**< Number of supported Timeframe%s
* not including the @ref TF_CURRENT marker. */
// For converting between periods (as_period) and timeframes (as_timeframe.)
/// @cond Skip
const ENUM_TIMEFRAMES gcPeriods[]={ PERIOD_CURRENT,
PERIOD_M1, PERIOD_M2, PERIOD_M3, PERIOD_M4, PERIOD_M5, PERIOD_M6,
PERIOD_M10, PERIOD_M12, PERIOD_M15, PERIOD_M20, PERIOD_M30, PERIOD_H1,
PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6, PERIOD_H8, PERIOD_H12,
PERIOD_D1, PERIOD_W1, PERIOD_MN1};
/// @endcond
/// Convert a period to a timeframe.
Timeframe as_timeframe(ENUM_TIMEFRAMES period=PERIOD_CURRENT){
if(period == PERIOD_CURRENT) period = (ENUM_TIMEFRAMES) _Period;
Timeframe tf = TF_M1; while(gcPeriods[tf] < period) ++tf;
return tf;
}
/// Convert a timeframe to a period;
ENUM_TIMEFRAMES as_period(Timeframe tf){ return gcPeriods[tf]; }
/** Returns the next larger timeframe. Larger timeframes should be 5 times
* larger (approximately,) but M5 to M15 is 3, and M15 to M30 and M30 to H1 is
* only 2. So for those I skip two sizes. H1 to H4 is 4 so I allow that. */
Timeframe larger(Timeframe tf){
static const Timeframe larger[] = { WRONG_VALUE,
// TF_M1, TF_M2, TF_M3, TF_M4, TF_M5, TF_M6,
TF_M5, TF_M10, TF_M15, TF_M20, TF_M30, TF_M30,
// TF_M10, TF_M12, TF_M15, TF_M20, TF_M30, TF_H1,
TF_H1, TF_H1, TF_H1, TF_H2, TF_H2, TF_H4,
// TF_H2, TF_H3, TF_H4, TF_H6, TF_H8, TF_H12,
TF_H12, TF_H12, TF_D1, TF_D1, TF_D1, TF_D1,
// TF_D1, TF_W1, TF_MN1
TF_W1, TF_MN1, WRONG_VALUE};
return larger[tf];
}
ENUM_TIMEFRAMES next_larger(ENUM_TIMEFRAMES period){
return as_period(as_timeframe(period) + 1);
}
// defgroup tf Time Frames
/// @}