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

 
Alexey Viktorov #:

Stupid on the second try. Apparently the time has come up in the evening.

I did not get it right, but I don't know how to divide the instrument into currencies.

And there is a probability of middle equality, I did not see it at first glance, but it is better to do a full search for equality of currency names in the instrument from the 2nd to the 3rd position. Or cut off the 1st and the last position and search in the remaining 4 digits)

 
Valeriy Yastremskiy #:

A B C D is correct, but I don't understand how to divide the instrument into currencies.

And there is a probability of middle equality, I did not see it right away, but it is better to do a full search for equality of currency names in the instrument from the 2nd to the 3rd position. Or cut off the 1st and the last position and search in the remaining 4 characters.)

No, I got stupid on the second try only in the 4 conditions. After all, for the task it does not matter in what position the desired item will be found, in zero or third, the main thing is found or not. As a result, there are two conditions, one for the base currency and one for the second currency.

 
Alexey Viktorov #:

No, I got dumb on the second try only in the 4 conditions. After all, for the task it does not matter in which position the search item will be found, zero or third, the main thing is whether it is found or not. As a result, there are two conditions, one for the base currency and one for the second one.

So I excluded the middle equality from the second or third position of the instrument. If not excluded, then it is correct, 2 conditions.

 
Valeriy Yastremskiy #:

Well, I was excluding the middle equality thereby, from the second or third position of the instrument. If you don't exclude, you are correct, 2 conditions.

I still don't understand what "midpoint equality" means.

Signal on EURUSD

A EURJPY order - search for EUR and find it, it is true. The second condition does not need to be checked.

GBPJPY - look for EUR, do not find it. look for USD, do not find it, the throws are false. Total two conditions.

 
Alexey Viktorov #:

I still don't understand what a "middle equal" is.

Signal on EURUSD

Order on EURJPY - search for EUR and find, ejection true. The second condition does not need to be checked.

GBPJPY - look for EUR, do not find it. look for USD, do not find it, the throws are false. Total two conditions.

EURJPY is equal among URJP

GBPJPY among BPJP

I agree, it is a rare case. But it is possible, judging by the great number of instruments.

 
Valeriy Yastremskiy #:

EURJPY equality amongst URJP

GBPJPY among BPJP

I agree, it is a rare case. But possible, judging by the large number of instruments.

Nah, I'd rather stay on my wavelength. I find it hard to understand why...

 

How does the constructor work in structures?

struct as{
  int a,
      b,
      c;
    void as(){
    b=0;c=0;
    a=b+c;
    }  
 };
as sir;
 

Hello! I'm racking my brain.

Whoever is not difficult, please help with the comments.


1. What is the purpose of variable "bb" and correspondingly, operator if (bb == 0) bb = i; ?


2. if ((Time[i]>=BeginDateCalc && Time[i]<=EndDateCalc && NumberOfBars<=0)

|| (NumberOfBars>0 && NumberOfBars>=i))

How can NumberOfBars be <= 0 and for what?


3. s += (High [i] - Low [i]) / Point;

What is the division by Point for?


4. By the condition of the loop for (i = Bars; i > 0; i--) the count goes from the "oldest" to the "youngest" bar.

Why is b++ variable incremented, but not decremented?

//+----------------------------------------------------------------------------+
//|                                                          AverageRange.mq4  |
//|                                                    Ким Игорь В. aka KimIV  |
//|                                                       http://www.kimiv.ru  |
//|                                                                            |
//|  14.09.2005  Скрипт для расчёта:                                           |
//|              средней волатильности инструмента High-Low                    |
//|              Возможность использования заданного количества баров          |
//+----------------------------------------------------------------------------+
#property copyright "Ким Игорь В. aka KimIV"
#property link      "http://www.kimiv.ru"
#property  show_inputs

extern datetime BeginDateCalc = D'2013.01.01';
extern datetime EndDateCalc   = D'2013.12.31';
extern int      NumberOfBars  = 100;         


//+----------------------------------------------------------------------------+
//|  script program start function                                             |
//+----------------------------------------------------------------------------+
void start() {
   int    i;           //счётчик
   int    b  = 0;      //использовано баров
   int    bb = 0;      //?????????????????????
   int    s =  0;      //сумма всех значений High - Low
   string st = "";     //строка вывода на экран    

  for (i = Bars; i > 0; i--) {
    
    if ((Time [i] >= BeginDateCalc && Time [i] <= EndDateCalc && NumberOfBars <= 0)
    || (NumberOfBars > 0 && NumberOfBars >= i)) {
      
      if (bb == 0) bb = i;
      s += (High [i] - Low [i]) / Point;
      
      b++;
    }
  }

  st =      "Начало: " + TimeToStr (Time [bb], TIME_DATE | TIME_MINUTES) + "\n";        // "/n" - это перенос строки
  st = st + "Конец: " + TimeToStr (Time [bb - b + 1], TIME_DATE | TIME_MINUTES) + "\n";
  st = st + "Использовано баров: " + b + "\n";
  st = st + "Средняя волатильность: " + s / b + " п.\n";
  
  Comment (st);
}
//+----------------------------------------------------------------------------+
 

The bb contains the bar index of the first triggered condition. This index is then used to calculate start time of calculation.

NumberOfBars - this variable is set by the user, and this guy is not reliable and may set a minus value. Perhaps, the logic is that if NumberOfBars is non-positive, the calculation is carried out between the start and end date, while if it is positive, then it is calculated by the number of candlesticks set with this variable.

The Point is divided into points (1.01051-1.01000)/Point=51 to convert the values from the fractional part to points.

The variable bb after zero is changed only once during the whole operation of the script. if (bb == 0)

 
Aleksei Stepanenko #:

The bb contains the bar index of the first triggered condition. This index is then used to calculate start time of calculation.

NumberOfBars - this variable is set by the user, and this guy is not reliable and may set a minus value. Perhaps, the logic is that if NumberOfBars is non-positive, the calculation is carried out between the start and end dates.

But the point is divided to transfer values from the fractional part to points 0.00051/Point=51

Variable bb after zero is changed only once during the whole operation of the script.

To be honest, I don't understand Kim's logic; why do the conditions of bar times exceeding the specified value and the number of calculated bars with OR the number of calculated bars is greater than the number of bars Barz))) And at the same time it just corrects the custom parameters)

And it doesn't even display an alert that the user messed up)

Reason: