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

 
Andrey Sokolov:

Can you tell me what is meant in the entry

int i,limit=prev_calculated==0 ? rates_total-1 : rates_total-prev_calculated;

"==" , "?" , ": "

?

Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
  • www.mql5.com
В качестве первого операнда – "выражение1" – может быть использовано любое выражение, результатом которого является значение типа bool. Если результат равен , то выполняется третий операнд – "выражениеЗ". Второй и третий операнды, то есть "выражение2" и "выражениеЗ", должны возвращать значения одного типа и не должны иметь тип void...
 
It's just awful! If I can still trace the logic in the Expert Advisors, correct some things, add some more... I don't understand the code of indicators at all(
 
prom18:

Thank you, Igor. I have not formulated it correctly. The indicator is calculated and drawn for a specified number of bars (50 in this case) and in a separate window. It needs not the open price but the first bar of the day to indicate the MA. But anyway, thank you.

read SetIndexDrawBegin() - this is a restriction for drawing the indicator buffer, never used

or in my example you can do it that way:

input int BarCount = 50;
....

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[])
  {
   int i,limit;
   static double dayopen=0.0;
   static int lastday=0;
   if(prev_calculated==0)
     {
      limit=rates_total-1;
      dayopen=0.0;
      lastday=0;
     }
   else limit=rates_total-prev_calculated;
   limit = fmin(BarCount,limit);
   for(i=limit; i>=0; i--)
     {
      if(TimeDay(time[i])!=lastday)
        {
         dayopen=open[i];
         lastday= TimeDay(time[i]);
        }
      Label1Buffer[i]=dayopen;
     }
   return(rates_total);
  }

i.e. restrict the calculation of indicator buffers to theBarCount setting

 
Andrey Sokolov:

Can you tell me what is meant in the entry

int i,limit=prev_calculated==0 ? rates_total-1 : rates_total-prev_calculated;

"==" , "?" , ": "

?

https://docs.mql4.com/ru/basis/operators/ternary


I rewrote my example, in the first version it would not work correctly when switching TFs, you need to reset dayopen and lastday, they are described with modifier static

Условный оператор ?: - Операторы - Основы языка - Справочник MQL4
Условный оператор ?: - Операторы - Основы языка - Справочник MQL4
  • docs.mql4.com
В качестве первого операнда – "выражение1" – может быть использовано любое выражение, результатом которого является значение типа bool. Если результат равен , то выполняется третий операнд – "выражениеЗ". Второй и третий операнды, то есть "выражение2" и "выражениеЗ", должны возвращать значения одного типа и не должны иметь тип void...
 
Artyom Trishkin:

Return also the index in the function parameter passed by reference

Returned:

double GetPatt5barsDN()
{
double low3 = 0;
int index = 0;
for(int i=1; i<20; i++)
{
if
((Close[i] > Open[i]) &&
(Close[i+1] > Open[i+1]) &&
(Close[i+2] > Open[i+2]) && //Low[i+2] is needed on this candle
(Close[i+3] < Open[i+3]) &&
(Close[i+4] < Open[i+4])

low3 = Low[i+2];
index = i+2;
}

return(low3);
return(index);
}


What should I do next?

 
Sfinks35:

Returned:

double GetPatt5barsDN()
{
double low3 = 0;
int index = 0;
for(int i=1; i<20; i++)
{
if
((Close[i] > Open[i]) &&
(Close[i+1] > Open[i+1]) &&
(Close[i+2] > Open[i+2]) && //Low[i+2] is needed on this candle
(Close[i+3] < Open[i+3]) &&
(Close[i+4] < Open[i+4])

low3 = Low[i+2];
index = i+2;
}

return(low3);
return(index);
}


What should I do next?

That's no way to get it back.


Like this.

int GetPatt5barsDN()
      {
       double low3 = 0;
       int index = 0;
       for(int i=1; i<20; i++)
          {
            if
            ((Close[i] > Open[i]) &&  
            (Close[i+1] > Open[i+1]) &&
            (Close[i+2] > Open[i+2]) && //На этой свече нужен Low[i+2]
            (Close[i+3] < Open[i+3]) &&  
            (Close[i+4] < Open[i+4]))
             
            low3 = Low[i+2];
            index = i+2;
          } 
           
          return(index);
      }


Further

double min = Low[GetPatt5barsDN()];
 
Sfinks35:

Returned:

double GetPatt5barsDN()
{
double low3 = 0;
int index = 0;
for(int i=1; i<20; i++)
{
if
((Close[i] > Open[i]) &&
(Close[i+1] > Open[i+1]) &&
(Close[i+2] > Open[i+2]) && //Low[i+2] is needed on this candle
(Close[i+3] < Open[i+3]) &&
(Close[i+4] < Open[i+4])

low3 = Low[i+2];
index = i+2;
}

return(low3);
return(index);
}


What should I do next?

Where's the index return via a parameter by reference?

And please insert the code correctly:


 
Is there a function in MQL4 that can detect whether a quote is a 5 or 4 decimal place, how many decimal places an asset has for example EURJPY has 2 decimal places, EURUSD has 4 decimal places?
 
Seric29:
Is there a function in MQL4 that can identify quotes from an account type, like 5 or 4 decimal places, what are the ways to identify how many zeros an asset has after the comma for example EURJPY has 2 decimal places, EURUSD has 4 decimal places?

https://docs.mql4.com/ru/predefined/digitsvar

Digits - Предопределенные переменные - Справочник MQL4
Digits - Предопределенные переменные - Справочник MQL4
  • docs.mql4.com
Digits - Предопределенные переменные - Справочник MQL4
 
Artyom Trishkin:

Where's the index return via a parameter by reference?

And please insert the code correctly:


Good afternoon!
I seem to have got it right now:
double GetPatt5barsDN(int &index)
      {
       double low3 = 0;
       for(int i=1; i<20; i++)
          {
            if
            ((Close[i] > Open[i]) &&  
            (Close[i+1] > Open[i+1]) &&
            (Close[i+2] > Open[i+2]) && //На этой свече нужен Low[i+2]
            (Close[i+3] < Open[i+3]) &&  
            (Close[i+4] < Open[i+4]))
             
            low3 = Low[i+2];
            index = i+2;
          }           
     return(low3);
     }

But on compilation it generates one warning: possible loss of data due to type conversion on line:
index = GetPatt5barsDN(index);

double low3 = 0;
   int index = 0;
   low3 = GetPatt5barsDN(index);
   index = GetPatt5barsDN(index);
   Print("low3= ", low3);
   Print("index= ", index);

There are no errors in the function header (or in the function itself) during compilation.

Reason: