Errors, bugs, questions - page 1793

 
fxsaber:

And is it possible to write such a function?

Yes, you need to implement a constructor and copy operator
 
Slawa:

There is an error in drawing type DRAW_CANDLES after updating it: I do everything as described here: https://www.mql5.com/ru/forum/23/page19#comment_2891050

Cannot change the build type (1-2-3) by selecting via input parameters. Code:

#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);
  }
//+------------------------------------------------------------------+

Specifically - the first type (candles + contours first colour) works fine, it doesn't switch to the others.

Added:

If you set colours via preprocessor directive - all ok, but then also impossible to change the drawing type DRAW_CANDLES.

Список изменений в билдах MetaTrader 5 Client Terminal
Список изменений в билдах MetaTrader 5 Client Terminal
  • www.mql5.com
Автоматическое обновление доступно через систему LiveUpdate:.
 
Комбинатор:
Yes, we need to implement a constructor and copy operator
Unfortunately, this solution works only for custom structure. In the example of MqlTradeRequest.
 
Alexey Kozitsyn:

There is an error in drawing type DRAW_CANDLES after updating it: I do everything as described here: https://www.mql5.com/ru/forum/23/page19#comment_2891050

Cannot change the build type (1-2-3) by selecting via input parameters. Code:

You have an error in your code, you should use PlotIndexSetInteger:

         ////--- Устанавливаем количество цветов стиля (не помогает)
         PlotIndexSet Integer( 0, PLOT_COLOR_INDEXES, 3 );
 
fxsaber:
Unfortunately, this solution works only for custom structure. In the MqlTradeRequest example.
Then pass the structure by reference in parameters. Another option is to make your own copy of the structure and cast it, but we have to think how to make it nice.
 
Anton:
You have an error in your code, you should use PlotIndexSetInteger:

         ////--- Устанавливаем количество цветов стиля (не помогает)
         PlotIndexSet Integer( 0, PLOT_COLOR_INDEXES, 3 );
Geez, right, thanks!
 
Комбинатор:
Then pass the structure by reference in the parameters. Another option is to make your own copy of the structure and cast, but you have to think how to do it nicely.
I don't get it.
 
fxsaber:
I don't get it.
struct MyTradeRequest
{
  // копия MqlTradeRequest
  // + нужные операторы
};

// ...
MyTradeRequest request = Function();
MqlTradeResult = {0};
OrderSend((MqlTradeRequest)request, result);
// ...
It's just an idea, there may be errors, I wrote directly in the browser
 
Комбинатор:
struct MyTradeRequest
{
  // копия MqlTradeRequest
  // + нужные операторы
};

// ...
MyTradeRequest request = Function();
MqlTradeResult = {0};
OrderSend((MqlTradeRequest)request, result);
// ...
It's just an idea, there may be errors, I wrote directly in the browser
I get the idea. But that kind of casting won't work, will it?
 
fxsaber:
I get the idea. But that kind of casting won't work.
Why not?