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

 
Maxim Kuznetsov:

Alert("Разбег "+DoubleToString(delta,_Digits));

or Alert(StringFormat("Spread %.5f",delta));

in general, get used to it, they are just different representations of the same number. Think back to your wonderful school days - that's where it comes from.

Thank you. But what if I need to use the delta value as a number and compare it? For example.

if(delta>0.00005)
  {
   //------------
  }
Would that be correct?
 
prom18:

Thank you. What if I need to use the delta value as a number and compare? For example.

Is this correct?

You can compare two real numbers like this:

bool EqualDoubles(double d1,double d2,double epsilon)
  {
   if(epsilon<0) 
      epsilon=-epsilon;
//---
   if(d1-d2>epsilon) 
      return false;
   if(d1-d2<-epsilon) 
      return false;
//---
   return true;
  }

https://www.mql5.com/ru/docs/basis/types/double

Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
  • www.mql5.com
Вещественные типы (или типы с плавающей точкой) представляют значения, имеющие дробную часть. В языке MQL5 есть два типа для чисел с плавающей точкой. Способ представления вещественных чисел в машинной памяти определен стандартом IEEE 754 и не зависит от платформ, операционных систем и языков программирования. Константы с плавающей точкой...
 
Mihail Matkovskij:

You can compare two real numbers like this:

https://www.mql5.com/ru/docs/basis/types/double

You can, if you're sure they can't be very close in meaning. After all, soft is compared to warm.
 
Alexey Viktorov:
You can, if you're sure they can't be very close in value. After all, soft is compared to warm.

I don't get it. For example. I take the number of pips that price has passed in one tick. If the price passed more than 20 points, then I get an Alert.

I compare the price difference (1.12300-1.12321=0.00021) with the necessary maximum value (0.00020).

0.00021>0.00020.

What does this have to do with soft and warm?

 
prom18:

I don't get it. For example. I take the number of pips that price has passed in one tick. If the price passed more than 20 points, then I get an Alert.

I compare the price difference (1.12300-1.12321=0.00021) with the necessary maximum value (0.00020).

0.00021>0.00020.

What does this have to do with soft and warm?

you need points, so compare points. they are integers by the way.

and double is compared to epsilon (DBL_EPS if memory serves), otherwise you might get 3.0-0.2 > 2.0+0.8 (figuratively, figures may be different)

 
Maxim Kuznetsov:

you need points, so compare the points. they are integers by the way.

while double is compared to epsilon (DBL_EPS if memory serves), otherwise you may get 3.0-0.2 > 2.0+0.8 (figuratively, numbers may be different)

better use@fxsaber example for this purpose:

int PriceToInteger( const double Price, const double point )
{
   return((int)(Price / point + 0.1));
}

script to check:

//+------------------------------------------------------------------+
void OnStart()
{
   int bar1 = PriceToInteger(iClose(NULL, 0, 1), _Point);
   int bar2 = PriceToInteger(iClose(NULL, 0, 2), _Point);
   printf("bar2 - bar1 = %i point", bar2 - bar1);
}
//+------------------------------------------------------------------+
int PriceToInteger( const double Price, const double point )
{
   return((int)(Price / point + 0.1));
}
//+------------------------------------------------------------------+
 
prom18:

I don't get it. For example. I take the number of pips that price has passed in one tick. If the price passed more than 20 points, then I get an Alert.

I compare the price difference (1.12300-1.12321=0.00021) with the necessary maximum value (0.00020).

0.00021>0.00020.

What does this have to do with soft and warm?

Well sometimes you don't have to read everything that's written.

You took numbers that are normally represented by the system. Take these...

  double a=1.12328,
         b=1.12309,
         c=0.00019,
         d=a-b;

and you get

1.1232800000000001
1.1230899999999999
0.00019
0.000190000000000135

The idea is a-b==c, but the computer will give you such errors. It was written about it a lot on the forum, search and read.

But you can take the normalised difference and the normalised control value and compare them.

 
Иван:
Good time to you all. Question: in MT4, when working in the tester with crosses (pairs without quid), how does the tester calculate the results of closed positions, if the account, on which testing is conducted, is a dollar account? For the recalculation of position totals in dollars, does the tester take the exchange rate of the base currency of the cross to the dollar at the current moment or at the moment of the tested interval? I strongly suspect that it is at the current time. If so, is it impossible to make it calculate at the time of the interval?
Does anyone know?
 
Иван:
Does anyone know?

count the MODE_TICKVALUE itself for each tick.

 
Alexey Viktorov:
You could, if you're sure they can't be very close in value. After all, soft is compared to warm.

Ifprom18 needs to compare two numbers, within Digits signs, this is the only method that works:

double price1 = 1.23450;
double price2 = 1.23447;

if(EqualDoubles(price1, price2, ((_Digits == 4) ? 0.0100 : 0.00100)) {
  ...
}

But as you can see, it has even more variation: https://www.mql5.com/ru/forum/160683/page1205#comment_17247843. Therefore, in the example I intentionally reduced the comparison accuracy by two digits. Of course, such a spread in price values is quite inaccurate... But how else to compare two numbers in cases like this...? If the deviation was over Digits, then we could not use EqualDoubles, but use NormalizeDouble to cut off all unnecessary things.

Although, you could also do it like this:

int digits = Digits() - 2;

double price1 = NormalizeDouble(1.23450, digits);
double price2 = NormalizeDouble(1.23447, digits);

if(price1 == price2) {
  ...
}