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

 
Andrey F. Zelinsky:
there's a little bit about it herehttps://docs.mql4.com/ru/convert/normalizedouble

DoubleToString, IMHO...

Print.

 
Andrey F. Zelinsky:
there's a little bit about it herehttps://docs.mql4.com/ru/convert/normalizedouble
You won't believe it, but originally all the data was normalised, and there was a digis after the comma. I know that even double values have to be normalised. Try to recalculate the normalized static data yourself, I think it's a compiler error, but I hope I'm wrong, so far I solved it with MathRound, but it's wrong!
 
arhipov-76:
You won't believe it, but originally all data were normalized and the digis was after the comma. I know that even double values must be normalized. Try to recalculate normalized static data yourself, I think it's a compiler error, but I hope I'm wrong, so far I solved this problem with MathRound function, but it's wrong!

I don't know what digis is, just try DoubleToString(...) function.

If you make calculations with what you have now inside the EA, the calculations are correct, even withNormalizeDouble(), but if you want to output parameters outside, for example Print, Alert, Comment, then use normalization through DoubleToString(...)

DoubleToString - Преобразование данных - Справочник MQL4
DoubleToString - Преобразование данных - Справочник MQL4
  • docs.mql4.com
DoubleToString - Преобразование данных - Справочник MQL4
 

No matter how you normalise the number 0.0001, it will remain an infinite periodic fraction in binary representation because it has a division by 5. In a computer, this infinite fraction has to be truncated to a length that fits. Dividing by it results in something very long again, which also has to be trimmed. To get a "good" look at the resulting number in decimal form, you need to convert it in the program to a string with a given suitable number of fractional digits. Using, for example, DoubleToString, as already written here.

P.S. " the result outputs one tenth less than it should be" - there was no such thing, a vain accusation. By one hundred millionth it did...

 
Timur1988:

Hello! Please help me with the algorithm!
I wrote a simple script, which calculates Pearson's correlation coefficient. The arrays are based on closing prices, starting from the first bar.

The price array is taken from the first bar to the 24th bar.
Now I want to calculate the correlation also for 24 bars, but take the price array from the SECOND(!) bar.

Not knowing the algorithm, I entered each price array manually:

24 bars is a drag, and if I want to know the correlation for 100 bars, it's a pain in the ass to enter each array.
What to do, people?)

I should probably fix the square root of the string Koef=Edxdy/(sqrt(DoubleToString((Edx2*Edy2), w));

 
Vladimir:

We should probably also correct the square root of the string calculation Koef=Edxdy/(sqrt(DoubleToString((Edx2*Edy2), w)));

Here's a working function to calculate the correlation, just give the arrays with prices, and the output will be the value:

string Correlation1(double& CurOpen[], double& SubOpen[]) {
double sumXY2=0, sumX2=0, sumY2=0, sumXs2=0, sumYs2=0, res2=1;

int k=MathMin(ArraySize(CurOpen), ArraySize(SubOpen));
  if(k>2) {
   for(int i=0; i<k; i++) {
     sumXY2+=CurOpen[i]*SubOpen[i];
     sumX2 +=CurOpen[i];
     sumY2 +=SubOpen[i];
     sumXs2+=CurOpen[i]*CurOpen[i];
     sumYs2+=SubOpen[i]*SubOpen[i];    
    }
   res2 = (k*sumXY2-sumX2*sumY2) / MathSqrt( (k*sumXs2-sumX2*sumX2)*(k*sumYs2-sumY2*sumY2) );
  }
  return(DoubleToStr(res2,2));
}
 
Hello! I put my robot on a demo account and it's been running for the second month. Today I open the terminal, two orders have been placed by one signal, although one order has been placed before. I have a restriction on the number of orders. What may be the reason?
 

Here's what I use

Вот что я использую

if(ExistPositions(Symb)==false&&ExistOrders(Symb)==false&&Delta_Buy<Low[1]&& sar>Close[1])
{SetOrder(NULL,OP_BUYSTOP,Lts,sar,sar-SL*Point(),sar+TP*Point(),Magik_number);}
if(ExistPositions(Symb)==false&&ExistOrders(Symb)==false&&Delta_Sell>High[1] && sar<Close[1])
{SetOrder(NULL,OP_SELLSTOP,Lts,sar,sar+SL*Point(),sar-TP*Point(),Magik_number);}


//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.03.2008                                                     |
//|  Описание : Возвращает флаг существования ордеров.                         |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любой ордер)                    |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//|    ot - время открытия             ( 0   - любое время установки)          |
//+----------------------------------------------------------------------------+
bool ExistOrders(string sy="", int op=-1, int mn=-1, datetime ot=0) {
  int i, k=OrdersTotal(), ty;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      ty=OrderType();
      if (ty>1 && ty<6) {
        if ((OrderSymbol()==sy || sy=="") && (op<0 || ty==op)) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (ot<=OrderOpenTime()) return(True);
          }
        }
      }
    }
  }
  return(False);
}
//--------------------------------------------------------------------------------//


bool ExistPositions(string sy="", int op=-1, datetime ot=0) {
  int i, k=OrdersTotal();

  if (sy=="0") sy=Symb;
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if ( OrderMagicNumber()==Magik_number) {
              if (ot<=OrderOpenTime()) return(True);
            }
          }
        }
      }
    }
  }
  return(False);
}
 
Neron_76:

Here's what I use

The cycles need to be counted in reverse order, fromOrdersTotal()-1 to 0.
 
Vitalie Postolache:
Cycles should be counted in reverse order, fromOrdersTotal()-1 to 0.
Thank you, I will have to redo it.