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

 
Alexey Viktorov:

Time minus time divided by PeriodSeconds()

so it could be the wrong length at the Friday-Monday transition (or if there are missed bars in the history)

it is better to read point time and then define bars

datetime time1=(datetime)ObjectGetInteger(ExtChartID,name,OBJPROP_TIME,0);
datetime time2=(datetime)ObjectGetInteger(ExtChartID,name,OBJPROP_TIME,1);

int bar1=iBarShift(_Symbol,_Period,time1);
int bar2=iBarShift(_Symbol,_Period,time2);
 
Taras Slobodyanik:

so it could be the wrong length at the Friday-Monday transition (or if there are missed bars in the history)

it is better to read the time of the points and then identify the bars

Agreed. Didn't bother myself or my brain. Then it is better to take the number of bars between dates.

int  Bars( 
   string           symbol_name,     // имя символа 
   ENUM_TIMEFRAMES  timeframe,       // период 
   datetime         start_time,      // с какой даты 
   datetime         stop_time        // по какую дату 
   );
 
int start()
{
  if(Check()==false)
      return;  
      
  int TotalOrders;
  double NewPrice, NewLots, NewTP, NewSL;
  /*****************************************************************************/
  /* Здесь часть кода, которая работает при каждом новом тике                  */ 
  /*****************************************************************************/
  TotalOrders = CountOfOrders(); 
     double sprd = Ask-Bid;
     int tot = CountOfOrders2();
     double spred = spred/Point*(tot-1);

  if(tot > 1)PercCloseDown();


This part says error



Can you tell me how to start the robot?


 
Ivan Butko:

This part writes an error

How do I get the robot to start?

Here the variable is declared and immediately it is divided:

double spred = spred/Point*(tot-1); 

The error shows that the compiler treats this variable (spred) as undeclared. This is also at least not good, because it (variable) is not initialized - since it is nota global variable, it may have an undefined value...

Try declaring it earlier and assigning a value to it
 
Yevhenii Levchenko:

Here a variable is declared and immediately it is shared:

The error shows that the compiler treats this variable (spred) as undeclared. This is also at least not good, because it (the variable) is not initialized - since it is not a global variable, there may be an undefined value...

Try to declare it earlier and assign a value to it

Eugene, from the bottom of my heart!
It's on, thank you.

 

What to do if in MQL5 ...

if(BarsCalculated(handle) == -1)

... it's been about a minute and the problem is the same. Why so long?


Error 4806 - Requested data not found ... - ...how do I make my EA find it?

 
Ivan Butko:
int start()
{
  if(Check()==false)
      return;  
      
  int TotalOrders;
  double NewPrice, NewLots, NewTP, NewSL;
  /*****************************************************************************/
  /* Здесь часть кода, которая работает при каждом новом тике                  */ 
  /*****************************************************************************/
  TotalOrders = CountOfOrders(); 
     double sprd = Ask-Bid;
     int tot = CountOfOrders2();
     double spred = spred/Point*(tot-1);

  if(tot > 1)PercCloseDown();


This part says error



Can you tell me how to start the robot?


Line 61, which line is it?
 

How do I catch the out of memory error?


What could be causing this message in the first place?


I've written a program of about 20 thousand lines. I have a lot of different classes, arrays and structures.

Approximately once every two or three days the "out of memory" message pops up.

I don't know how to track down which function is responsible for memory leak.

 
Sergey Likho:

How do I catch the out of memory error?


What could be causing this message in the first place?


I've written a program of about 20 thousand lines. I have a lot of different classes, arrays and structures.

Approximately once every two or three days the "out of memory" message pops up.

I don't know how to catch it, which function is responsible for memory leak.

Make sure each new has its own delete

That is, only through careful reading of your code. To make reading easier and more fun, you can comment it out :-)

It is also a good idea to write test-case scripts for each class and check leaks inside classes that way.

 
Maxim Kuznetsov:

make sure that each new has its own delete

That is, just by reading the code carefully. To make reading easier and more fun, you can also comment :-)

It's also a good idea to write test-case scripts for each class and check leaks inside classes that way.

New, delete are not used. The class elements are defined at the beginning and I don't recreate them.

Mostly I work with arrays.


What aretest-case scripts ?

Reason: