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

 

Hello. Please show me where the error is.

void OnStart()
  {
datetime current_time=TimeCurrent();
//datetime current_time=D'2019.10.18 19:55:00';
datetime our_time=(current_time-60)-MathMod((current_time-60),60);
datetime t1=our_time;
datetime t2=our_time+60;
PrintFormat("current_time=%s",TimeToString(current_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
PrintFormat("our_time=%s",TimeToString(our_time,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
string stock="MSFT";
MqlTick tick_array[];// массив для приема тиков
int received=CopyTicksRange(stock, tick_array, COPY_TICKS_TRADE, t1*1000, t2*1000);
Print(stock," Всего тиков ",received);
Print(tick_array[0].time,": Last = ",tick_array[0].last,"  Volume = ",tick_array[0].volume );
ulong total=tick_array[0].volume; ulong buy=tick_array[0].volume; ulong sell=0; bool flag='b';
int ticks=ArraySize(tick_array); double pprice=tick_array[0].last; int i=1;
while(i<ticks)
      { 
        total=total+tick_array[i].volume;//{считаем общий объем}
        if (pprice<tick_array[i].last)  flag='b';//{если пред.тик меньше зн.'b'}
        if (pprice<=tick_array[i].last)
            if (flag='b')
                buy=buy+tick_array[i].volume;//{считаем,что сделка по BID} 
        if (pprice>tick_array[i].last)  flag='s';//{если пред.тик больше зн.'s'} 
        if (pprice>=tick_array[i].last)
            if (flag='s')
               sell=sell+tick_array[i].volume;//{считаем,что сделка по ASK}
        pprice=tick_array[i].last;//{ставим счетчик на последн. тик}
        i=i+1; 
      }               
Print (total," ",buy," ",sell);       
  }
 
werter:

Hello. Could you please show me where the error is?

somewhere in the code

 
Vladimir Pastushak:

somewhere in the code.

Hilarious.

This is BuySellVolume. The total volume is not equal to the sum of Buy and Sell, but only slightly more.

 

What can the 'inf' in the indicator on the MLQ5 mean?

This is the first time I have encountered this and I have not found anything in the documentation search

 
Alexandr Sokolov:

What can the 'inf' in the indicator on the MLQ5 mean?

This is the first time I've encountered this and I couldn't find anything in the documentation search

Not a good search: an INF search produces several results.

For example look in MathLog

Return value

The natural logarithm of value in case of success. If val is negative, the function returns NaN (undefined value). If value is 0, the functionreturns INF (infinity).


This result means: the code has an error in the algorithm of value calculation (e.g. we forget to initialize variables - we just hope we will get lucky, in division operations we don't think ...).

Поиск - MQL5.community
Поиск - MQL5.community
  • www.mql5.com
Поиск выполняется с учетом морфологии и без учета регистра. Все буквы, независимо от того, как они введены, будут рассматриваться как строчные. По умолчанию наш поиск показывает страницы...
 
Vladimir Karputov:

Not a good search: an INF search produces several results.

For example look in MathLog

Returned value

The natural logarithm of value in case of success. If val is negative, the function returns NaN (undefined value). If value is 0, the function returns INF (infinity).


This result means: the code contains an error in the algorithm of value calculation (e.g. we forget to initialize variables - we hope for the worst, in division operations we don't think ...).

That's all I've found in search >>> documentation (but I didn't read every description, I always find it by title - habit)


About initialization of variables (I either misunderstood you or heard about it for the first time), for example:

double a = 0, b;

... Isn't it enough? I usually declare variables and use

 
Alexandr Sokolov:

Here's everything I saw in my search >>> documentation (but I didn't read the description of each one, I always find it by the title - habit)

***

Bad habit.


Alexandr Sokolov:


... isn't that enough? I usually declare variables and use

And here comes the "black swan" - the b variable is not initialised, it can contain any rubbish.

 
Alexandr Sokolov:

What can the 'inf' in the indicator on the MLQ5 mean?

This is the first time I've encountered this and I couldn't find anything in the documentation search

I figured out what the problem is!

If you have initialised the buffers EMPTY_VALUE

ArrayInitialize(Bufer,EMPTY_VALUE);

... then you copied or calculated insufficient number of timeseries in further calculations and then multiply any value by EMPTY_VALUE from the buffer - you get inf


Here I just alerited, and only multiplying by EMPTY_VALUE results in inf


 
Vladimir Karputov:

Thank you

 
Alexandr Sokolov:

I see what the problem is!

If you have initialised the EMPTY_VALUE buffers

... then in further calculations you have copied or calculated insufficient number of timeseries and then multiply any value by EMPTY_VALUE from buffer - then you get inf


Here I have just alerated, and only when multiplying by EMPTY_VALUE does it get inf


It looks like you found the reason. So when initializing a buffer with EMPTY_VALUE, during arithmetic operations we should first check "is EMPTY_VALUE accidentally present in the buffer at this index?

Reason: