#define BAR_NUMBER 0 // 가격과 시간을 가져오는 바의 번호
//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- BAR_NUMBER 인덱스로 단일 바의 데이터를 복사합니다.
MqlRates rates[]={};
if(CopyRates(_Symbol, _Period, BAR_NUMBER, 1, rates)!=1)
{
PrintFormat("CopyRates() failed for bar %d. Error %d", BAR_NUMBER, GetLastError());
return;
}
//--- 획득한 가격과 시간을 차트 픽셀 좌표로 변환합니다.
int x=0, y=0;
ResetLastError();
if(!ChartTimePriceToXY(ChartID(), 0, rates[0].time, rates[0].close, x, y))
{
Print("ChartTimePriceToXY() failed. Error ", GetLastError());
return;
}
//--- 획득한 결과를 저널에 출력합니다.
PrintFormat("For bar[%d] with opening time %s and price %.*f, the chart coordinates are x: %d, y: %d", BAR_NUMBER, TimeToString(rates[0].time), _Digits, rates[0].close, x, y);
/*
결과:
For bar[0] with opening time 2024.08.09 15:06 and price 1.27378, the chart coordinates are x: 784, y: 240
*/
}
|