//+------------------------------------------------------------------+
//| 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());
}
}
}
|