PlotIndexSetInteger

该函数建立一定特征的相应值,指标性质应该是整型,图表型,布尔型或者颜色型。有两种变量函数。

调用指定的属性标识符。

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

示例:这是画有三色线的指标。每五个节点改变一次颜色。

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//---- 图线颜色

#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);// 第一指数

   if(j<200) return(1);// 第二指数

   return(2); // 第三指数

  }

//+------------------------------------------------------------------+

//| 自定义指标反复函数                                                  |

//+------------------------------------------------------------------+

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:// 第一配色方案

               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:// 第二配色方案

               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:// 第三配色方案

               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);

  }

//+------------------------------------------------------------------+