Download MetaTrader 5
To add comments, please log in or register
How to earn at MQL5.community? Come and find out!
Black_Jack822
57
Black_Jack822 2015.09.06 22:41 
Hi all. Please help me find an error in this script.

It will open a new chart with specific template when you drag it from script list and drop it on the open chart, but when using "hotkey" it will open chart which is selected in MT4 "symbol list" instead the one which is currently open.

#import "user32.dll"

   int GetAncestor(int hWnd, int gaFlags);
   int GetDlgItem(int hDlg, int nIDDlgItem);
   int PostMessageA(int hWnd, int Msg, int wParam, int lParam);
   int GetParent(int hWnd);
   int GetWindow(int hWnd,int uCmd);   
   
#import

#define WM_COMMAND   0x0111
#define WM_KEYDOWN   0x0100
#define VK_HOME      0x0024
#define VK_DOWN      0x0028

//+------------------------------------------------------------------+
//| Open a new chart                                                 |
//+------------------------------------------------------------------+
int init()
  {
   OpenChart(Symbol(),Period());
 
   return(0);
  }
//--------------------------------------------------------------------
int OpenChart(string SymbolName, int TimeFrame)
{
   int hFile, SymbolsTotal, hTerminal, hWnd, intCmd;
   
   hFile = FileOpenHistory("symbols.sel", FILE_BIN|FILE_READ);
   if(hFile < 0) return(-1);

   SymbolsTotal = (FileSize(hFile) - 4) / 128;
   FileSeek(hFile, 4, SEEK_SET);

   hTerminal = GetAncestor(WindowHandle(Symbol(), Period()), 2);

   hWnd = GetDlgItem(hTerminal, 0xE81C);
   hWnd = GetDlgItem(hWnd, 0x50);
   hWnd = GetDlgItem(hWnd, 0x8A71);

   PostMessageA(hWnd, WM_KEYDOWN, VK_HOME, 0);
//---------------------------------------------------
   switch( TimeFrame )
   {
      case 1:   intCmd = 33137;  break;
      case 5:   intCmd = 33138;  break;
      case 15:  intCmd = 33139;  break;
      case 30:  intCmd = 33140;  break;
      case 60:   intCmd = 35400;  break;
      case 240:   intCmd = 33136;  break;
      case 1440:   intCmd = 33134;  break;
      case 10080:   intCmd = 33141;  break;
      case 43200:  intCmd = 33334;  break;
   }
//--------------------------------------------------   
   for(int i = 0; i < SymbolsTotal; i++)
   {
      if(FileReadString(hFile, 12) == Symbol())
      {
      PostMessageA(hTerminal, WM_COMMAND, 33160, 0);
      Sleep(100); 
      PostMessageA(hTerminal,WM_COMMAND,intCmd,0);
      Sleep(100);
      PostMessageA(hTerminal, WM_COMMAND, 34800, 0 );        
   
   return(0);
      }
      PostMessageA(hWnd, WM_KEYDOWN, VK_DOWN, 0);
      FileSeek(hFile, 116, SEEK_CUR);
   }
   FileClose(hFile);

   return(-1);
}
//-----------------------------------------------------
Alain Verleyen
Moderator
30186
Alain Verleyen 2015.09.07 09:31  
  • All these WinApi calls are not needed, MT4 has now built-in functions to do such things.
  • MT4 is now using Unicode for strings, you have to use unicode version of WinApi functions (with suffix 'W' instead of 'A').
Black_Jack822
57
Black_Jack822 2015.09.07 11:27  
Alain Verleyen:
  • All these WinApi calls are not needed, MT4 has now built-in functions to do such things.
  • MT4 is now using Unicode for strings, you have to use unicode version of WinApi functions (with suffix 'W' instead of 'A').
will it fix the problem that I've mentioned??
/
To add comments, please log in or register