Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 722

 
I can't figure out why it hangs
//+------------------------------------------------------------------+
//|                     Машка за больший период без перерисовки .mq4 |
//|                                                             Zver |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Zver"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property  indicator_color1 Aqua
extern int Otobrajat_v_istorii = 1000;
extern int ma_shift=0;
extern int ma_method =0;
extern int applied_price=0;


double buf_ma[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
     SetIndexBuffer(0,buf_ma);         // Назначение массива буферу
   SetIndexStyle(0,DRAW_LINE,EMPTY,2);// Стиль линии
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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,// Индекс бара
   Counted_bars;
   Counted_bars=IndicatorCounted(); // Количество просчитанных баров 
   i=Bars-Counted_bars-1;           // Индекс первого непосчитанного
   if(i>Otobrajat_v_istorii-1) // Если много баров то ..
      i=Otobrajat_v_istorii-1;                  // ..рассчитывать заданное колич.
     
   while(i>=1) // Цикл по непосчитанным барам
     {

    
     buf_ma[i]=iMA(Symbol(),Period(),5,ma_shift,ma_method,applied_price,i);
  
     
     }
   
   
   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
Code variant
int Err;   //Номер ошибки
int FunErr(int Err) // Функция обработки ошибок
gives a warning:
declaration of 'Err' hides global declaration at line 51
Another code variant
int Err;   //Номер ошибки
int FunErr(Err) // Функция обработки ошибок
gives an error:
'Err' - declaration without type
How to write it correctly?
 
Zver4991:
I can't figure out why it hangs
int i// Bar index
while(i>=1) // Cycle through uncounted bars
i>=1always.
 
Shurkin:
int i// Bar index
while(i>=1) // Loop over uncounted bars
i>=1always.

Right, I forgot about...thanks.

i--;

 
//--------------------------------------------------------------------
int Count=0;                                    
//--------------------------------------------------------------------
void OnTick()   
  {
   Count++;
   Comment("Новый тик ", Count);
   //if(Count>2) ExpertRemove();
  }
//--------------------------------------------------------------------
void OnDeinit(const int reason)
  {
   Comment("Сработала ф-ия deinit() при выгрузке");
  }
//--------------------------------------------------------------------

If to uncomment if(Count>2) ExpertRemove(), and exit by this function, thenafter EA unloading, comment "Deinit() triggered during unloading" remains displayed on the chart.

Does anyone know why, if such EA is removed from the chart via context menu, then Comment() from OnDeinit does not remain on the chart?

 

Shurkin:

Code variant
int Err;   //Номер ошибки
int FunErr(int Err) // Функция обработки ошибок
gives a warning:
declaration of 'Err' hides global declaration at line 51
Another code variant
int Err;   //Номер ошибки
int FunErr(Err) // Функция обработки ошибок
gives an error:
'Err' - declaration without type
How to write it correctly?

This is an error of language design in general, defended at the highest level. Two facts:

1. The MQL4++ language allows hiding variable names in nested scopes.

2. When hiding variable names in nested scopes, there must be a warning, which cannot be disabled.

To answer the question, there are at least two possibilities:

1. use name hiding, but put up with the presence of a warning (bad, you might miss a really important other warning among the many warnings about hiding names which could help detect and eliminate a potential error).

2. Do not use name hiding, even though the language has such a feature. For example, name the global variable gErr instead of Err.

Instead of prohibiting hiding names, a non-removable warning is introduced. Take advantage of it.

 

In Russian: the correct option is the first, ignore the warnings.

 
tara:

In Russian: the correct option is the first, ignore the warnings.

Thank you.
 
Where can I find function descriptions in the inclusion files?
 
Zver4991:
Where can I find descriptions of functions in the inclusion files?

If the files are from the standard library, of course you can. You need to open this include file, and in it you will see something like the following:

#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CChart.                                                    |
//| Purpose: Class of the "Chart" object.                            |
//|          Derives from class CObject.                             |
//+------------------------------------------------------------------+
class CChart : public CObject
Next, highlight "CChart" and copy it. Press F1 - help opens and in the tab "Search" paste the desired text + Enter.