Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 682

 

I have a large programme with the same type of objects. I mean many types. But they are repeated in different modules of the program. And in the logs, after testing is complete, for example, I get xxx undeleted objects. And so on several types.

How can I find out where I'm not deleting objects? Is there some toolkit for this?

 
mbjen:

I have a large programme with the same type of objects. I mean many types. But they are repeated in different modules of the program. And in the logs, after testing is complete, for example, I get xxx undeleted objects. And so on several types.

How can I find out where I'm not deleting objects? Is there some toolkit for this?

Bug of the 1930 build.

 
The test EA somehow opened BUYSTOP below the price! Now I cannot even close the order manually. How is this even possible?
Files:
 

I was surprised to find that MQl5 supports OpenCL

Hasn't anyone written an optimiser for robots during this time, so that millions of runs would not go on for centuries, but at least for years? :)

 
Igor Makanu:

it means you are counting on every tick the code you submitted and not initializingSredRazmax andSredRazmin variables

It's a good habit to initialize variables before using them - that's what they teach at universities, it reduces the time it takes to find bugs ;)

I initialised them at the beginning, and in the comment you can see another array element by element (to check and 0 does not change, so the formula should work,) Here is the full code:

//+------------------------------------------------------------------+
//|                                                           01.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 1
//#property indicator_color1 Red
//#property indicator_width1 1

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;
extern int nn=30;

int shift, ww=0;
double zz, SredRazmax, SredRazmin, Sredn; 
double HZZ[];


int OnInit()
  {
//--- indicator buffers mapping
    SetIndexBuffer(0, HZZ);
 // SetIndexStyle(0, DRAW_SECTION);
//---
   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[])
  {
//---
  for(shift = 0; shift <= Bars-1; shift++)
  {
      zz = iCustom(NULL, 0, "ZigZag", ExtDepth, ExtDeviation, ExtBackstep, 0, shift);
           if(zz > 0.0)
           {
           HZZ[ww]=zz;
           ww++;          
           }
  }
   
  
       for(ww=0;ww<=nn;ww++)
       {
      if(HZZ[ww]>HZZ[ww+1]){SredRazmax += HZZ[ww];}     
      if(HZZ[ww]<HZZ[ww+1]){SredRazmin += HZZ[ww+1];}
      
       
  Comment("Средний размах = ", (SredRazmax-SredRazmin)/nn,",",HZZ[0],",",HZZ[1],",",HZZ[2],",",HZZ[3],",",HZZ[4]); 
        }      
   
//---------------------------------------------+
//расчет среднего значения           
//---------------------------------------------+      

   //    for(ww=0;ww<=nn;ww++){
   //    if(HZZ[ww]>HZZ[ww+1]){Sredn += HZZ[ww]-HZZ[ww+1];}     
   //    if(HZZ[ww]<HZZ[ww+1]){Sredn += HZZ[ww+1]-HZZ[ww];}
       
 // Comment("Средний размах = ", Sredn,",",HZZ[0],",",HZZ[1],",",HZZ[2],",",HZZ[3],",",HZZ[4]); 

            
         
     
       
//--- return value of prev_calculated for next call
    return(0);

  }
 
Artyom Trishkin:

Bug from build 1930.

What is it? I have MT4. Build 1090.

 
mbjen:

What is it? I have MT4. Build 1090.

An object created by means of new must either be attached to an object array or deleted by itself in OnDeinit()
 
Dmitry Belov:

I initialised them at the beginning, and the comment outputs another array element by element (to check to see and 0 does not change, so the formula should work,) Here is the full code:

You didn't initialize them at the beginning or anywhere else, you just declared them

I wrote before using, i.e. if you have variables SredRazmax, SredRazmin, Sredn are sums of array values, then to correctly calculate the sum, you need to zero the variable and then add the array values and save them in this variable

i.e.

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[])
  {
//---
    SredRazmax = 0.0;
    SredRazmin = 0.0;
    Sredn = 0.0;
    .....

And the second, what you have a question, in the indicator every tick will callOnCalculate() and it means you will constantly count the tops of ZigZag at every tick, i.e. approximately 40-60 times per second

 
Artyom Trishkin:
An object created by new must either be attached to an object array or deleted by itself in OnDeinit()

Thank you for the enlightenment. But you should at least read my question.

 
mbjen:

Thank you for the enlightenment. But you should at least read my question.

I did and I answered it.
Reason: