カスタム指標の値を確認するためにMT4/MT5の表示メニューからデータウィンドウを表示させることがあります。

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fed5553d-7f83-49f3-b1e0-83c1f84f0b3d/chart3.png

指標ラインが複数ある場合、それを区別するためにラベルをつけた方がわかりやすいでしょう。そのために以下のようにOnInit()関数にコードを追加します。

//初期化関数
int OnInit()
{
   //配列を指標バッファに関連付ける
   SetIndexBuffer(0, Buf);
   SetIndexBuffer(1, BufSmooth);
   //時系列配列に設定
   ArraySetAsSeries(Buf, true);
   ArraySetAsSeries(BufSmooth, true);
   //プロット開始位置の設定
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MomPeriod);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, MomPeriod+Smooth);
   //指標ラベルの設定
   SetIndexLabel(0, "Momentum("+IntegerToString(MomPeriod)+")");
   SetIndexLabel(1, "Smooth("+IntegerToString(Smooth)+")");
   return(INIT_SUCCEEDED);
}

[SetIndexLabel()](<https://docs.mql4.com/customind/setindexlabel>)の最初の引数に指標番号を、2番目の引数に表示させたいラベル名を設定します。

ここでは、パラメータの値も表示させるために、"Momentum("")"の文字列の間にMomPeriodの値を文字列に変換した[IntegerToString(MomPeriod)](<https://www.mql5.com/ja/docs/convert/integertostring>)+で連結しておきます。

このコードを追加することで、以下のように各指標のラベル名が表示されます。

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ee2362cd-66eb-4277-aa88-713acd976bc9/_2021-05-29_182157.png