Erros, bugs, perguntas - página 1093

 
zfs:
Esvaziar aí, mesmo que a cor esteja definida no código. Com tudo isso, o resultado positivo estava lá, mas desapareceu, por muito ridículo que pareça).
Então um pequeno código reproduzindo o problema ajudaria a resolvê-lo.
 
tol64:
Então um código curto que reproduza o problema ajudará.
#property indicator_separate_window

#property indicator_buffers 6                 // Количество буферов для расчёта индикатора
#property indicator_plots   2                 // Количество графических серий

#property  indicator_label1  "Open;High;Low;Close"

//перечисление методов отображения индикатора
enum ViewInd
  {
   Line,               // линии
   Bar,                // бары
   Candles             // свечи
  }; 
  
input ViewInd      _ViewInd= Line;     //вид индикатора  

double op[],cl[],hi[],lo[],s[];
double buffer_color_line[];//Буфер для индекса цвета



int OnInit()
  {
   for (int i=0;i<=5;i++)
    PlotIndexSetDouble(i,PLOT_EMPTY_VALUE,0);
   ArrayInitialize(op,0);ArrayInitialize(cl,0);  
   ArrayInitialize(hi,0);ArrayInitialize(lo,0);  
   ArrayInitialize(s,0);     

    
   if(_ViewInd==Line){
    SetIndexBuffer(5,s,INDICATOR_DATA);//Привязка массива к буферу
    PlotIndexSetInteger(5,PLOT_DRAW_TYPE,DRAW_LINE);
    PlotIndexSetInteger(5,PLOT_LINE_STYLE,STYLE_SOLID);
    PlotIndexSetInteger(5,PLOT_LINE_COLOR,clrRed);
    ArraySetAsSeries(s,true);
   }
   else{
   SetIndexBuffer(0,op,INDICATOR_DATA);
   SetIndexBuffer(1,hi,INDICATOR_DATA);
   SetIndexBuffer(2,lo,INDICATOR_DATA);
   SetIndexBuffer(3,cl,INDICATOR_DATA);
   SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);//Сопоставляем массив-буфер индексов цветов с буфером индикатора
   ArraySetAsSeries(op,true);
   ArraySetAsSeries(hi,true);
   ArraySetAsSeries(lo,true);
   ArraySetAsSeries(cl,true);   
   ArraySetAsSeries(buffer_color_line,true);      
//Задаем количество индексов цветов для графического построения
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
   if (_ViewInd==Candles)PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_COLOR_CANDLES); else
    PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_BARS);
//Задаем цвет для каждого индекса
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrBlue);   //Нулевой индекс -> Синий
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrOrange); //Первый индекс  -> Оранжевый   
   }   
//---
   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 limit;//MQL 4 RULEZZZ
   int counted_bars=prev_calculated;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=rates_total-counted_bars;
   
   for (int i=0;i<limit;i++){
    if(_ViewInd==Line)s[i]=MathRand();
    else{
     op[i]=MathRand();
     cl[i]=MathRand();
   if (op[i]>cl[i])buffer_color_line[i]=1;else buffer_color_line[i]=0;
     hi[i]=32767;
     lo[i]=0;        
    }  
   }

   return(rates_total);
  }
//+------------------------------------------------------------------+
É algo parecido com isto.
 
zfs:
Assim.

É assim que aparecerão os valores após o nome curto

for (int i=0;i<=5;i++)
    {PlotIndexSetDouble(i,PLOT_EMPTY_VALUE,0);};
Trata-se da ordem nos amortecedores. https://www.mql5.com/ru/forum/12882#comment_539990
В каком порядке делать SetIndexBuffer() и зависит ли он он порядка директив #property indicator_x ?
В каком порядке делать SetIndexBuffer() и зависит ли он он порядка директив #property indicator_x ?
  • www.mql5.com
может ли кто-то на пальцах обьяснить правила привязки индикаторного буфера к опр.
 
E como isso me ajuda, não compreendo nada). Algo pode ser mudado para que funcione, mas ainda está torto, e eu gostaria de saber mais sobre isso.
 
zfs:
É algo parecido com isto.

Caos total e confusão. ) Aqui está uma versão de trabalho (corrigiu os erros e escovou-a):

//+------------------------------------------------------------------+
//|                                                        #Test.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
//---
#property indicator_buffers 5 // Количество буферов для расчёта индикатора
#property indicator_plots   1 // Количество графических серий
//---
#property  indicator_color1  clrDodgerBlue,C'0,50,100'
//--- Перечисление методов отображения индикатора
enum ViewInd
  {
   Line,   // линии
   Bar,    // бары
   Candles // свечи
  };
//--- Внешние параметры
input ViewInd _ViewInd=Line; // Вид индикатора  
//---
double op[],cl[],hi[],lo[];
double buffer_color_line[]; // Буфер для индекса цвета
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(_ViewInd==Line)
     {
      //--- Привязка массива к буферу
      SetIndexBuffer(0,cl,INDICATOR_DATA);
      //---
      PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
      PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_SOLID);
     }
   else
     {
      SetIndexBuffer(0,op,INDICATOR_DATA);
      SetIndexBuffer(1,hi,INDICATOR_DATA);
      SetIndexBuffer(2,lo,INDICATOR_DATA);
      SetIndexBuffer(3,cl,INDICATOR_DATA);
      //--- Сопоставляем массив-буфер индексов цветов с буфером индикатора
      SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);
      //---
      if(_ViewInd==Candles)
         PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_CANDLES);
      else
         PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_BARS);
     }
//--- Установим метки для текущего таймфрейма
//    В режиме линия только цена закрытия
   if(_ViewInd==Line)
      PlotIndexSetString(0,PLOT_LABEL,"Close");
//--- В других режимах все цены баров/свеч
//    В качестве разделителя используется ";"
   else if(_ViewInd==Bar || _ViewInd==Candles)
      PlotIndexSetString(0,PLOT_LABEL,"Open;"+"High;"+"Low;"+"Close");
//---
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
//---
   ArrayInitialize(op,0);
   ArrayInitialize(cl,0);
   ArrayInitialize(hi,0);
   ArrayInitialize(lo,0);
//---
   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 limit=0; //MQL 4 RULEZZZ
//---
   if(prev_calculated==0)
      limit=0;
   else
      limit=prev_calculated-1;
//---
   for(int i=limit; i<rates_total; i++)
     {
      if(_ViewInd==Line)
         cl[i]=MathRand();
      else
        {
         op[i]=MathRand();
         cl[i]=MathRand();
         hi[i]=32767;
         lo[i]=1;
         //---
         if(op[i]>cl[i])
            buffer_color_line[i]=1;
         else
            buffer_color_line[i]=0;
        }
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Como é que funciona

if(_ViewInd==Line){
}
   else{

if (_ViewInd==Candles)
else

se

enum ViewInd
  {
   Line,               // линии
   Bar,                // бары
   Candles             // свечи
  }; 

?

Verificar duas vezes todas as condições e parênteses, e sem um laço, definir as propriedades tampão de forma linear, ordenar a partir da ligação acima.

 
Silent:

...

Verificar duas vezes todas as condições e parênteses, e definir as propriedades tampão linearmente sem um laço, ordenar a partir da ligação acima.

Não é de todo necessário um laço. Mais precisamente, a propriedade só precisa de ser definida para um buffer, em todas as opções de mapeamento.
 
tol64:
Não há qualquer necessidade de um laço.
Geralmente sim, mas se houver muitos amortecedores, é mais curto :-) embora eu não faça isso. É mais fácil para mim ler retratos lineares.
 
Silent:
Geralmente sim, mas se houver muitos amortecedores, é mais curto :-) embora eu não faça isso. É mais fácil para mim ler portmanteaus lineares.
De facto, pode haver tantos tampões (máx. 512), que é muito mais difícil ler o tricô sem os laços. ) Nesta variante existe apenas um tampão.
 
tol64:
Não há qualquer necessidade de um laço.
Óptimo). Obrigado. Como um relógio. O conhaque está a arrefecer).
Razão: