ChartIndicatorDelete

지정된 차트 창에서 지정된 이름의 지표를 제거.

bool  ChartIndicatorDelete(
   long           chart_id,              // 차트 id
   int            sub_window             // 하위 창 번호
   const string   indicator_shortname    // 지표의 단축명
   );

매개변수

chart_id

[in]  차트 ID. 0은 현재 차트를 나타냅니다.

sub_window

[in] 차트 하위창의 번호. 0은 주 차트 하위 창을 나타냅니다.

const indicator_shortname

[in] INDICATOR_SHORTNAME 속성에 IndicatorSetString()기능에서 지표의 단축명을 설정. 지표의 단축명을 가져오기 위해 ChartIndicatorName() 기능을 사용.

값 반환

지표를 성공적으로 삭제할 경우 true를 반환합니다. 그렇지 않으면 false를 반환합니다. 오류 정보를 가져오기 위해 GetLastError() 기능을 사용.

주의

차트 하위 창에 같은 단축명을 가진 두 개의 지표가 있는 경우, 행의 첫 번째 지표가 삭제됩니다.

이 차트의 다른 지표가 삭제 중인 지표 값을 기반으로 하는 경우, 그러한 지표 또한 삭제 됩니다.

iCustom()IndicatorCreate()기능을 사용하여 지표를 만들 때, 지정된 지표의 단축명과 파일 이름을 혼동하지 마십시오. 지표의 단축명이 명시적으로 설정되지 않는 경우, 지표의 소스코드를 포함하는 파일 이름이 컴파일 중에 지정됩니다.

차트에서 지표를 삭제한다고 해서 해당 계산 부분이 터미널 메모리에서 삭제되는 것은 아닙니다. 지표 핸들을 해제하기 위해 IndicatorRelease() 기능을 사용.

지표의 단축명이 올바른 형식이어야 합니다. INDICATOR_SHORTNAME 속성에 IndicatorSetString() 기능을 사용하여 기록됩니다. 단축명은 지표의 모든 입력 변수의 값을 포함해야하는데, 이는 ChartIndicatorDelete() 기능에 의해 차트에서 삭제될 지표의 단축명으로 식별되기 때문입니다.

초기화에 실패한 후 지표를 삭제하는 예:

//+------------------------------------------------------------------+
//|                                    Demo_ChartIndicatorDelete.mq5 |
//|                         Copyright 2000-2024, MetaQuotes Ltd. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- 히스토그램 플롯
#property indicator_label1  "Histogram"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- 매개변수 입력
input int      first_param=1;
input int      second_param=2;
input int      third_param=3;
input bool     wrong_init=true;
//--- 지표 버퍼
double         HistogramBuffer[];
string         shortname;
//+------------------------------------------------------------------+
//| 사용자 지정 지표 초기화 함수                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   int res=INIT_SUCCEEDED;
//--- HistogramBuffer 배열을 지표 버퍼에 연결
   SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA);
//--- 입력 매개변수를 기준으로 지표의 단축명 구성
   shortname=StringFormat("Demo_ChartIndicatorDelete(%d,%d,%d)",
                          first_param,second_param,third_param);
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- 지표의 강제 완료가 설정된 경우 0이 아닌 값을 반환합니다
   if(wrong_init) res=INIT_FAILED;
   return(res);
  }
//+------------------------------------------------------------------+
//| 사용자 지정 지표 반복 함수                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- 루프에서 작업하기 위한 시작 포지션
   int start=prev_calculated-1;
   if(start<0) start=0;
//--- 지표 버퍼에 값을 채우기
   for(int i=start;i<rates_total;i++)
     {
      HistogramBuffer[i]=close[i];
     }
//--- 다음 번 호출에 대해 prev_calculated 값을 반환
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Deinit 이벤트의 핸들러                                   |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   PrintFormat("%s: 초기화 취소 이유 code=%d",__FUNCTION__,reason);
   if(reason==REASON_INITFAILED)
     {
      PrintFormat("%s (파일 %s) 단축명을 가진 지표가 차트에서 자체 삭제됩니다",shortname,__FILE__);
      int window=ChartWindowFind();
      bool res=ChartIndicatorDelete(0,window,shortname);
      //--- ChartIndicatorDelete()의 호출 결과 분석
      if(!res)
        {
         PrintFormat("%s 지표를 #%d 창에서 삭제하는 데 실패하였습니다. 오류 코드 %d",
                     shortname,window,GetLastError());
        }
     }
  }

추가 참조

ChartIndicatorAdd(), ChartIndicatorName(), ChartIndicatorsTotal(), iCustom(), IndicatorCreate(), IndicatorSetString()