OBJ_TEXT

텍스트 개체.

ObjText

참조

텍스트에 상대적인 고정점 포지션은 ENUM_ANCHOR_POINT 열거에서 선택할 수 있습니다. 텍스트 경사 각도를 OBJPROP_ANGLE 속성을 사용하여 변경할 수도 있습니다.

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

 

//--- 설명
#property description "스크립트는 \"텍스트\" 그래픽 개체를 생성합니다."
//--- 스크립트 실행 중 입력 매개변수의 표시 창
#property script_show_inputs
//--- 스크립트의 입력 매개변수
input string            InpFont="Arial";         // 글꼴
input int               InpFontSize=10;          // 글꼴 크기
input color             InpColor=clrRed;         // 색상
input double            InpAngle=90.0;           // 경사각(도)
input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_LEFT;   // 앵커 유형
input bool              InpBack=false;           // 배경 개체
input bool              InpSelection=false;      // 이동하려면 강조 표시
input bool              InpHidden=true;          // 개체 목록에 숨겨짐
input long              InpZOrder=0;             // 마우스 클릭 우선 순위
//+------------------------------------------------------------------+
//| 텍스트 개체 생성                                             |
//+------------------------------------------------------------------+
bool TextCreate(const long              chart_ID=0,               // 차트의 ID
                const string            name="Text",              // 개체 이름
                const int               sub_window=0,             // 하위 창 인덱스
                datetime                time=0,                   // 고정점 시간
                double                  price=0,                  // 고정점 가격
                const string            text="Text",              // 텍스트 그 자체
                const string            font="Arial",             // 글꼴
                const int               font_size=10,             // 글꼴 크기
                const color             clr=clrRed,               // 색상
                const double            angle=0.0,                // 텍스트 기울기
                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER// 앵커 유형
                const bool              back=false,               // 배경에
                const bool              selection=false,          // 이동하려면 강조 표시
                const bool              hidden=true,              // 개체 목록에 숨겨짐
                const long              z_order=0)                // 마우스 클릭 우선 순위
  {
//--- 고정점 좌표를 설정하지 않은 경우
   ChangeTextEmptyPoint(time,price);
//--- 오류 값 재설정
   ResetLastError();
//--- 텍스트 개체 생성
   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": \"텍스트\" 개체 생성 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 텍스트 설정
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- 텍스트 글꼴 설정
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- 글꼴 크기 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- 텍스트 경사각 설정
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- 앵커 유형 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- 색상 설정
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- 전경(false) 또는 배경(true)에 표시
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the object by mouse
   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 TextMove(const long   chart_ID=0,  // 차트의 ID
              const string name="Text"// 개체 이름
              datetime     time=0,      // 고정점 시간 좌표
              double       price=0)     // 고정점 시간 가격 좌표
  {
//--- 포인트 위치가 설정되지 않은 겨우 입찰 가격이 있는 현재 막대로 이동합니다
   if(!time)
      time=TimeCurrent();
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- 오류 값 재설정
   ResetLastError();
//--- 고정점 이동
   if(!ObjectMove(chart_ID,name,0,time,price))
     {
      Print(__FUNCTION__,
            ": 고정점 이동 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 개체 텍스트 변경                                           |
//+------------------------------------------------------------------+
bool TextChange(const long   chart_ID=0,  // 차트의 ID
                const string name="Text"// 개체 이름
                const string text="Text"// 텍스트
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 개체 텍스트 변경
   if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text))
     {
      Print(__FUNCTION__,
            ": 텍스트 변경 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 텍스트 개체 삭제                                               |
//+------------------------------------------------------------------+
bool TextDelete(const long   chart_ID=0,  // 차트의 ID
                const string name="Text"// 개체 이름
  {
//--- 오류 값 재설정
   ResetLastError();
//--- 개체 삭제
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": \"텍스트\" 개체 삭제 실패! Error code = ",GetLastError());
      return(false);
     }
//--- 실행 성공
   return(true);
  }
//+------------------------------------------------------------------+
//| 고정점 값 확인 및 기본값 설정                 |
//| 빈 곳의 경우                                                   |
//+------------------------------------------------------------------+
void ChangeTextEmptyPoint(datetime &time,double &price)
  {
//--- 점의 시간이 설정되지 않은 경우 현재 막대에 표시됩니다
   if(!time)
      time=TimeCurrent();
//--- 포인트 가격이 설정되지 않은 경우 입찰 값을 갖습니다
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  }
//+------------------------------------------------------------------+
//| 스크립트 프로그램 시작 함수                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime date[]; // 표시된 막대의 날짜를 저장하기 위한 배열
   double   low[];  // 표시된 막대의 저가 가격을 저장하기 위한 배열
   double   high[]; // 표시된 막대의 고가 가격을 저장하기 위한 배열
//--- 차트 창에 표시되는 막대 수
   int bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);
//--- 메모리 할당
   ArrayResize(date,bars);
   ArrayResize(low,bars);
   ArrayResize(high,bars);
//--- 날짜 배열 채우기
   ResetLastError();
   if(CopyTime(Symbol(),Period(),0,bars,date)==-1)
     {
      Print("시간 값 복사 실패! Error code = ",GetLastError());
      return;
     }
//--- 저가 가격의 배열 채우기
   if(CopyLow(Symbol(),Period(),0,bars,low)==-1)
     {
      Print("저가 가격의 값 복사 실패! Error code = ",GetLastError());
      return;
     }
//--- 고가 가격의 배열 채우기
   if(CopyHigh(Symbol(),Period(),0,bars,high)==-1)
     {
      Print("고가 가격 값 복사 실패! Error code = ",GetLastError());
      return;
     }
//--- 텍스트 디스플레이 빈도 지정
   int scale=(int)ChartGetInteger(0,CHART_SCALE);
//--- 단계 지정
   int step=1;
   switch(scale)
     {
      case 0:
         step=12;
         break;
      case 1:
         step=6;
         break;
      case 2:
         step=4;
         break;
      case 3:
         step=2;
         break;
     }
//--- 고가 및 저가 막대의 값에 대한 텍스트 만들기(간격 포함)
   for(int i=0;i<bars;i+=step)
     {
      //--- 텍스트 생성
      if(!TextCreate(0,"TextHigh_"+(string)i,0,date[i],high[i],DoubleToString(high[i],5),InpFont,InpFontSize,
         InpColor,InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder))
        {
         return;
        }
      if(!TextCreate(0,"TextLow_"+(string)i,0,date[i],low[i],DoubleToString(low[i],5),InpFont,InpFontSize,
         InpColor,-InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder))
        {
         return;
        }
      //--- 스크립트 작업이 강제로 비활성화 되었는지 확인
      if(IsStopped())
         return;
      //--- 차트 다시 그리기
      ChartRedraw();
      // 0.05초 지연
      Sleep(50);
     }
//--- 0.5초 지연
   Sleep(500);
//--- 텍스트 삭제
   for(int i=0;i<bars;i+=step)
     {
      if(!TextDelete(0,"TextHigh_"+(string)i))
         return;
      if(!TextDelete(0,"TextLow_"+(string)i))
         return;
      //--- 차트 다시 그리기
      ChartRedraw();
      // 0.05초 지연
      Sleep(50);
     }
//---
  }