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

 
Alexey Belyakov:

Good afternoon!

Help me solve a simple problem.

Gap counter. I want to count gaps that are more than 10 points.

The variable "gap" resets to zero. I don't understand why. I've already tried everything. I've tried loops and static - it doesn't work. I suspect I wrote the loops incorrectly.

#property strict
#property script_show_inputs

input int GapInPips   =  100;
input int GapCount    =  10;
//+------------------------------------------------------------------+
void OnStart()
{
   int i = 1, gap = 0;
   while(i < Bars && gap < GapCount && !IsStopped())
   {
      int r = (int)(MathAbs(Close[i + 1] - Open[i]) / Point);
      if (r >= GapInPips)
      {
         gap++;
         Print("ГЭП!========: ", gap, " , ВЕЛИЧИНА ГЭПА==: ", r, ", время гэпа = ", Time[i]);
      }
      i++;
   }
}
//+------------------------------------------------------------------+

0 09:36:28.169 t EURUSD,H1: GAP!========: 1 , GAP EXPECTATION==: 182, gap time = 2020.06.15 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 2 , GAP VALUE==: 112, gap time = 2020.06.01 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 3 , GAP VALUE==: 134, gap time = 2020.05.11 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 4 , GAP VALUE==: 225, gap time = 2020.04.13 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 5 , GAP VALUE==: 192, gap time = 2020.03.30 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 6 , GAP VALUE==: 100, gap time = 2020.03.24 23:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 7 , GAP VALUE==: 926, gap time = 2020.03.16 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 8 , GAP VALUE==: 602, gap time = 2020.03.09 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 9 , GAP VALUE==: 136, gap time = 2020.03.02 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 10 , GAP VALUE==: 242, gap time = 2020.02.24 00:00:00

 

I can't figure out why i+1 starts the script in an infinite loop? Warning at the bottom - expression has no effect, but there is an effect)

string com=""; // объявление глобальной переменной для хранения информации для отладки
//---
void OnStart(void)
  {
   for(int i=0; i<10; i+1)
     {
      myfunc();
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void myfunc()
  {
//--- объявление статического счетчика
   static int cnt=0;
//--- сохранение информации для отладки в глобальную переменную
   com=(__FUNCSIG__+" cnt="+(string)cnt+"\n")+com;
   Comment(com); // вывод информации для отладки
//---
   cnt++;
//---
  }
 
awsomdino:

I can't figure out why i+1 starts the script in an infinite loop? Warning at the bottom - expression has no effect, but there is an effect)

Because i+1 does not increase the value of i

It should be either i++ or i+=1

 
Hi all. How do I calculate the indicator readings (dailymoving average) at last day's close? Thanks
Moving Average of Oscillator (OsMA)
Moving Average of Oscillator (OsMA)
  • www.mql5.com
On Balance Volume (OBV) Индикатор Балансового Объема (On Balance Volume, OBV) связывает объем и изменение цены, сопровождавшее данный объем. Momentum Индикатор движущей силы рынка (Momentum) измеряет величину изменения цены финансового инструмента за определенный...
 
Carcass77:
Hi all. How to calculate the indicator readings (dailymoving average) at last day's close ? Thanks

Calculate or receive ? MQL5 or 4 ?

 
Artyom Trishkin:

Calculate or receive ? MQL5 or 4 ?

MQL4 get

 
Carcass77:

MQL4 get

A simple moving average with period 14, shift 0, calculated using Close prices on the daily chart of the current symbol. Take the value of the first bar (zero is the current day):

double ma_day1=iMA(Symbol(),PERIOD_D1,14,0,MODE_SMA,PRICE_CLOSE,1);
 
Artyom Trishkin:

A simple moving average with period 14, shift 0, calculated from Close prices on the daily chart of the current symbol. We take the value of the first bar (zero is the current day):

Thank you

 
Igor Makanu:

0 09:36:28.169 t EURUSD,H1: GAP!========: 1 , GAP VALUE==: 182, gap time = 2020.06.15 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 2 , GAP VALUE==: 112, gap time = 2020.06.01 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 3 , GAP VALUE==: 134, gap time = 2020.05.11 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 4 , GAP VALUE==: 225, gap time = 2020.04.13 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 5 , GAP VALUE==: 192, gap time = 2020.03.30 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 6 , GAP VALUE==: 100, gap time = 2020.03.24 23:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 7 , GAP VALUE==: 926, gap time = 2020.03.16 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 8 , GAP VALUE==: 602, gap time = 2020.03.09 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 9 , GAP VALUE==: 136, gap time = 2020.03.02 00:00:00

0 09:36:28.169 t EURUSD,H1: GAP!========: 10 , GAP VALUE==: 242, GAP Time = 2020.02.24 00:00:00

Maybe it was a wrong variant? I copied it. Nothing, no results in the log.

 
Alexey Belyakov:

maybe you sent the wrong version? I copied it. Nothing, no results in the log.

That's the one.

the only thing left to do is to find out in which magazine you are looking at the print results, see the experts tab

Reason: