//--- 입력 매개변수
input ENUM_TIMEFRAMES InpPeriod1 = PERIOD_CURRENT; // First Period
input ENUM_TIMEFRAMES InpPeriod2 = PERIOD_M1; // Second Period
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- InpPeriod1 및 InpPeriod2 차트 기간의 초의 수를 가져옵니다.
int sec1=PeriodSeconds(InpPeriod1);
int sec2=PeriodSeconds(InpPeriod2);
//--- 수신된 값을 로그에 표시합니다.
PrintFormat("Seconds in period %s: %lu, in period %s: %lu",TimeframeDescription(InpPeriod1),sec1,TimeframeDescription(InpPeriod2),sec2);
//--- 차트 기간이 InpPeriod1인 바에 포함된 InpPeriod2 차트 기간의 바의 수를 계산합니다.
int res=sec1/sec2;
if(res==0)
res=1;
//--- 얻은 값을 로그에 표시합니다.
PrintFormat("One bar %s contains %d bars %s",TimeframeDescription(InpPeriod1),res,TimeframeDescription(InpPeriod2));
/*
Result:
Seconds in period M5: 300, in period M1: 60
One bar M5 contains 5 bars M1
*/
}
//+------------------------------------------------------------------+
//| 차트 주기명 반환 |
//+------------------------------------------------------------------+
string TimeframeDescription(const ENUM_TIMEFRAMES period)
{
return(StringSubstr(EnumToString(period==PERIOD_CURRENT ? Period() : period), 7));
}
|