我还编写了一个系列版本
代码样式是 MetaEditor 中的 "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; }
Intrabar Volume Flow:
该指标可直观显示每个条形图中成交量随时间的变化情况。它以滚动柱状图格式显示刻度线成交量。
Author: Conor Mcnamara