Errors, bugs, questions - page 1620

 
Unfortunately, not always. If you don't connect for a long time, the terminal gives out "Account disable" and then you have to log in manually. This happens e.g. at a foundation where the servers are usually switched off overnight.
 
Dmitri Custurov:
Unfortunately, not always. If you don't connect for a long time, the terminal gives out "Account disable" and then you have to log in manually. This happens e.g. at a foundation where the servers are usually switched off at night.
And in this case (with a long lack of connection), if you run the command "File" -> "Connect to trading account" in the window will be exactly the same trading account?
 
Exactly the same. I only set up one account.
 
Dmitri Custurov:
Hello all. I asked this question several pages ago, but I will try again. Is there any way to re-login my account when MT5 server connection is interrupted? Search on forums did not give anything.
If I restart the terminal, does it start with running EAs (I don't have the terminal installed, I cannot check)? If yes, then you can write a shell script that will do the restart. And pull this script from your EA.
 
Dmitri Custurov:
Unfortunately, not always. If you don't connect for a long time, the terminal gives out "Account disable" and then you have to log in manually. This happens e.g. at a fund where the servers are usually switched off at night.
This is either a bug or a specific setup of the broker. Please contact Service Desk with this problem. It should not happen.
 
Can the developers comment on the promised, but unimplemented, ability to return a function value by reference? Have they not got around to it, or is there some difficulty with it?
 
Dmitri Custurov:
Unfortunately not always. If you do not connect for a long time, the terminal gives out "Account disable" and then you have to login manually. This happens e.g. at a foundation where the servers are usually switched off at night.

Here is the script that brings up the "File" menu - "Connect to trading account" - click on the "OK" button - so the terminal will connect to the last trading account that was authenticated:

Connect to a trading account

//+------------------------------------------------------------------+
//|                                                    ClickMenu.mq5 |
//|                              Copyright © 2016, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property script_show_inputs
input int number_menu=1;               //меню "Файл"
input int item_menu=14;                //пункт "Подключиться к торговому счёту"

#ifndef  _IsX64
#define  HWND long
#define  HMENU long
#define  HBITMAP long
#define  ULONG_PTR long
#else
#define  HWND int
#define  HMENU int
#define  HBITMAP int
#define  ULONG_PTR int
#endif 

#define  UINT int
#define  GA_ROOT            0x0002      // Retrieves the root window by walking the chain of parent windows
#define  WM_COMMAND         0x0111
#define  MIIM_STRING        0x00000040
#define  MIIM_SUBMENU       0x00000004
#define  BM_CLICK           0x000000F5

#import "user32.dll"
int  GetLastError();
//+------------------------------------------------------------------+
//| GetAncestor. Retrieves the handle to the ancestor of the         |
//| specified window. Извлекает дескриптор предка заданного окна     |
//+------------------------------------------------------------------+
HWND  GetAncestor(HWND hwnd,UINT gaFlags);
HMENU GetMenu(HWND hWnd);
//int   GetMenuItemCount(HMENU hMenu);
HMENU GetSubMenu(HMENU hMenu,int   nPos);
int   GetMenuItemID(HMENU hMenu,int nPos);
bool  PostMessageW(HWND hWnd,UINT Msg,int wParam,int lParam);
HWND  GetLastActivePopup(HWND hWnd);
HWND  GetDlgItem(HWND hDlg,int nIDDlgItem);
#import
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long  mainChartID=ChartID();                          //возвращает идентификатор текущего графика
   int   hdlmainChartID=ChartWindowsHandle(mainChartID); //получает хэндл графика   
   HWND  hdlRoot=GetAncestor(hdlmainChartID,GA_ROOT);    //получает хендл предка указанного окна
                                                         //Print("hdlRoot = ",IntegerToString(hdlRoot));

   HMENU hmenu=GetMenu(hdlRoot);                         //получает хэндл главного меню терминала
/*int count_hmenu=GetMenuItemCount(hmenu);
   Print("в главном меню ",IntegerToString(count_hmenu)," элементов");*/

   HMENU hsubmenu=GetSubMenu(hmenu,number_menu);         //получает хэндл заданного подменю ("Файл")
/*int count_hsubmenu=GetMenuItemCount(hsubmenu);
   Print("в подменю ",IntegerToString(number_menu)," ",IntegerToString(count_hsubmenu)," элементов");*/
   
   int hpos=GetMenuItemID(hsubmenu,item_menu);           //получает хэндл пункта "Подключиться к торговому счёту"
   PostMessageW(hdlRoot,WM_COMMAND,hpos,0);              //кликаем на пункт "Подключиться к торговому счёту"

   Sleep(2000);
   HWND hlastPopup=GetLastActivePopup(hdlRoot);          //получает хендл последнего PopUp меню
   HWND hOK=GetDlgItem(hlastPopup,0x00000001);           //получает хенд кнопки из диалога
   PostMessageW(hOK,BM_CLICK,0,0);                       //кликаем на кнопку "OK"
  }
//+------------------------------------------------------------------+
//| The function gets the handle graphics                            |
//| Функция получает хэндл графика                                   |
//+------------------------------------------------------------------+
int ChartWindowsHandle(long chart_ID)
  {
//--- prepare the variable to get the property value
//--- подготовим переменную для получения значения свойства
   long result=-1;
//--- reset the error value
//--- сбросим значение ошибки
   ResetLastError();
//--- receive the property value
//--- получим значение свойства
   if(!ChartGetInteger(chart_ID,CHART_WINDOW_HANDLE,0,result))
     {
      //--- display the error message in Experts journal
      //--- выведем сообщение об ошибке в журнал "Эксперты"
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
//--- вернем значение свойства графика
   return((int)result);
  }
//+------------------------------------------------------------------+

If everything works, I will clean up the code and post it in KodoBase.

Files:
ClickMenu.mq5  5 kb
 

MQL4. The StringToCharArray() description says "Symbolically copies a string converted from unicode to ansi into a specified location of an array of uchar type". I have an impression that there is an error in the description. With this function, you can simply convert a character into a number corresponding to the code depending on the character encoding (the function has 5 parameters). I.e. there is no conversion "... from unicode to ansi..." here. Correct me if I'm wrong.

If I need to find code, for example, for € symbol for Ansi, then in place of 5th parameter I will write CP_ACP. If as UTF7, then CP_UTF7. If for Unicode, I use StringToShortArray() (see script).

#property strict
void OnStart()
  {
   string a = "€"; // euro symbol
   uchar  ArrayAnsi[1], ArrayUTF7[1];
   ushort ArrayUnicode[1];
   
   int Count;
   Count=StringToCharArray(a,ArrayAnsi,0,WHOLE_ARRAY,CP_ACP);
   Print("1) € in Ansi = ",IntegerToString(ArrayAnsi[0]));
   
   Count=StringToCharArray(a,ArrayUTF7,0,WHOLE_ARRAY,CP_UTF7);
   Print("2) € in UTF7 = ",IntegerToString(ArrayUTF7[0]));

   Count=StringToShortArray(a,ArrayUnicode,0,WHOLE_ARRAY);
   Print("3) € in Unicode = ",IntegerToString(ArrayUnicode[0]));
  }


 

A bug in the compiler.

template<typename T>  void  Func (T&)     {  }
template<typename T>  void  Func (T*&)    {  }

template<typename T>  void  InterFunc(T& var)  { Func(var); }   // 'var' - parameter conversion not allowed
  

class A {  };


void F1()  { A a;   InterFunc(a);  }

void F2()  { A* a;  Func(a);  }

If you remove the F2 function, however, it compiles normally.

 

Compiler error.

class A {  };


void Func(A* const&)   {   }


void OnStart()
  {    
    A* const a= NULL;
    
    Func(a);  // 'a' - cannot convert from const pointer to nonconst pointer
  }
Reason: