OBJ_CHART

차트 개체.

ObjChart

참조

" OBJ_CHART" 유형 객체는 시각적 테스트 중에 지원되지 않습니다(표시되지 않음).

고정점 좌표는 픽셀 단위로 설정됩니다. 고정 모서리를 ENUM_BASE_CORNER 열거에서 선택할 수 있습니다.

차트 개체에 대해 기호, 주기 및 스케일을 선택할 수 있습니다. 가격 스케일 및 날짜 표시 모드도 활성화/비활성화할 수 있습니다.

다음 스크립트는 차트에서 차트 개체를 만드로 이동합니다. 그래픽 개체의 속성을 만들고 변경할 수 있는 특수 기능이 개발되었습니다. 이러한 기능은 자체 애플리케이션에서 "있는 대로" 사용할 수 있습니다.

 

//--- 설명
#property description "스크립트는 \"차트\" 개체를 생성합니다."
//--- 스크립트 실행 중 입력 매개변수의 표시 창
#property script_show_inputs
//--- 스크립트의 입력 매개변수
input string           InpName="Chart";             // 개체 이름
input string           InpSymbol="EURUSD";          // 기호
input ENUM_TIMEFRAMES  InpPeriod=PERIOD_H1;         // 주기
input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER// 고정 모서리
input int              InpScale=2;                  // 스케일
input bool             InpDateScale=true;           // 시간 스케일 표시
input bool             InpPriceScale=true;          // 가격 스케일 표시
input color            InpColor=clrRed;             // 강조 표시된 경우 테두리 색상
input ENUM_LINE_STYLE  InpStyle=STYLE_DASHDOTDOT;   // 강조 표시된 경우 선 스타일
input int              InpPointWidth=1;             // 이동할 점 크기
input bool             InpBack=false;               // 배경 개체
input bool             InpSelection=true;           // 이동하려면 강조 표시
input bool             InpHidden=true;              // 개체 목록에 숨겨짐
input long             InpZOrder=0;                 // 마우스 클릭 우선 순위
//+------------------------------------------------------------------+
//| 차트 개체 생성                                            |
//+------------------------------------------------------------------+
bool ObjectChartCreate(const long              chart_ID=0,               // 차트의 ID
                       const string            name="Chart",             // 개체 이름
                       const int               sub_window=0,             // 하위 창 인덱스
                       const string            symbol="EURUSD",          // 기호
                       const ENUM_TIMEFRAMES   period=PERIOD_H1,         // 주기
                       const int               x=0,                      // X 좌표
                       const int               y=0,                      // Y 좌표
                       const int               width=300,                // 너비
                       const int               height=200,               // 높이
                       const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER// 고정 모서리
                       const int               scale=2,                  // 스케일
                       const bool              date_scale=true,          // 시간 스케일 표시
                       const bool              price_scale=true,         // 가격 스케일 표시
                       const color             clr=clrRed,               // 강조 표시된 경우 테두리 색상
                       const ENUM_LINE_STYLE   style=STYLE_SOLID,        // 강조 표시된 경우 선 스타일
                       const int               point_width=1,            // 점 크기 이동
                       const bool              back=false,               // 배경에
                       const bool              selection=false,          // 이동하려면 강조 표시
                       const bool              hidden=true,              // 개체 목록에 숨겨짐
                       const long              z_order=0)                // 마우스 클릭 우선 순위
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 차트 개체 생성
   if(!ObjectCreate(chart_ID,name,OBJ_CHART,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체 생성 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 개체 좌표 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- 개체 크기 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- 지정된 점 좌표를 기준으로 차트 모서리 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- 기호 설정
   ObjectSetString(chart_ID,name,OBJPROP_SYMBOL,symbol);
//--- 주기 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_PERIOD,period);
//--- 스케일 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_CHART_SCALE,scale);
//--- 시간 스케일 표시(true) 또는 숨김(false)
   ObjectSetInteger(chart_ID,name,OBJPROP_DATE_SCALE,date_scale);
//--- 가격 스케일 표시(true) 또는 숨김(false)
   ObjectSetInteger(chart_ID,name,OBJPROP_PRICE_SCALE,price_scale);
//--- 개체 강조 모드가 활성화된 경우 테두리 색 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- 개체 강조 모드가 활성화된 경우 테두리 스타일 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- 개체를 이동할 고정점 크기를 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,point_width);
//--- 전경(false) 또는 배경(true)에 표시
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- 마우스를 사용하여 레이블 이동 모드 활성화(true) 또는 비활성화(false)
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- 개체 목록에서 그래픽 개체 이름 숨기기(true) 또는 표시(false)
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- 차트에서 마우스 클릭 이벤트 수신 우선 순위 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 차트 개체의 기호 및 시간 프레임을 설정               |
//+------------------------------------------------------------------+
bool ObjectChartSetSymbolAndPeriod(const long            chart_ID=0,       // 차트의 ID (차트 개체의 ID가 아닌)
                                   const string          name="Chart",     // 개체 이름
                                   const string          symbol="EURUSD",  // 기호
                                   const ENUM_TIMEFRAMES period=PERIOD_H1// 시간 프레임
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 차트 개체의 기호 및 시간 프레임 설정
   if(!ObjectSetString(chart_ID,name,OBJPROP_SYMBOL,symbol))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 기호 설정 실패! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_PERIOD,period))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 주기 설정 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 차트 개체 이동                                                |
//+------------------------------------------------------------------+
bool ObjectChartMove(const long   chart_ID=0,   // 차트의 ID (차트 개체의 ID가 아닌)
                     const string name="Chart"// 개체 이름
                     const int    x=0,          // X 좌표
                     const int    y=0)          // Y 좌표
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 개체 이동
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 X 좌표 이동 실패! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 Y 좌표 이동 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 차트 개체 크기 변경                                         |
//+------------------------------------------------------------------+
bool ObjectChartChangeSize(const long   chart_ID=0,   // 차트의 ID (차트 개체의 ID가 아닌)
                           const string name="Chart"// 개체 이름
                           const int    width=300,    // 너비
                           const int    height=200)   // 높이
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 개체 크기 변경
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 너비 변경 실패\! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 높이 변경 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 차트 개체의 ID 반환                                         |
//+------------------------------------------------------------------+
long ObjectChartGetID(const long   chart_ID=0,   // 차트의 ID (차트 개체의 ID가 아닌)
                      const string name="Chart"// 개체 이름
  {
//--- 변수를 준비하여 차트 개체의 ID를 가져오기
   long id=-1;
//--- 오류 값 재설정
   ResetLastError();
//--- ID 가져오기
   if(!ObjectGetInteger(chart_ID,name,OBJPROP_CHART_ID,0,id))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체의 ID 가져오기 실패! Error code = ",GetLastError());
     }
//--- 결과 반환
   return(id);
  }
//+------------------------------------------------------------------+
//| 차트 개체 삭제                                              |
//+------------------------------------------------------------------+
bool ObjectChartDelete(const long   chart_ID=0,   // 차트의 ID (차트 개체의 ID가 아닌)
                       const string name="Chart"// 개체 이름
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 버튼 삭제
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": \"차트\" 개체 삭제 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 마켓 워치(Market Watch)의 기호 수 가져오기
   int  symbols=SymbolsTotal(true);
//--- 지정된 이름의 기호가 기호 목록에 있는지 확인합니다
   bool exist=false;
   for(int i=0;i<symbols;i++)
      if(InpSymbol==SymbolName(i,true))
        {
         exist=true;
         break;
        }
   if(!exist)
     {
      Print("오류! ",InpSymbol," 기호가 \"Market Watch\에 존재하지 않습니다"!");
      return;
     }
//--- 입력 매개변수의 유효성 검사
   if(InpScale<0 || InpScale>5)
     {
      Print("오류! 입력 매개변수의 잘못된 값!");
      return;
     }
 
//--- 차트 창 크기
   long x_distance;
   long y_distance;
//--- 창 크기 설정
   if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance))
     {
      Print("차트 너비 가져오기 실패! Error code = ",GetLastError());
      return;
     }
   if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance))
     {
      Print("차트 높이 가져오기 실패! Error code = ",GetLastError());
      return;
     }
//--- 차트 개체 좌표 및 해당 크기 설정
   int x=(int)x_distance/16;
   int y=(int)y_distance/16;
   int x_size=(int)x_distance*7/16;
   int y_size=(int)y_distance*7/16;
//--- 차트 개체 생성
   if(!ObjectChartCreate(0,InpName,0,InpSymbol,InpPeriod,x,y,x_size,y_size,InpCorner,InpScale,InpDateScale,
      InpPriceScale,InpColor,InpStyle,InpPointWidth,InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
//--- 차트를 다시 그리고 1초 동안 대기
   ChartRedraw();
   Sleep(1000);
//--- 차트 개체 늘이기
   int steps=(int)MathMin(x_distance*7/16,y_distance*7/16);
   for(int i=0;i<steps;i++)
     {
      //--- 크기 조정
      x_size+=1;
      y_size+=1;
      if(!ObjectChartChangeSize(0,InpName,x_size,y_size))
         return;
      //--- 스크립트 작업이 강제로 비활성화 되었는지 확인
      if(IsStopped())
         return;
      //--- 차트를 다시 그리고 0.01 초 대기
      ChartRedraw();
      Sleep(10);
     }
//--- 0.5초 지연
   Sleep(500);
//--- 차트의 시간 프레임 변경
   if(!ObjectChartSetSymbolAndPeriod(0,InpName,InpSymbol,PERIOD_M1))
      return;
   ChartRedraw();
//--- 3초 지연
   Sleep(3000);
//--- 개체 삭제
   ObjectChartDelete(0,InpName);
   ChartRedraw();
//--- 1초 동안 대기
   Sleep(1000);
//---
  }