PlotIndexSetInteger

この関数は、対応する指示線の対応するプロパティの値を設定します。指標プロパティは int、char、bool または color 型でなければなりません。この関数には 2 つのバージョンがあります。

プロパティの識別子を示す呼び出し

bool  PlotIndexSetInteger(
  int  plot_index,        // プロットスタイルインデックス
  int  prop_id,          // プロパティ識別子
  int  prop_value        // 設定する値
  );

プロパティの識別子と修飾子を示す呼び出し

bool  PlotIndexSetInteger(
  int  plot_index,        // プロットスタイルインデックス
  int  prop_id,          // プロパティ識別子
  int  prop_modifier,    // プロパティ修飾子
  int  prop_value        // 設定する値
  )

パラメータ

plot_index

[in] グラフィックプロットのインデックス

prop_id

[in] 値は ENUM_PLOT_PROPERTY_INTEGER 列挙のいずれかです。

prop_modifier

[in]  指定されたプロパティの修飾子。修飾子は色インデックスプロパティのみで必要です。

prop_value

[in]  プロパティ値

戻り値

成功の場合は true、それ以外の場合は false

例: 3 色の線を描画する指標色は 5 ティックごとに変わります。

colorline

 

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   1
//---- ColorLine をプロットする
#property indicator_label1 "ColorLine"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1 clrRed,clrGreen,clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1  3
//--- 指標バッファ
double         ColorLineBuffer[];
double         ColorBuffer[];
int            MA_handle;
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数                                            |
//+------------------------------------------------------------------+
void OnInit()
 {
//--- 指標バッファマッピング
  SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA);
  SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
//--- MA ハンドルの取得
  MA_handle=iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE);
//---
 }
//+------------------------------------------------------------------+
//| 色インデックスを取得                                                   |
//+------------------------------------------------------------------+
int getIndexOfColor(int i)
 {
  int j=i%300;
  if(j<100) return(0);// 1 番目のインデックス
  if(j<200) return(1);// 2 番目のインデックス
  return(2); // 3 番目のインデックス
 }
//+------------------------------------------------------------------+
//| カスタム指標の反復関数                                                |
//+------------------------------------------------------------------+
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[])
 {
//---
  static int ticks=0,modified=0;
  int limit;
//--- 初めての計算、またはバーの数が変わった
  if(prev_calculated==0)
    {
    //--- MA の値を ColorLineBuffer 指標バッファに複製する
    int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
    if(copied<=0) return(0);// 複製に失敗。廃棄する。
    //--- バー全部で線の色を設定
    for(int i=0;i<rates_total;i++)
        ColorBuffer[i]=getIndexOfColor(i);
    }
  else
    {
    //--- MA の値を ColorLineBuffer 指標バッファに複製する
    int copied=CopyBuffer(MA_handle,0,0,rates_total,ColorLineBuffer);
    if(copied<=0) return(0);
 
     ticks++;// ティックを数える
    if(ticks>=5)//基本配色を変更する時
       {
        ticks=0; // カウンタをリセット
        modified++; // 色変換のカウンタ
        if(modified>=3)modified=0;// カウンタをリセット
        ResetLastError();
        switch(modified)
          {
          case 0:// 1 番目の基本配色
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrBlue);
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrGreen);
              Print("Color scheme "+modified);
              break;
          case 1:// 2 番目の基本配色
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrYellow);
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrPink);
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLightSlateGray);
              Print("Color scheme "+modified);
              break;
          default:// 3 番目の基本配色
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrLightGoldenrod);
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrchid);
              PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrLimeGreen);
              Print("Color scheme "+modified);
          }
       }
    else
       {
        //--- 開始位置を設定
        limit=prev_calculated-1;
        //--- バー全部で線の色を設定
        for(int i=limit;i<rates_total;i++)
           ColorBuffer[i]=getIndexOfColor(i);
       }
    }
//--- 次の呼び出しのために prev_calculated の値を返す
  return(rates_total);
 }
//+------------------------------------------------------------------+