Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1253

 
Vladimir Karputov:

Optimisation is performed by AGENTS (in your case, LOCAL AGENTS).

To view local agent logs: right click on the Log tab and go to the agent folder

That's the thing, there are no errors. Everything checks out. Maybe there's a firewall or something.

Files:
 
Aleksandr Dziuba:

That's the thing - there are no errors. Everything counts. Maybe there are firewalls or something?

Run a single test, a single pass. Not optimization, just a single pass. You'll be able to see the log that way.

 
Vladimir Karputov:

Run a single test - a single pass. Not optimisation, but a single pass. That way you can see the log for sure.

What do you mean, visual? Well, I got the log. I don't see anything bad there. Parameters are all passed. Even it ran, but the output is still 20,000.

Files:
20200924.log  17 kb
 
Aleksandr Dziuba:

What do you mean, visual? Well, I got the log. I don't see anything wrong with it. The parameters are all passed. Even it was executed. But the output Balance was 20000 and still is.

So, change the code so that it gives errormessages when there are errors or if the trade operation cannot be performed. Or in general, the code is wrong and does not give signals. Miracles do not happen.

Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений / Ошибки компиляции
Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений / Ошибки компиляции
  • www.mql5.com
Импортируемая функция не может иметь такого параметра (нельзя передавать указатель, класс или структуру, содержащую динамический массив, указатель, класс и т.д.) Недопустимый возвращаемый тип. Например, такая ошибка будет выдана для функций, импортированных из...
 
Vladimir Karputov:

So change the code so that it gives errormessages when errors occur or if the trade cannot be executed. Or the code is faulty and does not give any signals at all. There are no miracles.

Yeah.

So, optimization is not included to Ontick. OnInit is processed. But On-Tick is not generated. Here is the problem.

I integrated Print ( ) dots in inputs and outputs. Only Init is written into log.

P.S.

I handle errors. Force of habit. I've been writing programs since 1987.

 
Aleksandr Dziuba:

Yeah.

In general, the optimisation is not included in Ontick. OnInit is processed. But On Tick is not generated. The problem.

I integrated Print points ( ) in inputs and outputs. Only Init is written into log.

P.S.

I handle errors. Force of habit. I've been writing programs since 1987.

Only telepaths will be able to help without the code - and now all the telepaths are on holiday.

 
Vladimir Karputov:

Without the code, only telepaths can help - and now, as luck would have it, all the telepaths are on holiday.

I found the reason. For some reason, the indicators are not recalculated in Ontick (it does not give the number of recalculated bars). Maybe I need to update the quotes.

I have nevertheless lost my thanks. I have become smarter. I have learned where the logs are written.

 

Converted a simple indicator from MQL4 -> MQL5, but no signal on the last few bars. Please help me to find the reason. Source code and result is in attachment. I will paste here the converted one as well.

#property indicator_chart_window
#property indicator_plots   4
#property indicator_buffers 4
#property indicator_color1 PaleVioletRed
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Red
#property indicator_color4 LimeGreen

input int  dist2           = 21;       // Distance#2
input int  dist1           = 14;       // Distance#1

double b1[];
double b2[];
double b3[];
double b4[];

int    handle_atr;
int    min_rates_total;
double atr[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {

   SetIndexBuffer(0,b1,INDICATOR_DATA);
   SetIndexBuffer(1,b2,INDICATOR_DATA);
   SetIndexBuffer(2,b3,INDICATOR_DATA);
   SetIndexBuffer(3,b4,INDICATOR_DATA);
   
   ArraySetAsSeries(b1,true);
   ArraySetAsSeries(b2,true);
   ArraySetAsSeries(b3,true);
   ArraySetAsSeries(b4,true);

   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_LINE);
   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_ARROW);
   PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_ARROW);

      PlotIndexSetInteger(2,PLOT_ARROW,159);
      PlotIndexSetInteger(3,PLOT_ARROW,159);
   
   ResetLastError();
   handle_atr = iATR(NULL,PERIOD_CURRENT,50);
   if(handle_atr==INVALID_HANDLE) {
      Print("   ***   ATR handle was unable to create. Error ",GetLastError());
      return INIT_FAILED;
   }

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   
   PlotIndexSetString(0,PLOT_LABEL,"SuperSignals Upper");
   PlotIndexSetString(1,PLOT_LABEL,"SuperSignals Lower");
   PlotIndexSetString(2,PLOT_LABEL,"SuperSignals Sell");
   PlotIndexSetString(3,PLOT_LABEL,"SuperSignals Buy");

        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 counted_bars=prev_calculated;
   int i,limit;
   
   ArraySetAsSeries(Low,true);
   ArraySetAsSeries(High,true);

   if(counted_bars<0) return 0;
   if(counted_bars>0) counted_bars--;
           limit=rates_total-counted_bars;
           limit=MathMax(limit,dist1);
           limit=MathMax(limit,dist2);

   for (i = limit-1; i >= 0; i--) {
         int hhb1 = ArrayMaximum(High,i-dist1/2,dist1);
         int llb1 = ArrayMinimum(Low, i-dist1/2,dist1);
         int hhb  = ArrayMaximum(High,MathMax(0,i-dist2/2),dist2);
         int llb  = ArrayMinimum(Low, MathMax(0,i-dist2/2),dist2);

            b1[i] = EMPTY_VALUE;
            b2[i] = EMPTY_VALUE;
            b3[i] = EMPTY_VALUE;
            b4[i] = EMPTY_VALUE;
         
         ArraySetAsSeries(atr,true);
         int copied=CopyBuffer(handle_atr,0,0,limit,atr);
         if (copied<=0) Print("   ***   ATR failed to copy.");
         double tr = atr[i];

                      b1[i] = High[hhb];
                      b2[i] = Low[llb];
         if (i==hhb1) b3[i] = High[hhb1]+tr/2;
         if (i==llb1) b4[i] = Low[llb1] -tr/2;
    }
   
   return rates_total;
}
//+------------------------------------------------------------------+

The result.


 
Grigori.S.B:

Converted a simple indicator from MQL4 -> MQL5, but no signal on the last few bars. Please help me to find the reason. Source code and result is in attachment. I will paste here the converted one as well.

The result.


The culprit may be something not logically done between the platforms

Please pay attention to the different input parameters

MT4

ArrayMaximum
Ищет в одномерном числовом массиве максимальный элемент.

int  ArrayMaximum(
   const void&   array[],             // массив для поиска
   int           count=WHOLE_ARRAY,   // количество проверяемых
   int           start=0              // с какого индекса начинаем поиск
   );

MT5

ArrayMaximum
Ищет максимальный элемент в первом измерении многомерного числового массива.

int  ArrayMaximum(
   const void&   array[],             // массив для поиска
   int           start=0,             // с какого индекса начинаем поиск
   int           count=WHOLE_ARRAY    // количество проверяемых
   );
 
Vitaly Muzichenko:

Sort of the culprit could be something not logically done between platforms

Note the different input parameters

MT4

MT5

Thank you Vitaliy.

The order of variables in this place is correct. I have swapped them during conversion. Also iHighest / iLowest functions were in MQL4.

This is something else. I have already racked my brains.