//--- paramètres d'entrée
input ENUM_TIMEFRAMES InpPeriod1 = PERIOD_CURRENT; // Première période
input ENUM_TIMEFRAMES InpPeriod2 = PERIOD_M1; // Deuxième période
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- obtient le nombre de secondes dans les périodes du graphique InpPeriod1 et InpPeriod2
int sec1=PeriodSeconds(InpPeriod1);
int sec2=PeriodSeconds(InpPeriod2);
//--- affiche les valeurs reçues dans le journal
PrintFormat("Seconds in period %s: %lu, in period %s: %lu",TimeframeDescription(InpPeriod1),sec1,TimeframeDescription(InpPeriod2),sec2);
//--- calcule combien de barres de la période graphique InpPeriod2 sont contenues dans une barre avec la période graphique InpPeriod1
int res=sec1/sec2;
if(res==0)
res=1;
//--- affiche la valeur obtenue dans le journal
PrintFormat("One bar %s contains %d bars %s",TimeframeDescription(InpPeriod1),res,TimeframeDescription(InpPeriod2));
/*
Résultat :
Seconds in period M5: 300, in period M1: 60
One bar M5 contains 5 bars M1
*/
}
//+------------------------------------------------------------------+
//| Retourne le nom de la période |
//+------------------------------------------------------------------+
string TimeframeDescription(const ENUM_TIMEFRAMES period)
{
return(StringSubstr(EnumToString(period==PERIOD_CURRENT ? Period() : period), 7));
}
|