오류, 버그, 질문 - 페이지 1622

 
fxsaber :
경우에 따라 시각적 테스트 에서 닫히지 않는 창에 있는 것 같습니다. 그러나 재생산할 수 없습니다. 이제 모든 것이 작동했습니다.

테스트나 최적화가 있었나요? 후자의 경우 실제로 문제가 있습니다.

[삭제]  
Karputov Vladimir :

다음은 "파일" 메뉴를 호출하는 스크립트입니다 - "거래 계정에 연결" 항목 - "확인" 버튼 클릭 - 이런 식으로 터미널은 승인된 마지막 거래 계정에 연결됩니다:

 #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

_IsX64는 그렇게 사용할 수 없습니다. 런타임 에만 중요 합니다.

 
Alexey Navoykov :

테스트나 최적화가 있었나요? 후자의 경우 실제로 문제가 있습니다.

단일 실행, 최적화는 포함되지 않습니다.
 
Koldun Zloy :

_IsX64는 그렇게 사용할 수 없습니다. 런타임 에만 중요 합니다.

힌트를 주셔서 감사합니다. 포함된 파일 형태로 수정 및 발행:

 //+------------------------------------------------------------------+
//|                                          LoginToTradeAccount.mqh |
//|                              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 description "Library for clicks on the MetaTrader 5 menu \"File\" item \"Login to trading account\""
#property description "Библиотека для кликов по меню MetaTrader 5 \"Файл\" пункт \"Подключиться к торговому счёту\""

int number_menu= 1 ;   //menu "File"; меню "Файл"
int item_menu= 14 ;     //item "Login to trading account"; пункт "Подключиться к торговому счёту"

#define GA_ROOT             0x00000002    // Retrieves the root window by walking the chain of parent windows
#define WM_COMMAND         0x00000111
#define BM_CLICK           0x000000F5

#import "user32.dll"
int    GetLastError ();
//+------------------------------------------------------------------+
//| GetAncestor. Retrieves the handle to the ancestor of the         |
//| specified window. Возвращает хендл предка заданного окна         |
//+------------------------------------------------------------------+
//--- x64
long   GetAncestor( long hwnd, int gaFlags);
//--- x86
int   GetAncestor( int hwnd, int gaFlags);
//+------------------------------------------------------------------+
//| GetMenu. Retrieves a handle to the menu assigned to the          |
//| specified window. Возвращает хендл меню,                         |
//| назначенного указанному окну.                                    |
//+------------------------------------------------------------------+
//--- x64
long GetMenu( long hWnd);
//--- x86
int GetMenu( int hWnd);
//+------------------------------------------------------------------+
//| GetSubMenu. Retrieves a handle to the drop-down menu or submenu  |
//| activated by the specified menu item. Возвращает хендл           |
//| выпадающего меню или подменю указанного пункта меню.             |
//+------------------------------------------------------------------+
//--- x64
long GetSubMenu( long hMenu, int nPos);
//--- x86
int GetSubMenu( int hMenu, int nPos);
//+------------------------------------------------------------------+
//| GetMenuItemID. Retrieves the menu item identifier of a menu item |
//| located at the specified position in a menu. Возвращает          |
//| идентификатор пункта меню, расположенного в                      |
//| указанной позиции в меню.                                        |
//+------------------------------------------------------------------+
//--- x64
int    GetMenuItemID( long hMenu, int nPos);
//--- x86
int    GetMenuItemID( int hMenu, int nPos);
//+------------------------------------------------------------------+
//| PostMessageW. Places (posts) a message in the message queue      |
//| associated with the thread that created the specified window     |
//| and returns without waiting for the thread to process the        |
//| message. Размещает (публикует) сообщение в очереди сообщений,    |
//| связанной с потоком, который создал указанное окно и             |
//| возвращается, не дожидаясь потока, чтобы обработать сообщение.   |
//+------------------------------------------------------------------+
//--- x64
bool   PostMessageW( long hWnd, int Msg, int wParam, int lParam);
//--- x86
bool   PostMessageW( int hWnd, int Msg, int wParam, int lParam);
//+------------------------------------------------------------------+
//| GetLastActivePopup. Determines which pop-up window owned by the  |
//| specified window was most recently active. Определяет, какое     |
//| всплывающее окно, принадлежащие указанному окну, совсем недавно  |
//| было активным.                                                   |
//+------------------------------------------------------------------+
//--- x64
long   GetLastActivePopup( long hWnd);
//--- x86
int   GetLastActivePopup( int hWnd);
//+------------------------------------------------------------------+
//| GetDlgItem. Retrieves a handle to a control in the specified     |
//| dialog box. Возвращает хэндл элемента управления в               |
//| указанном диалоговом окне.                                       |
//+------------------------------------------------------------------+
//--- x64
long   GetDlgItem( long hDlg, int nIDDlgItem);
//--- x86
int   GetDlgItem( int hDlg, int nIDDlgItem);
#import
//+------------------------------------------------------------------+
//| Click on the item "Login to trading account"                     |
//| Клик на пункте "Подключиться к торговому счёту"                  |
//+------------------------------------------------------------------+
void LoginToTradeAccount()
  {
   long mainChartID= ChartID (); //returns the ID of the current chart; возвращает идентификатор текущего графика
   int hdlmainChartID=ChartWindowsHandle(mainChartID); //returns the Chart window handle (HWND); получает хэндл графика 

   if ( _IsX64 )
     {
       long hdlRoot=GetAncestor(( long )hdlmainChartID,GA_ROOT);
       long hmenu=GetMenu(hdlRoot);
       long hsubmenu=GetSubMenu(hmenu,number_menu);
       int hpos=GetMenuItemID(hsubmenu,item_menu);
      PostMessageW(hdlRoot,WM_COMMAND,hpos, 0 );
       Sleep ( 2000 );
       long hlastPopup=GetLastActivePopup(hdlRoot);
       long hOK=GetDlgItem(hlastPopup, 0x00000001 );
      PostMessageW(hOK,BM_CLICK, 0 , 0 );
     }
   else
     {
       int hdlRoot=GetAncestor(hdlmainChartID,GA_ROOT);
       int hmenu=GetMenu(hdlRoot);
       int hsubmenu=GetSubMenu(hmenu,number_menu);
       int hpos=GetMenuItemID(hsubmenu,item_menu);
      PostMessageW(hdlRoot,WM_COMMAND,hpos, 0 );
       Sleep ( 2000 );
       int hlastPopup=GetLastActivePopup(hdlRoot);
       int hOK=GetDlgItem(hlastPopup, 0x00000001 );
      PostMessageW(hOK,BM_CLICK, 0 , 0 );
     }
  }
//+------------------------------------------------------------------+
//| 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);
  }
//+------------------------------------------------------------------+
파일:
 
Dmitri Custurov :
불행히도 항상 그런 것은 아닙니다. 장기간 연결이 없으면 단말기에서 "계정 비활성화"가 발생하고 그 이후에는 수동으로 로그인해야 합니다. 예를 들어, 이것은 일반적으로 밤에 서버가 꺼져 있는 펀드에서 발생합니다.

해결책은 다음과 같습니다. EA는 주기적으로 거래 서버( TERMINAL_CONNECTED )에 대한 연결 상태를 확인하고 반환된 값이 "0"이면 "파일" 메뉴가 호출됩니다(WIN API 사용), "연결 거래 계정으로" 항목. 메뉴 클릭 기능을 구현하는 포함 파일은 여기 입니다. 고문 예:

 //+------------------------------------------------------------------+
//|                                           TestAccountDisable.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"

#include <LoginToTradeAccount.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- create timer
   EventSetTimer ( 12 );

//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- destroy timer
   EventKillTimer ();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer ()
  {
//---
   static bool cleaner= false ;
   if (!cleaner)
     {
       long rezult= TerminalInfoInteger ( TERMINAL_CONNECTED );
       Comment ( "TERMINAL_CONNECTED: " , IntegerToString (rezult));
       if (rezult== 0 )
         LoginToTradeAccount();
     }
   else
       Comment ( "" );
   cleaner=!cleaner;
  }
//+------------------------------------------------------------------+

EA는 12초마다 연결 상태를 확인하고 2초마다 댓글을 삭제합니다.

 
확정은 없나요?
 

어레이가 있는 파일을 어드바이저에 연결하는 방법은 무엇입니까?

먼저 스크립트는 배열을 작성합니다.

 string filename= "mas.dat" ;
int handle= FileOpen (filename, FILE_BIN | FILE_WRITE );
FileWriteArray (handle,hol, 0 , 4608 );
FileClose (handle);

어드바이저에 다음 파일을 포함합니다.

 #include <mas.dat> 

컴파일할 때 오류:

'????????????????????????????????????...' - 식별자가 너무 깁니다. mas.dat 하나 하나

' ' - 알 수 없는 기호 mas.dat 하나 3015

 
Aliaksandr Yemialyanau :

어레이가 있는 파일을 어드바이저에 연결하는 방법은 무엇입니까?

먼저 스크립트는 배열을 작성합니다.

어드바이저에 다음 파일을 포함합니다.

컴파일할 때 오류:

'????????????????????????????????????...' - 식별자가 너무 깁니다. mas.dat 하나 하나

' ' - 알 수 없는 기호 mas.dat 하나 3015

전체 어레이 파일을 메모리로 읽은 다음 작업하는 것이 훨씬 더 빠릅니다. 가속은 몇 배 더 빠릅니다.
 
Karputov Vladimir :

해결책은 다음과 같습니다. EA는 주기적으로 거래 서버( TERMINAL_CONNECTED )에 대한 연결 상태를 확인하고 반환된 값이 "0"이면 "파일" 메뉴가 호출됩니다(WIN API 사용), "연결 거래 계정으로" 항목. 메뉴 클릭 기능을 구현하는 포함 파일은 여기 입니다. 고문 예:

EA는 12초마다 연결 상태를 확인하고 2초마다 댓글을 삭제합니다.

솔루션을 제공해 주셔서 대단히 감사합니다. 모든 것이 작동합니다.
 
디버깅
 #define i ii

void OnTick ()
{
   for ( int i = 0 ; i < 5 ; i++)
     Print (i); // отладчик по Shift+F9 показывает не ii, а i, выдавая Unknown identifier
}