проблема с отображением индикатора - страница 2

 
Vladimir Karputov:

Значит где-то в расчётах пропускаете один или несколько баров (а возможно в этих барах или оставляете значение "0" или даже принудительно ставите "0"). Вот отрезок и рисует от цены с графика вниз в пропасть к нулю (а может даже не к нулю, а к какому-то значению со знаком минус).


спасибо, нашел баг, а по разукрашке не поможете, читал, пробовал, не получается, я просто раньше один буфер в два цвета не красил, не пойму как это сделать

 
Dmitry Melnichenko:

спасибо, нашел баг, а по разукрашке не поможете, читал, пробовал, не получается, я просто раньше один буфер в два цвета не красил, не пойму как это сделать


Чоб я так помнил :). 

Сейчас сам открою справку и напишу пример :)

 
Vladimir Karputov:

Чоб я так помнил :). 

Сейчас сам открою справку и напишу пример :)


спасибо огромное

 
Vladimir Karputov:

Чоб я так помнил :). 

Сейчас сам открою справку и напишу пример :)


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

Файлы:
jigdf2e_4.png  73 kb
 

или даже так

Файлы:
dapa4km_5.png  55 kb
 

Итак, пример: 

DRAW_COLOR_SECTION_easy

Должен менять цвет через КАЖДЫЕ "The length of sections in bars" - но что-то напутал - то через 9, то через 10 рисует. Но думаю, это не важно - главное что это максимально облегчённый пример рисования стилем рисования DRAW_COLOR_SECTION.

Цвет присваивается здесь:

      if(bars<bars_in_section)
        {
         //---
         ColorSectionBuffer[i]=high[i];
         ColorSectionColors[i]=0;
        }
      else
        {
         //---
         ColorSectionBuffer[i]=low[i];
         ColorSectionColors[i]=1;
        }

а сами цвета (их два) задаются в "шапке":

#property indicator_color1  clrRed,clrBlue


Сам код:

//+------------------------------------------------------------------+
//|                                      DRAW_COLOR_SECTION_easy.mq5 |
//|                              Copyright © 2017, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.000"
#property description "An example of drawing with the style \"DRAW_COLOR_SECTION\""
#property description "    - change the color every ten bars"
#property indicator_chart_window 
#property indicator_buffers 2 
#property indicator_plots   1 
//--- plot ColorSection 
#property indicator_label1  "ColorSection" 
#property indicator_type1   DRAW_COLOR_SECTION 
//--- Define 8 colors for coloring sections (they are stored in a special array) 
#property indicator_color1  clrRed,clrBlue
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  3 
//--- input parameters 
input int      bars_in_section=10;        // The length of sections in bars 
//--- A buffer for plotting 
double         ColorSectionBuffer[];
//--- A buffer for storing the line color on each bar 
double         ColorSectionColors[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ColorSectionBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ColorSectionColors,INDICATOR_COLOR_INDEX);
//--- The 0 (empty) value will mot participate in drawing 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//--- Check the indicator parameter 
   if(bars_in_section<=0)
     {
      PrintFormat("Invalid section length=%d",bars_in_section);
      return(INIT_PARAMETERS_INCORRECT);
     }
//---
   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[])
  {
/* 
ATTENTION! Index "0" in the buffers 
   ColorSectionBuffer
   ColorSectionColors
   time[]
   open[]
   high[]
   low[]
   close[]
   tick_volume[]
   volume[]
   spread[]
on the chart - this is the LEFT bar!
*/
//---
   static long bars=0;
   static datetime prev_time=0;
//--- The number of the bar from which the calculation of indicator values starts 
   int start=0;
//--- If the indicator has been calculated before, then set start on the previous bar 
   if(prev_calculated>0)
      start=prev_calculated-1;
//--- Here are all the calculations of the indicator values 
   for(int i=start;i<rates_total;i++)
     {
      if(bars>=bars_in_section*2)
         bars=0;
      if(bars<bars_in_section)
        {
         //---
         ColorSectionBuffer[i]=high[i];
         ColorSectionColors[i]=0;
        }
      else
        {
         //---
         ColorSectionBuffer[i]=low[i];
         ColorSectionColors[i]=1;
        }
      if(time[i]>prev_time)
        {
         bars++;
         prev_time=time[i];
        }
     }
//--- Return the prev_calculated value for the next call of the function 
   return(rates_total);
  }
//+------------------------------------------------------------------+
Файлы:
 
Vladimir Karputov:

Итак, пример: 

Должен менять цвет через КАЖДЫЕ "The length of sections in bars" - но что-то напутал - то через 9, то через 10 рисует. Но думаю, это не важно - главное что это максимально облегчённый пример рисования стилем рисования DRAW_COLOR_SECTION.

Цвет присваивается здесь:

а сами цвета (их два) задаются в "шапке":


Сам код:


спасибо, но не пойму почему arrows разлетаються при смене Таймфрейма

 

я сделал так

   for(int a=MathMin(ProceedMaxHistoryBars,rates_total-fractalBarsOnEachSide-1);a>=fractalBarsOnEachSide;a--)

   {

      if(Long[a]!=EMPTY_VALUE && Long[a]!=0)

      {

         Section[a]=low[a];

         if(Section[a]>last)SectColor[a]=0;

         else SectColor[a]=1;

         last=Section[a];

      }

      else if(Short[a]!=EMPTY_VALUE && Short[a]!=0)

      {

         Section[a]=high[a];

         if(Section[a]>last)SectColor[a]=0;

         else SectColor[a]=1;

         last=Section[a];

      }

      else Section[a]=EMPTY_VALUE;

   }

 
Dmitry Melnichenko:

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


Для этого добавил в OnInit() (версия 1.001) принудительное заполнение индикаторных буферов:

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ColorSectionBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ColorSectionColors,INDICATOR_COLOR_INDEX);
//--- The 0 (empty) value will mot participate in drawing 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//--- Check the indicator parameter 
   if(bars_in_section<=0)
     {
      PrintFormat("Invalid section length=%d",bars_in_section);
      return(INIT_PARAMETERS_INCORRECT);
     }
   ArrayInitialize(ColorSectionBuffer,0);
   ArrayInitialize(ColorSectionColors,0);
//---
   return(INIT_SUCCEEDED);
  }
Файлы:
 
Vladimir Karputov:

Для этого добавил в OnInit() (версия 1.001) принудительное заполнение индикаторных буферов:


спасибо, но arrows при смене тф все равно раскидывает по графику!!!

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