Errores, fallos, preguntas - página 1793

 
fxsaber:

¿Y es posible escribir una función así?

Sí, es necesario implementar un constructor y un operador de copia
 
Slawa:

Hay un error en el tipo de dibujo DRAW_CANDLES después de actualizarlo: hago todo como se describe aquí: https://www.mql5.com/ru/forum/23/page19#comment_2891050

No se puede cambiar el tipo de construcción (1-2-3) seleccionando a través de los parámetros de entrada. Código:

#property indicator_separate_window
#property indicator_plots 1
#property indicator_buffers 4                          
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//--- Перечисление - новые типы отрисовки DRAW_CANDLE
enum ENUM_DRAW_CANDLE_TYPE
  {
   DRAW_CANDLE_TYPE_1,            // Один цвет: #1 - контуры и тела
   DRAW_CANDLE_TYPE_2,            // Два цвета: #1 - контуры, #2 - тела
   DRAW_CANDLE_TYPE_3             // Три цвета: #1 - контуры, #2 - восход., #3 - нисход.
  };
//---
double bufopen[];
double bufhigh[];
double buflow[];
double bufclose[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
input ENUM_DRAW_CANDLE_TYPE inpDrawCandleStyle=DRAW_CANDLE_TYPE_1;
input color inpClr1 = clrWhite;
input color inpClr2 = clrLime;
input color inpClr3 = clrRed;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Привязываем буферы
   SetIndexBuffer(0,bufopen,INDICATOR_DATA);
   SetIndexBuffer(1,bufhigh,INDICATOR_DATA);
   SetIndexBuffer(2,buflow,INDICATOR_DATA);
   SetIndexBuffer(3,bufclose,INDICATOR_DATA);
//--- Устанавливаем тип графического построения
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_CANDLES);
//--- Устанавливаем пустые значения в буферах
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
//--- Устанавливаем цвета индикатора
   switch(inpDrawCandleStyle) // В зависимости от типа построения свечей
     {
      case DRAW_CANDLE_TYPE_1:                                          // Если все свечи одним цветом
         ////--- Устанавливаем количество цветов стиля (не помогает)
         //PlotIndexGetInteger( 0, PLOT_COLOR_INDEXES, 1 );
         //---
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpClr1);
         break;
      case DRAW_CANDLE_TYPE_2:                                          // Если контуры цветом #1, а тела - цветом #2
         ////--- Устанавливаем количество цветов стиля (не помогает)
         //PlotIndexGetInteger( 0, PLOT_COLOR_INDEXES, 2 );
         //--- Устанавливаем цвет индикатора
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpClr1);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpClr2);
         break;
      case DRAW_CANDLE_TYPE_3:                                          // Если контуры цветом #1, восх - #2, нисх - #3
         ////--- Устанавливаем количество цветов стиля (не помогает)
         //PlotIndexGetInteger( 0, PLOT_COLOR_INDEXES, 3 );
         //--- Устанавливаем цвет индикатора
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpClr1);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpClr2);
         PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,inpClr3);
         break;
      default:                                                         // Если тип построения не определен
         Print(__FUNCTION__,": ОШИБКА! Неизвестный тип построения свечей '"+EnumToString(inpDrawCandleStyle)+"'");
         return(INIT_FAILED);                                          // Выходим с ошибкой
     }
//---
   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[])
  {
//---
   if(prev_calculated<=0)
      for(int i=0; i<rates_total; i++)
        {
         bufopen[ i ] = open[ i ];
         bufhigh[ i ] = high[ i ];
         buflow[i]=low[i];
         bufclose[i]=close[i];
        }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Específicamente - el primer tipo (velas + contornos primer color) funciona bien, no cambia a los otros.

Añadido:

Si establece los colores a través de la directiva del preprocesador - todo bien, pero entonces también es imposible cambiar el tipo de dibujo DRAW_CANDLES.

Список изменений в билдах MetaTrader 5 Client Terminal
Список изменений в билдах MetaTrader 5 Client Terminal
  • www.mql5.com
Автоматическое обновление доступно через систему LiveUpdate:.
 
Комбинатор:
Sí, necesitamos implementar un constructor y un operador de copia
Lamentablemente, esta solución sólo funciona para la estructura personalizada. En el ejemplo de MqlTradeRequest.
 
Alexey Kozitsyn:

Hay un error en el tipo de dibujo DRAW_CANDLES después de actualizarlo: hago todo como se describe aquí: https://www.mql5.com/ru/forum/23/page19#comment_2891050

No se puede cambiar el tipo de construcción (1-2-3) seleccionando a través de los parámetros de entrada. Código:

Tienes un error en tu código, deberías usar PlotIndexSetInteger:

         ////--- Устанавливаем количество цветов стиля (не помогает)
         PlotIndexSet Integer( 0, PLOT_COLOR_INDEXES, 3 );
 
fxsaber:
Lamentablemente, esta solución sólo funciona para la estructura personalizada. En el ejemplo MqlTradeRequest.
A continuación, pasar la estructura por referencia en los parámetros. Otra opción es hacer tu propia copia de la estructura y fundirla, pero hay que pensar cómo hacerla bonita.
 
Anton:
Tienes un error en tu código, deberías usar PlotIndexSetInteger:

         ////--- Устанавливаем количество цветов стиля (не помогает)
         PlotIndexSet Integer( 0, PLOT_COLOR_INDEXES, 3 );
Cielos, cierto, ¡gracias!
 
Комбинатор:
A continuación, pasar la estructura por referencia en los parámetros. Otra opción es hacer tu propia copia de la estructura y el reparto, pero tienes que pensar cómo hacerlo bien.
No lo entiendo.
 
fxsaber:
No lo entiendo.
struct MyTradeRequest
{
  // копия MqlTradeRequest
  // + нужные операторы
};

// ...
MyTradeRequest request = Function();
MqlTradeResult = {0};
OrderSend((MqlTradeRequest)request, result);
// ...
Es sólo una idea, puede haber errores, he escrito directamente en el navegador
 
Комбинатор:
struct MyTradeRequest
{
  // копия MqlTradeRequest
  // + нужные операторы
};

// ...
MyTradeRequest request = Function();
MqlTradeResult = {0};
OrderSend((MqlTradeRequest)request, result);
// ...
Es sólo una idea, puede haber errores, he escrito directamente en el navegador
Entiendo la idea. Pero ese tipo de casting no funcionará, ¿verdad?
 
fxsaber:
Entiendo la idea. Pero ese tipo de reparto no funcionará.
¿Por qué no?