ObjectGetValueByTime

이 함수는 지정된 객체의 지정된 시간 값에 대한 가격 값을 반환합니다.

double  ObjectGetValueByTime(
   long      chart_id,     // 차트 식별자
   string    name,         // 오브젝트명
   datetime  time,         // 시간
   int       line_id       // 라인 번호
   );

Parameter

chart_id

[in]  차트 식별자. 0은 현재 차트를 의미합니다.

name

[in]  객체명.

time

[in]  시간 값.

line_id

[in]  Line ID.

반환값

지정된 개체의 지정된 시간 값에 대한 가격 값.

참고

이 함수는 동기식 호출을 사용합니다. 이는 이 함수가 호출하기 전에 이 차트에 대해 대기한 모든 명령의 실행을 대기하므로 이 함수는 시간이 많이 걸릴 수 있습니다. 차트에서 많은 개체로 작업할 때는 이 기능을 고려해야 합니다.

객체는 하나의 가격 좌표에 여러 개의 값을 가질 수 있으므로 라인 번호를 지정해야 합니다. 이 함수는 다음 개체에만 적용됩니다.

  • 추세선 (OBJ_TREND)
  • 각도별 추세선 (OBJ_TRENDBYANGLE)
  • Gann line (OBJ_GANNLINE)
  • 등거리 채널 (OBJ_CHANNEL) - 2 lines
  • 선형 회귀 채널 (OBJ_REGRESSION) - 3 lines
  • 표준편차 채널 (OBJ_STDDEVCHANNEL) - 3 lines
  • 애로우드 라인 (OBJ_ARROWED_LINE)

 

예:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00""
 
#define   OBJ_NAME   "TestObjectGetValueByTime" // graphical object name
/+------------------------------------------------------------------+
//| Script program start function                                   |
/+------------------------------------------------------------------+
void OnStart()
  {
//--- 차트 ID, 심볼
   long   chart_id=ChartID();
   string symbol=ChartSymbol(chart_id);
 
   long bar1=0bar2=0visible=0;
//--- 차트의 첫 번째 바를 왼쪽에 표시
   ResetLastError();
   if(!ChartGetInteger(chart_idCHART_FIRST_VISIBLE_BAR0bar1))
     {
      Print("ChartGetInteger() failed. Error "GetLastError());
      return;
     }
//--- 차트에 보이는 바의 수
   if(!ChartGetInteger(chart_idCHART_VISIBLE_BARS0visible))
     {
      Print("ChartGetInteger() failed. Error "GetLastError());
      return;
     }
 
//--- 획득한 값을 조정하고 오른쪽에 보이는 첫 번째 바의 인덱스를 계산합니다.
   bar1-=1;
   visible-=2;
   bar2=bar1-visible;
 
//--- 왼쪽의 보이는 바의 High에서 오른쪽 보이는 막대의 Low까지의 등거리 채널을 구축합니다.
   if(!CreateChannel(chart_id, (int)bar1, (int)bar2))
      return;
   
   int digits=(int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);
   
//--- 차트에서 왼쪽에 보이는 바에서 오른쪽에 보이는 바까지 루프로
//--- 각 등거리 채널 라인의 루프 바 시간에 대한 가격 값을 가져옵니다.
//--- 저널에서 각 라인에 수신된 가격을 표시합니다.
   for(int i=(int)bar1i>=bar2 && !IsStopped(); i--)
     {
      datetime time=GetTime(symboli);
      if(time==0)
         continue;
      
      string time_str=TimeToString(time);
      double value0=ObjectGetValueByTime(chart_idOBJ_NAMEtime0);
      double value1=ObjectGetValueByTime(chart_idOBJ_NAMEtime1);
      string idx=StringFormat("%03d"i);
      PrintFormat("[%s] For time %s the price value at 0 line of the object: %.*f, at line 1: %.*f",
                  idxTimeToString(time), digitsvalue0digitsvalue1);
     }
   
//--- 5초간 기다렸다가 정리
      Sleep(5000);
   ObjectDelete(chart_idOBJ_NAME);
   ChartRedraw(chart_id);
   /*
   결과:
   [114For time 2025.01.02 05:00 the price value at 0 line of the object1.03732at line 11.03393
   [113For time 2025.01.02 05:30 the price value at 0 line of the object1.03694at line 11.03355
   [112For time 2025.01.02 06:00 the price value at 0 line of the object1.03657at line 11.03318
   [111For time 2025.01.02 06:30 the price value at 0 line of the object1.03619at line 11.03280
   [110For time 2025.01.02 07:00 the price value at 0 line of the object1.03581at line 11.03242
   [109For time 2025.01.02 07:30 the price value at 0 line of the object1.03544at line 11.03205
   [108For time 2025.01.02 08:00 the price value at 0 line of the object1.03506at line 11.03167
   [107For time 2025.01.02 08:30 the price value at 0 line of the object1.03468at line 11.03129
   [106For time 2025.01.02 09:00 the price value at 0 line of the object1.03431at line 11.03092
   [105For time 2025.01.02 09:30 the price value at 0 line of the object1.03393at line 11.03054
   [104For time 2025.01.02 10:00 the price value at 0 line of the object1.03355at line 11.03016
   [103For time 2025.01.02 10:30 the price value at 0 line of the object1.03318at line 11.02979
   [102For time 2025.01.02 11:00 the price value at 0 line of the object1.03280at line 11.02941
   [101For time 2025.01.02 11:30 the price value at 0 line of the object1.03242at line 11.02903
   [100For time 2025.01.02 12:00 the price value at 0 line of the object1.03205at line 11.02866
   [099For time 2025.01.02 12:30 the price value at 0 line of the object1.03167at line 11.02828
   [098For time 2025.01.02 13:00 the price value at 0 line of the object1.03129at line 11.02790
   [097For time 2025.01.02 13:30 the price value at 0 line of the object1.03092at line 11.02753
   [096For time 2025.01.02 14:00 the price value at 0 line of the object1.03054at line 11.02715
   [095For time 2025.01.02 14:30 the price value at 0 line of the object1.03016at line 11.02677
   [094For time 2025.01.02 15:00 the price value at 0 line of the object1.02979at line 11.02640
   [093For time 2025.01.02 15:30 the price value at 0 line of the object1.02941at line 11.02602
   [092For time 2025.01.02 16:00 the price value at 0 line of the object1.02903at line 11.02564
   [091For time 2025.01.02 16:30 the price value at 0 line of the object1.02866at line 11.02527
   [090For time 2025.01.02 17:00 the price value at 0 line of the object1.02828at line 11.02489
   [089For time 2025.01.02 17:30 the price value at 0 line of the object1.02790at line 11.02451
   [088For time 2025.01.02 18:00 the price value at 0 line of the object1.02753at line 11.02414
   [087For time 2025.01.02 18:30 the price value at 0 line of the object1.02715at line 11.02376
   [086For time 2025.01.02 19:00 the price value at 0 line of the object1.02677at line 11.02338
   [085For time 2025.01.02 19:30 the price value at 0 line of the object1.02640at line 11.02301
   [084For time 2025.01.02 20:00 the price value at 0 line of the object1.02602at line 11.02263
   */
  }
/+------------------------------------------------------------------+
//| 인덱스로 지정된 바의 시간을 반환합니다.                              |
/+------------------------------------------------------------------+
datetime GetTime(const string symbol_nameconst int index)
  {
   if(index<0)
      return(0);
   datetime array[1];
   ResetLastError();
   if(CopyTime(symbol_namePERIOD_CURRENTindex1array)!=1)
     {
      PrintFormat("%s: CopyTime() failed. Error %d",__FUNCTION__GetLastError());
      return(0);
     }
   return(array[0]);
  }
//+--------------------------------------------------------------------------------------------+
//| 왼쪽의 바의 고점에서 오른쪽 바의 저점까지 등거리 채널을 구성합니다.                                |
//+--------------------------------------------------------------------------------------------+
bool CreateChannel(const long chart_idconst int bar1const int bar2)
  {
   long     visible=0;
   datetime time1 =0time2 =0;
   double   price1=0price2=0;
 
//--- 차트 심볼
   string symbol=ChartSymbol(chart_id);
   
//--- 차트 왼쪽에 보이는 첫 번째 바의 시간을 가져옵니다.
   ResetLastError();
   datetime time_array[1];
   if(CopyTime(symbolPERIOD_CURRENT, (int)bar11time_array)!=1)
     {
      PrintFormat("%s: CopyTime() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   time1=time_array[0];
   
//--- 오른쪽에 보이는 차트의 첫 번째 바의 시간을 가져옵니다.
   if(CopyTime(symbolPERIOD_CURRENT, (int)bar21time_array)!=1)
     {
      PrintFormat("%s: CopyTime() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   time2=time_array[0];
   
//--- 차트 왼쪽에 보이는 첫 번째 바의 최고가를 가져옵니다.
   double price_array[];
   if(CopyHigh(symbolPERIOD_CURRENT, (int)bar11price_array)!=1)
     {
      PrintFormat("%s: CopyHigh() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   price1=price_array[0];
   
//--- 차트 오른쪽에 보이는 첫 번째 바의 저가를 가져옵니다.
   if(CopyLow(symbolPERIOD_CURRENT, (int)bar21price_array)!=1)
     {
      PrintFormat("%s: CopyLow() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
   price2=price_array[0];
   
//--- 차트의 가격 범위를 포인트 단위로 계산합니다.
//--- 등거리 채널의 경우 두 번째 라인의 거리는 가격 범위의 1/3이 됩니다.
   double range=price1-price2;
   double distance=range*0.3;
   
//--- 계산된 좌표에서 그래픽 객체(등거리 채널)를 생성합니다.
   if(!ObjectCreate(chart_idOBJ_NAMEOBJ_CHANNEL0time1price1time2price2time1price1-distance))
     {
      PrintFormat("%s: ObjectCreate() failed. Error %d",__FUNCTION__GetLastError());
      return(false);
     }
     
//--- 차트를 업데이트하고 'true'를 반환합니다.
   ChartRedraw(chart_id);
   return(true);
  }

 

참고 항목

객체 유형