지표: Intrabar Volume Flow

 

Intrabar Volume Flow:

각 막대 내에서 시간에 따른 볼륨 변화를 시각화한 표시기입니다. 롤링 히스토그램 형식으로 틱 볼륨을 표시합니다.

Intrabar Volume Flow

Author: Conor Mcnamara

 

시리즈 버전도 코딩했습니다.

코드 스타일링은 메타에디터에서 "Mozilla" 선택입니다.

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 1

#property indicator_color1 clrGreen, clrRed
#property indicator_type1 DRAW_COLOR_HISTOGRAM

double plot[];
double col[];
double incomingVolume[];
double ma[];
double closes[];

input bool grannularTrend = false; // 세분화된 트렌드

int period = 20;

//+------------------------------------------------------------------+
//| 사용자 지정 표시기 초기화 기능 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 표시기 버퍼 매핑
  SetIndexBuffer(0, plot, INDICATOR_DATA);
  SetIndexBuffer(1, col,  INDICATOR_COLOR_INDEX);
  SetIndexBuffer(2, ma, INDICATOR_CALCULATIONS);
  SetIndexBuffer(3, incomingVolume, INDICATOR_CALCULATIONS);
  SetIndexBuffer(4, closes, INDICATOR_CALCULATIONS);

  ArraySetAsSeries(plot, true);
  ArraySetAsSeries(col, true);
  ArraySetAsSeries(ma, true);
  ArraySetAsSeries(incomingVolume, true);
  ArraySetAsSeries(closes, true);


  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[])
{
  ArraySetAsSeries(close, false);
  ArrayCopy(incomingVolume, tick_volume, 0, rates_total-1);

  ArrayCopy(closes, close, 0, rates_total-1);

  int buffSize = ArraySize(incomingVolume);

  ArraySetAsSeries(close, true);

  if(prev_calculated == 0) { initialzeBuffers();
  }
  
  long volumeThreshold = 0;
  long sum = 0;

  for (int j = 0; j < period; j++) sum += tick_volume[j];
  volumeThreshold = sum / 20;

  int empty_data = rates_total - buffSize;


  for(int i = buffSize-1; i>=empty_data; i--) {
    plot[i] = incomingVolume[i];
    trend(period, i, ma, closes);

    if (i < buffSize - 1) {
      if (!grannularTrend) {
        col[i] = ma[0] > ma[1] ? 0 : 1;
      } else {
        col[i] = (ma[i] > ma[i+1]) ? 0 : 1;
      }
    }

  }
  for(int i = buffSize-2; i>=0; i--) {

    closes[i+1] = closes[i];
    incomingVolume[i+1] = incomingVolume[i];
  }


  return buffSize;
}

void initialzeBuffers(){

  ArrayInitialize(plot, EMPTY_VALUE); 
  ArrayInitialize(col, EMPTY_VALUE); 
  ArrayInitialize(ma, EMPTY_VALUE); 
  ArrayInitialize(incomingVolume, EMPTY_VALUE); 
  ArrayInitialize(closes, EMPTY_VALUE);
}

void trend(int per, int idx, double &arr[], const double &close[])
{
  double sum = 0.0;
  for(int k = 1; k < per && (idx + k) < ArraySize(close); k++) {
    sum += close[idx + k];
  }
  arr[idx] = sum / per;
}