//+------------------------------------------------------------------+
//| DRAW_NONE.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_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- Invisible 플롯
#property indicator_label1 "막대 인덱스"
#property indicator_type1 DRAW_NONE
#property indicator_style1 STYLE_SOLID
#property indicator_color1 clrRed
#property indicator_width1 1
//--- 지표 버퍼
double InvisibleBuffer[];
//+------------------------------------------------------------------+
//| 사용자 지정 지표 초기화 함수 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 지표 버퍼 및 배열 바인딩
SetIndexBuffer(0,InvisibleBuffer,INDICATOR_DATA);
//--- 데이터 창에 표시할 값의 정확도 설정
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 사용자 지정 지표 반복 함수 |
//+------------------------------------------------------------------+
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[])
{
static datetime lastbar=0;
//--- 지표의 첫 번째 계산인 경우
if(prev_calculated==0)
{
//--- 막대 번호를 처음으로 다시 매깁니다
CalcValues(rates_total,close);
//--- 마지막 막대에서 현재 막대의 개방 시간을 기억
lastbar=(datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
}
else
{
//--- 새 막대가 나타난 경우 막대와 개방 시간이 다릅니다
if(lastbar!=SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE))
{
//--- 막대 번호를 다시 한 번 변경
CalcValues(rates_total,close);
//--- 마지막 막대에 있는 현재 막대의 개방 시간 업데이트
lastbar=(datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
}
}
//--- 다음 호출을 위한 prev_calculated의 반환 값
return(rates_total);
}
//+------------------------------------------------------------------+
//| 시계열처럼 막대에 번호를 매김 |
//+------------------------------------------------------------------+
void CalcValues(int total,double const &array[])
{
//--- 지표 버퍼의 인떽싱을 시계열처럼 설정
ArraySetAsSeries(InvisibleBuffer,true);
//--- 각 막대에 해당 번호를 입력
for(int i=0;i<total;i++) InvisibleBuffer[i]=i;
}
|