//--- 입력 매개변수
input group "The date can be entered in any of the formats:"
input group "yyyy.mm.dd [hh:mi], yyyy.mm.dd [hh:mi:ss]"
input group "yyyymmdd [hh:mi:ss], yyyymmdd [hhmiss]"
input group "yyyy/mm/dd [hh:mi:ss], yyyy-mm-dd [hh:mi:ss]"
input string InpDateStr; // Please enter the date here as a string
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- 입력에 문자열로 입력된 시간을 날짜/시간 값으로 변환합니다.
datetime time=StringToTime(InpDateStr);
//--- 입력한 문자열과 얻은 시간을 저널에 표시합니다.
PrintFormat("Date entered as a string in the form '%s' is converted to datetime in the form '%s'",
InpDateStr, TimeToString(time, TIME_DATE|TIME_MINUTES|TIME_SECONDS));
//--- 수신된 날짜-시간에 수직선을 생성하고 차트를 이 위치로 이동합니다.
if(CreateVLine(time))
ChartNavigateToTime(time);
/*
result:
Date entered as a string in the form '' is converted to datetime in the form '1970.01.01 00:00:00'
Date entered as a string in the form '2024' is converted to datetime in the form '2024.02.24 20:24:00'
Date entered as a string in the form '202400' is converted to datetime in the form '2024.02.24 20:24:00'
Date entered as a string in the form '20240000' is converted to datetime in the form '2024.02.24 00:00:00'
Date entered as a string in the form '2024022410' is converted to datetime in the form '2030.09.06 00:00:00'
Date entered as a string in the form '20240224 10' is converted to datetime in the form '2024.02.24 10:00:00'
Date entered as a string in the form '20240224 01' is converted to datetime in the form '2024.02.24 01:00:00'
Date entered as a string in the form '20240224 0030' is converted to datetime in the form '2024.02.24 23:00:00'
Date entered as a string in the form '20240224 0100' is converted to datetime in the form '2024.02.24 01:00:00'
*/
}
//+------------------------------------------------------------------+
//| 수직선 객체 만들기 |
//+------------------------------------------------------------------+
bool CreateVLine(const datetime line_time)
{
ResetLastError();
string name=MQLInfoString(MQL_PROGRAM_NAME)+"_VLINE";
if(!ObjectCreate(0, name, OBJ_VLINE, 0, line_time, 0))
{
Print("ObjectCreate() failed. Error code: ", GetLastError());
return(false);
}
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DOT);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, true);
return(true);
}
//+------------------------------------------------------------------+
//| 차트를 지정된 바 오픈 시간으로 이동 |
//+------------------------------------------------------------------+
bool ChartNavigateToTime(const datetime time)
{
ChartSetInteger(0, CHART_AUTOSCROLL, false);
ResetLastError();
int bar=iBarShift(_Symbol, PERIOD_CURRENT, time);
if(bar<0)
{
PrintFormat("%s: iBarShift() failed. Error code: %d", __FUNCTION__, GetLastError());
return(false);
}
long first=0;
if(!ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR, 0, first))
{
PrintFormat("%s: ChartGetInteger() failed. Error code: %d", __FUNCTION__, GetLastError());
return(false);
}
return(ChartNavigate(0, CHART_CURRENT_POS, (int)first-bar));
}
|