Помогите решить проблему и указать причину.

 

Задался идеей сделать разноцветные точки на графике.
Выбрал  DRAW_COLOR_ARROW.

Для его реализации нужен дополнительный буфер INDICATOR_COLOR_INDEX.

Погулив - нашёл пример кода. А он как и мои старания оказался не рабочий.

Вот и прошу - помогите - укажите в чём ошибка - что не так?

//+------------------------------------------------------------------+
//|                                                          Tst.mq5 |
//+------------------------------------------------------------------+
#property strict

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2

#property indicator_type1 DRAW_COLOR_ARROW
#property indicator_width1 1
#property indicator_color1 clrRed,clrBlue

#property indicator_type2 DRAW_COLOR_ARROW
#property indicator_width2 1
#property indicator_color2 clrRed,clrBlue

const int arrow_code=75;

double Buff1[],Buff2[],Buff1_clr[],Buff2_clr[]; 

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnInit(){
  
  SetIndexBuffer     (0,Buff1,INDICATOR_DATA);
  SetIndexBuffer     (1,Buff1_clr,INDICATOR_COLOR_INDEX);
  PlotIndexSetInteger(0,PLOT_ARROW,arrow_code);
  PlotIndexSetDouble (0,PLOT_EMPTY_VALUE,0);
  PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
  PlotIndexSetInteger(0,PLOT_LINE_WIDTH,3);

  SetIndexBuffer     (2,Buff2,INDICATOR_DATA);
  SetIndexBuffer     (3,Buff2_clr,INDICATOR_COLOR_INDEX);
  PlotIndexSetInteger(2,PLOT_ARROW,arrow_code); // Не работает
  PlotIndexSetDouble (2,PLOT_EMPTY_VALUE,0);
  PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);
  PlotIndexSetInteger(2,PLOT_LINE_WIDTH,3);     // Не работает
  
  IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
  IndicatorSetString(INDICATOR_SHORTNAME,"Test"); 
return;}//OnInit

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
return;}//OnDeinit

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[]){
  int first=0;
  if(prev_calculated==0)first=0;
  else first = prev_calculated-1;
  for(int bar=first; bar<rates_total; bar++){
    Buff1[bar]=high[bar];
    Buff2[bar]=low[bar];
    Buff1_clr[bar]=1;
    Buff2_clr[bar]=0;
  }
return(rates_total);}//OnCalulate

Код естественно облегчил сильно - для примера. Строчки которые не работают пометил "Не работают".

Жду ответа - за ранее благодарен. Не судите строго - только недавно начал осваивать mql5....



 
Всегда, всегда используйте MQL Wizard для создания заготовки индикатора. Wizard сразу корректно пропишет индикаторные буфера и графические построения. Создайте заготовки при помощи Wizard и выложите результат.
 
#property indicator_separate_window       // Индик. рисуется в отдельном окне
#property indicator_buffers 3          // Количество буферов
#property indicator_color1 Red         // Цвет первой линии
#property indicator_color2 Blue        // Цвет второй линии
#property indicator_color3 Green       // Цвет третьей линии

.....

int OnInit()                             // Специальная функция init()
  {
   //--------------------------------------------------------------------
   SetIndexBuffer(0,Line_0);           // Назначение массива буферу 0
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); // Стиль линии
//--------------------------------------------------------------------
   SetIndexBuffer(1,Line_1);           // Назначение массива буферу 1
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2); // Стиль линии
//--------------------------------------------------------------------
   SetIndexBuffer(2,Line_2);           // Назначение массива буферу 2
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2); // Стиль линии

....
можно так, или главное обьявить количество индикаторных буферов в свойствах это пропети, и в сетиндексбуфер и сетиндекстайл правильно добавить назначение массива буферу (это очень важно) и свойства стилю, которые вы можете добавить где угодно.
 

Всё вроде понял. Спасибо Vladimir Karputov за подсказку по поводу  MQL Wizard. Помогло.

Ох и трудно с первого раза понять после MQL4. Вот как должно быть - может кому пригодится.

//+------------------------------------------------------------------+
//|                                                       Test_2.mq5 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_COLOR_ARROW
#property indicator_color1  clrRed,clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Label2
#property indicator_label2  "Label2"
#property indicator_type2   DRAW_COLOR_ARROW
#property indicator_color2  clrRed,clrBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input int      Arrow_Code=75; // Arrow Code
//--- indicator buffers
double         Buff1[],Buff2[],Buff2_clr[],Buff1_clr[];
         
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(){

   SetIndexBuffer(0,Buff1,INDICATOR_DATA);
   SetIndexBuffer(1,Buff1_clr,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,Buff2,INDICATOR_DATA);
   SetIndexBuffer(3,Buff2_clr,INDICATOR_COLOR_INDEX);

   PlotIndexSetInteger(0,PLOT_ARROW,Arrow_Code);
   PlotIndexSetDouble (0,PLOT_EMPTY_VALUE,0);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,3);
   
   PlotIndexSetInteger(1,PLOT_ARROW,Arrow_Code);
   PlotIndexSetDouble (1,PLOT_EMPTY_VALUE,0);
   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,3);
   
  IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
  IndicatorSetString(INDICATOR_SHORTNAME,"Test"); 

return(INIT_SUCCEEDED);}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[]){
  int first=0;
  if(prev_calculated==0)first=0;
  else first = prev_calculated-1;
  for(int bar=first; bar<rates_total; bar++){
    Buff1[bar]=high[bar];
    Buff2[bar]=low[bar];
    Buff1_clr[bar]=1;
    Buff2_clr[bar]=0;
  }
return(rates_total);}

Всем спасибо! Получил что хотел.

Причина обращения: