
MQL4 インジケーター作成
IndicatorBuffers()
- できること
- 計算用を含めたバッファの総数を設定する
- 対応
- MQL4
IndicatorBuffers() とは
MQL4 のカスタムインジケーターで、表示しない計算用のバッファを含めたバッファの総数を設定する関数です。#property indicator_buffers は表示するバッファの数で、それより多く使うときに OnInit() で呼びます。
IndicatorBuffers() の書式と引数
bool IndicatorBuffers(int count)| 引数 | 型 | 省略時 | 説明 |
|---|---|---|---|
count | int | 必須 | バッファの総数。 |
戻り値
設定できたら true を返します。
IndicatorBuffers() の使い方(コード例)
#property strict
#property indicator_separate_window
#property indicator_buffers 1 // 表示するバッファは1本
double LineBuf[], CalcBuf[];
int OnInit()
{
IndicatorBuffers(2); // 表示1本 + 計算用1本
SetIndexBuffer(0, LineBuf);
SetIndexBuffer(1, CalcBuf);
SetIndexStyle(0, DRAW_LINE);
return INIT_SUCCEEDED;
}
// 終値の変化幅(CalcBuf)を計算し、その3本平均(LineBuf)を表示する
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[])
{
for(int i = rates_total - 2; i >= 0; i--)
CalcBuf[i] = close[i] - close[i + 1];
for(int i = rates_total - 4; i >= 0; i--)
LineBuf[i] = (CalcBuf[i] + CalcBuf[i + 1] + CalcBuf[i + 2]) / 3;
return rates_total;
}MetaEditor でコンパイルできることを確認済みです。
MQL4 と MQL5 の違い
MQL5 では #property indicator_buffers に総数を書き、計算用のバッファは SetIndexBuffer(番号, 配列, INDICATOR_CALCULATIONS) で登録します。












