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

 

After the last answers the picture became clearer and the most obvious one is that I am not destined to become a programmer :-)

So far I started with the simplest listing and this is what it turned out to be:


2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[4] = 86.0999999999999999 2018.10.15 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[3] = 85.989999999999999999 2018.10.16 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[2] = 86.76000000000001 2018.10.17 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[1] = 86.5 2018.10.18 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[0] = 85.72 2018.10.19 00:00:00



In some cases, for some reason, the price exceeds the dimension of two significant digits after the point in either direction.

And this happens without any errors in calculations, it's just the output of the price value from the chart base tmp1[i]=close[i];

Is there any way to fix it or just ignore it?



 

You can remove everything from it that's relevant to five, and get a template for four.


This can be written by someone who knows the difference between a five and a four, and it's definitely not me :-)


//--- Проверка количества доступных баров
   if(rates_total<fmax(period_ma,4)) return 0;


Where did the number 4 come from, what is its sacred meaning?

 
psyman:


This can be written by someone who knows the difference between a five and a four, and it's definitely not me :-)



Where did the number 4 come from, what sacred meaning does it have?

You certainly don't listen or read... I was:

Forum on trading, automated trading systems & strategy testing

Any MQL4 beginners questions, assistance and discussion on algorithms and codes

Artyom Trishkin, 2018.10.18 09:26

//+------------------------------------------------------------------+
//| 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[])
  {
//--- Проверка количества доступных баров (1 - минимально, 4 - оптимально для большинства расчётов. Но всё "по месту"...)
   if(rates_total<4) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated; // 0 - пришел новый тик, новый бар формироваться не начал. 1 - пришел новый тик и начал формироваться новый бар.
   if(limit>1) 
               // если вписать "limit>0", то на нулевом баре будет расчёт только нулевого бара, на каждом новом баре будет полный перерасчёт всей истории
               // если вписать "limit>1", то на нулевом баре будет расчёт только нулевого бара, на открытии нового бара - пересчёт первого и нулевого,
               // при подгрузке истории и на первом запуске - перерасчёт всей истории
     {
      limit=rates_total-1;
      // здесь должна быть инициализация всех используемых буферов индикатора необходимыми значениями (обычно EMPTY_VALUE и 0)
     }
//--- Расчёт индикатора
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      // необходимые действия по расчёту индикатора
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
psyman:

After the last answers the picture became clearer and the most obvious one is that I am not destined to become a programmer :-)

So far I started with the simplest listing and this is what it turned out to be:


2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[4] = 86.0999999999999999 2018.10.15 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[3] = 85.989999999999999999 2018.10.16 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[2] = 86.76000000000001 2018.10.17 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[1] = 86.5 2018.10.18 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[0] = 85.72 2018.10.19 00:00:00



In some cases, for some reason, the price exceeds the dimension of two significant digits after the point in either direction.

And this happens without any errors in calculations, it's just the output of the price value from the chart base tmp1[i]=close[i];

Is there any way to fix it or just ignore it?



It's fine. To print fractional numbers, simply use DoubleToString() with the required precision. In this case the required precision should be Digits()

 
psyman:

After the last answers the picture became clearer and the most obvious one is that I am not destined to become a programmer :-)

So far I started with the simplest listing and this is what it turned out to be:


2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[4] = 86.0999999999999999 2018.10.15 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[3] = 85.989999999999999999 2018.10.16 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[2] = 86.76000000000001 2018.10.17 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[1] = 86.5 2018.10.18 00:00:00

2018.10.20 08:42:43.343 _t1 CADJPY,Daily: tmp1[0] = 85.72 2018.10.19 00:00:00


In some cases, for some reason, the price exceeds the dimension of two significant digits after the point in either direction.

And this happens without any errors in calculations, it's just the output of the price value from the chart base tmp1[i]=close[i];

Can this be defeated in some way or just ignore it?

these are normal values for a real number. you can learn to write programs, everyone starts there - you just need to read a lot and try to write and write your own codes.

The accuracy of the real number, mantissa, and how it's all stored in memory, you can google it on the web, the principles of storage are the same everywhere.

if you want beautiful output use DoubleToStr()

 
Igor Makanu:

these are common values for a real number, you can learn to write programs, everyone starts there - you just need to read a lot and try to write and write your own codes

The accuracy of the real number, mantissa, and how it's all stored in memory, you can google it on the web, the principles of storage are the same everywhere.

if you want beautiful output, use DoubleToStr()

Where it is possible to use compatible functions, it is better to offer them for use. Otherwise this epic will start all over again. In this case: DoubleToString()

 

How could you prevent the EA from running on the same instruments?

For example, the EA works in eur/usd window, but when run in other windows on eur/usd some alert message is displayed. I will be very grateful for the help.

 
gans71:

How could you prevent the EA from running on the same instruments?

For example, the EA works in eur/usd window, but when run in other windows on eur/usd some alert message is displayed. I will be very grateful for help.

You need to transfer data from one EA to another, search the forum

or use the global variables of the terminal (this is the easiest way) - there you can write the value of the first EA, and subsequent copies of the EA will read this value and will not runhttps://www.mql5.com/ru/docs/globals

Документация по MQL5: Глобальные переменные терминала
Документация по MQL5: Глобальные переменные терминала
  • www.mql5.com
Глобальные переменные существуют в клиентском терминале 4 недели с момента последнего обращения, после этого автоматически уничтожаются. Обращением к глобальной переменной считается не только установка нового значения, но и чтение значения глобальной переменной.
 
Igor Makanu:

you need to transfer data from one EA to another, search the forum

or use the global variables of the terminal (this is the easiest way) - there you can write the value of the first EA, and subsequent copies of the EA will read this value and will not runhttps://www.mql5.com/ru/docs/globals

the EA is the same, you need to forbid it to run on the same instruments
 
gans71:
the EA is the same, you should not allow it to run on the same symbols

and? you couldn't have studied the help in 2 minutes

If you're talking specifically about how to pass a string to a global variable, the only way is to create a name for the global variable, i.e. in your case you run an EA on EURUSD, do a check

if(GlobalVariableCheck(_Symbol)) .....

If there is no such a variable, then create an oversized one, like this

if(GlobalVariableSet(_Symbol,Magic)==0) Print("Error writing to global variable # ",GetLastError());

then on completion of the Expert Advisor, delete the glob.variable

as it is, the terminal is not handy, and I kind of pointed out the direction of search