//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 날짜는 일요일입니다.
datetime time=D'2002.04.25 12:00';
string symbol="GBPUSD";
ENUM_TIMEFRAMES tf=PERIOD_H1;
bool exact=false;
//--- 지정된 시간에 막대가 없으면 iBarShift가 가장 가까운 막대의 색인을 반환합니다.
int bar_index=iBarShift(symbol,tf,time,exact);
//--- iBarShift() 호출 후 오류 코드를 확인하십시오.
int error=GetLastError();
if(error!=0)
{
PrintFormat("iBarShift(): GetLastError=%d - The requested date %s "+
"for %s %s는 가용한 내역에서 찾을 수 없습니다",
error,TimeToString(time),symbol,EnumToString(tf));
return;
}
//--- iBarShift() 기능이 성공적으로 실행되었습니다. exact=false에 대한 결과를 반환합니다.
PrintFormat("1. %s %s %s(%s): bar index is %d (exact=%s)",
symbol,EnumToString(tf),TimeToString(time),
DayOfWeek(time),bar_index,string(exact));
datetime bar_time=iTime(symbol,tf,bar_index);
PrintFormat("Time of bar #%d is %s (%s)",
bar_index,TimeToString(bar_time),DayOfWeek(bar_time));
//--- 지정된 시간으로 막대 색인을 요청합니다; 막대가 없으면 -1이 반환됩니다.
exact=true;
bar_index=iBarShift(symbol,tf,time,exact);
//--- iBarShift() 기능이 성공적으로 실행되었으며, exact=true에 대한 결과를 반환합니다.
PrintFormat("2. %s %s %s (%s):bar index is %d (exact=%s)",
symbol,EnumToString(tf),TimeToString(time)
,DayOfWeek(time),bar_index,string(exact));
}
//+------------------------------------------------------------------+
//| 주의 요일 이름을 반환합니다 |
//+------------------------------------------------------------------+
string DayOfWeek(const datetime time)
{
MqlDateTime dt;
string day="";
TimeToStruct(time,dt);
switch(dt.day_of_week)
{
case 0: day=EnumToString(SUNDAY);
break;
case 1: day=EnumToString(MONDAY);
break;
case 2: day=EnumToString(TUESDAY);
break;
case 3: day=EnumToString(WEDNESDAY);
break;
case 4: day=EnumToString(THURSDAY);
break;
case 5: day=EnumToString(FRIDAY);
break;
default:day=EnumToString(SATURDAY);
break;
}
//---
return day;
}
//+------------------------------------------------------------------+
/* Execution result
1. GBPUSD PERIOD_H1 2018.06.10 12:00(SUNDAY): bar index is 64 (exact=false)
Time of bar #64 is 2018.06.08 23:00 (FRIDAY)
2. GBPUSD PERIOD_H1 2018.06.10 12:00 (SUNDAY):bar index is -1 (exact=true)
*/
|