Questions from Beginners MQL5 MT5 MetaTrader 5 - page 997

 

Greetings fellow programmers. I need your help. The Expert Advisor opens only one deal on the first trading day of a month. It may be the first or the second or the third or even the fourth day. My condition is like this: if(Day == 1 || Day == 2 || Day == 3 || Day == 4 ){trade is opened} I want to ask if there is any function in MQL5 that would "tell EA that today is the first trading day of month"?

 
Kolya32:

Greetings fellow programmers. I need your help. My Expert Advisor opens only one order on the first trading day of a month, and it may be the first or the second, the third or even the fourth day. My condition is like this: if(Day == 1 || Day == 2 || Day == 3 || Day == 4 ){trade is opened} I want to ask if there is any function in MQL5 that would "tell EA that today is the first trading day of month"?

You can't find the first trading day or you can't check the date of the current day with the first trading day of the month?

This is how you can find out more accurately the opening date of the month in the current TF(PERIOD_CURRENT can of course be changed to any day, for example).

 datetime         StartDt=iTime(Symbol(),PERIOD_CURRENT,Bars(Symbol(),PERIOD_CURRENT,iTime(Symbol(),PERIOD_MN1,0),iTime(Symbol(),PERIOD_CURRENT,0))-1);

But it is better to check each functioniTime,Bars.

 
Kolya32:

Greetings fellow programmers. I need your help. My Expert Advisor opens only one deal on the first trading day of a month. But it may be the first or the second, the third or even the fourth day. My condition is like this: if(Day == 1 || Day == 2 || Day == 3 || Day == 4 ){trade is opened} I want to ask if there is any function in MQL5 that would "tell EA that today is the first trading day of month"?

Find where the opening of a new bar is discussed and substitute the period PERIOD_MN1 there

The opening of a new bar will be the first trading day of the month.

 
Aleksey Vyazmikin:

Can't identify the first trading day or can't check the current day's date with the first trading day of the month?

I cannot determine the first trading day of the month. Thank you for your recommendations I will experiment)

 
Alexey Viktorov:

Find where the opening of a new bar is discussed and substitute the period PERIOD_MN1

The opening of the new bar will be the first trading day of the month.

Thank you. I will experiment in this direction as well)

 

Why do the authors use colons for writing? The code below is simply full of colons. Although the same::Sleep(5); can be written without colons?

void CProgram::GetSymbols(void)
  {
   m_progress_bar.LabelText("Get symbols...");
   m_progress_bar.Update(1,2);
   ::Sleep(5);
//--- Освободить массив символов
   ::ArrayFree(m_symbols);
//--- Массив элементов строк
   string elements[];
//--- Фильтр названий символов
   if(m_symb_filter.IsPressed())
     {
      string text=m_symb_filter.GetValue();
      if(text!="")
        {
         ushort sep=::StringGetCharacter(",",0);
         ::StringSplit(text,sep,elements);
         //---
         int elements_total=::ArraySize(elements);
         for(int e=0; e<elements_total; e++)
           {
            //--- Чистка по краям
            ::StringTrimLeft(elements[e]);
            ::StringTrimRight(elements[e]);
           }
        }
     }
//--- Собираем массив форекс-символов
   int symbols_total=::SymbolsTotal(true);
   for(int i=0; i<symbols_total; i++)
     {
      //--- Получим имя символа
      string symbol_name=::SymbolName(i,false);
      //--- Скроем его в окне Обзор рынка
      ::SymbolSelect(symbol_name,false);
      //--- Если не форекс-символ, перейти к следующему
      if(::SymbolInfoInteger(symbol_name,SYMBOL_TRADE_CALC_MODE)!=SYMBOL_CALC_MODE_FOREX)

         if(m_symb_filter.IsPressed())
           {
            bool check=false;
            int elements_total=::ArraySize(elements);
            for(int e=0; e<elements_total; e++)
              {
               //--- Ищем совпадение в названии символа
               if(::StringFind(symbol_name,elements[e])>-1)
                 {
                  check=true;
                  break;
                 }
              }
            //--- Перейти к следующему, если не пропускает фильтр
            if(!check)
               continue;
           }
      //--- Сохраним символ в массив
      int array_size=::ArraySize(m_symbols);
      ::ArrayResize(m_symbols,array_size+1);
      m_symbols[array_size]=symbol_name;
     }
//--- Если массив пустой, установим текущий символ по умолчанию
   int array_size=::ArraySize(m_symbols);
   if(array_size<1)
     {
      ::ArrayResize(m_symbols,array_size+1);
      m_symbols[array_size]=::Symbol();
     }
//--- Покажем в окне Обзор рынка
   int selected_symbols_total=::ArraySize(m_symbols);
   for(int i=0; i<selected_symbols_total; i++)
      ::SymbolSelect(m_symbols[i],true);
  }
 
BillionerClub:

Why do the authors use colons for writing? The code below is simply full of colons. But can we write the same::Sleep(5); without colons?

Operation context resolution ( :: )

Each function in mql5-program has its own execution context. For example, the system function Print() is executed in the global context. The imported functions are called in the context of the corresponding import. Functions-methods of classes have the context of the corresponding class. The syntax of the context resolution operation:

[context_name]::function_name(parameters)

If there is no context name, it is an explicit reference to use a global context. If there is no context resolution operation, the function is searched for in the nearest context. If the function is not in the local context, it is searched in the global context.

Also, the context resolution operation is used to determine the member function of a class.

type Class_name::function_name(description_parameters)
{
// function body
}

If a program uses or may in the future use several functions of the same name from different execution contexts, ambiguity may occur. The order in which functions are called without explicitly specifying the context:

  1. Class methods. If the function with the given name is not specified in the class, you are looking for it on the next level.
  2. MQL5 Functions. If there is no such a function in the language, we are looking at the next level.
  3. Global functions defined by user. If there is no such a function, you are looking at the next level.
  4. Imported functions. If the function is not found among the imported ones, the compiler will generate an error.

To eliminate the ambiguity of a function call, explicitly specify the scope using the context resolution operation.

Документация по MQL5: Основы языка / Операции и выражения / Другие операции
Документация по MQL5: Основы языка / Операции и выражения / Другие операции
  • www.mql5.com
-1. В частном случае одномерного массива из 50 элементов обращение к первому элементу будет выглядеть как array[0], к последнему элементу - array[49]. Вызов функции с аргументами x1, x2,..., xn Каждый аргумент может представлять собой константу, переменную или выражение соответствующего типа. Передаваемые аргументы разделяются запятыми и должны...
 
Artyom Trishkin:

Context resolution operation ( ::: )

I take it the author is speeding up code processing. Well done.

 

The trading history is drawn on the chart, how do I disable this drawing?


 
BillionerClub:

The trading history is drawn on the chart, how can I disable such drawing?


Service - Settings - Trading - "Show trades on the chart in real time".