シリーズ・バージョンもコーディングした
コードのスタイリングは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; }
取引の機会を逃しています。
- 無料取引アプリ
- 8千を超えるシグナルをコピー
- 金融ニュースで金融マーケットを探索
Intrabar Volume Flow:
各バー内の出来高の時間変化を視覚化するインジケータ。ティックボリュームをローリングヒストグラム形式で表示します。
Author: Conor Mcnamara