ArraySetAsSeries

이 함수는 AS_SERIES 플래그를 선택된 동적 배열의 개체로 설정하고 요소는 시계열처럼 인덱싱.

bool  ArraySetAsSeries(
   const void&  array[],    // 참조에 의한 배열
   bool         flag        // true는 인덱스의 역순을 나타냅니다
   );

매개변수

array[]

[in][out]  설정할 숫자 배열.

플래그

[in]  배열 인덱싱 방향.

반환 값

이 함수는 성공 시 true를, 그렇지 않으면 false를 반환합니다.

참고

다차원 배열 또는 정적 배열(대괄호 안의 크기가 이미 컴파일 단게에서 미리 설정되어 있는 배열)에는 AS_SERIES 플래그를 설정할 수 없습니다. 시계열 인덱싱은 시계열 요소가 마지막부터 시작까지(최신 데이터부터 가장 오래된 데이터까지) 인덱싱된다는 점에서 공통 배열과 다릅니다.

예: 막대 번호를 표시하는 지표

막대 번호 표시 지표

 

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//---- 플롯 수
#property indicator_label1  "숫자"
#property indicator_type1   DRAW_LINE
#property indicator_color1  CLR_NONE
//--- 지표 버퍼
double         NumerationBuffer[];
//+------------------------------------------------------------------+
//| 사용자 지정 지표 초기화 함수                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- 지표 버퍼 맵핑
   SetIndexBuffer(0,NumerationBuffer,INDICATOR_DATA);
//--- 시계열에서처럼 버퍼에 대한 인덱싱 설정
   ArraySetAsSeries(NumerationBuffer,true);
//--- DataWindow에 표시되는 정확도 설정
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- 지표 배열 이름이 DataWindow에 표시되는 방법
   PlotIndexSetString(0,PLOT_LABEL,"Bar #"); 
//---
   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[])
  {
//---  현재 0 막대의 개장 시간을 저장하겠습니다
   static datetime currentBarTimeOpen=0;
//--- time[] 배열로 액세스 되돌리기 - 시계열처럼 실행
   ArraySetAsSeries(time,true);
//--- 0 막대의 시간이 저장된 시간과 다를 경우
   if(currentBarTimeOpen!=time[0])
     {
     //--- 현재에서 차트 깊이까지 모든 막대를 열거
      for(int i=rates_total-1;i>=0;i--) NumerationBuffer[i]=i;
      currentBarTimeOpen=time[0];
     }
//--- 다음 호출을 위한 prev_calculated의 반환 값
   return(rates_total);
  }

추가 참조

시계열에 액세스, ArrayGetAsSeries