Errors, bugs, questions - page 98

 

I don't understand "where the dog is buried", the code works, everything is OK, but the compiler warnings possible loss of data due to type conversion Indi.mqh 125 45 make me wonder.


//+------------------------------------------------------------------+
//|Получение значений позиций в средe BB цены AppPrice,Fast/Slow TEMA|
//+------------------------------------------------------------------+

void CIndi::SetPricePositions(ushort SymbolPosition,ushort Index,uchar AppPrice)
  {
   int handle=GetHandle(SymbolPosition,BANDS);
   double Upper =Upper_Band(handle,Index);
   double Base  =Base_Band(handle,Index);
   double Lower =Lower_Band(handle,Index);
   double FTema =GetValuesFromIndi(GetHandle(SymbolPosition,TEMA_FAST),0,Index);
   double STema =GetValuesFromIndi(GetHandle(SymbolPosition,TEMA_SLOW),0,Index);
   
   Bollinger[SymbolPosition][PRICE_POSITION]=(double)GetPricePos(handle,Index,AppPrice); ???
   Bollinger[SymbolPosition][FAST_POSITION] =(double)Custom.Position(Lower,Upper,FTema); ???
   Bollinger[SymbolPosition][SLOW_POSITION] =(double)Custom.Position(Lower,Upper,STema); ???
   Bollinger[SymbolPosition][UPPER]         =(double)Upper; ???
   Bollinger[SymbolPosition][BASE]          =(double)Base;  ???
   Bollinger[SymbolPosition][LOWER]         =(double)Lower; ???
  }
Документация по MQL5: Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений / Предупреждения компилятора
Документация по MQL5: Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений / Предупреждения компилятора
  • www.mql5.com
Стандартные константы, перечисления и структуры / Коды ошибок и предупреждений / Предупреждения компилятора - Документация по MQL5
 

To the developers.

As far as I understand, the swap issue has been resolved? Or then it's not clear why the topic disappeared from the servicedesk.....

 

When testing an EA

void OnTick(){
   Print(iTest());
}
//+------------------------------------------------------------------+
int iTest(){
   double i;
   int j;
   for(int x=3; x>0; x--) { 
      i=i+0.00001;
   }//Next x
   j=int(i/_Point);
   return(j);
}//iTest()

The log shows a constantly increasing number! Is it supposed to be like this?

In MQL4 you should have written

static double i;

 
EvgeTrofi:

When testing an EA

The log shows a constantly increasing number! Is this supposed to be like this?

Yes, it should be.

You did not initialize the local variable i, which on subsequent calls was allocated in the same place on the stack as on previous calls.

Документация по MQL5: Основы языка / Переменные / Локальные переменные
Документация по MQL5: Основы языка / Переменные / Локальные переменные
  • www.mql5.com
Основы языка / Переменные / Локальные переменные - Документация по MQL5
 
Renat:

Yes, that's how it should be.

You haven't initialized the local variable i which will be allocated in the same place of the stack during the next calls as it was during the previous calls.

In which case should the static memory class be used?

Incomprehensible sentence in help: "Local variables declared asstatic have scope of a block, despite the fact that they exist from the beginning of the program execution", please explain. There seems to be a syntactical or grammatical slip-up in this phrase :)

Note the example in the help:https://www.mql5.com/ru/docs/basis/variables/static

If you remove word static from the code, nothing will change:

int Counter()
  {
   int count;
   count++;
   if(count%100==0) Print("Функция Counter была вызвана уже ",count," раз");
   return count;
  }
void OnStart()
  {
//---
   int c=345;
   for(int i=0;i<1000;i++)
     {
      int c=Counter();
     }
   Print("c = ",c);
  }

Question: why do we need static at all if it is the same without it?

Документация по MQL5: Основы языка / Переменные / Статические переменные
Документация по MQL5: Основы языка / Переменные / Статические переменные
  • www.mql5.com
Основы языка / Переменные / Статические переменные - Документация по MQL5
 
ALozovoy:
Hello. You are missing the ExpertParameters parameter in the [Tester] description. You can find out more about it in the help.

Thank you, it's working.

 


Please tell me, what was the purpose of adding the ability to declare variables within blocks in the first place? Previously in a case like this:

  
int c;    for(int i=0;i<1000;i++)      {        int  c=Counter(); }

It used to be that a box would pop up that a direct was declared twice and it was clear that you had to come up with another name for the variable or use the same one but without the int. But now it may get confusing. Is it the same in C++?

(I used to program in Visual Basic before learning MQL. There was no such a mess there).

 
EvgeTrofi:

Then in which case should the static memory class be used?


No.

If you created a variable int i;, why didn't you initialize it? In fact, you yourself said "I don't care what's in this variable" and ended up with rubbish in it.

The correct way is int i=0;

Is it like that in C++ too?

Yes, that's right - you may create such variables inside a block.
 

I've encountered a problem on Windows 7 64 bit on 306 Bild of the terminal (Windows 7 32 bit all works fine).

Files:
mql64.png  52 kb
 
VanHelsing:

I've encountered a problem on Windows 7 64 bit on 306 Bild of the terminal (Windows 7 32 bit all works fine).

Please post in servicedesk a piece of code on which this situation occurs.
Reason: