How Do You Programmatically Open A New Chart?

[Deleted]  

Within a Script, I would like to open a new chart, but can find no documentaion on how to do this. Ideally, I would prefer to skip the solutions that include sending keys to the main terminal window (i.e. ALT-F N).

I have found examples of how to attach an EA to a chart :

int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");
PostMessageA(hWnd, MessageNumber, 14, EAName);

And to change the TimeFrame of a chart:

PostMessageA(hwnd_parent,WM_COMMAND,33137,0); 

Surely there must be a similar way to open a new chart, right?

Thanks!

JC
1674
JC  
databasedna:

[...] Surely there must be a similar way to open a new chart, right?

Not as far as I'm aware (and it's probably my post which you found for attaching an EA to a chart).


One thing to watch out for with the timeframe-changing method is that it almost certainly affects whichever chart is topmost, not (necessarily) the chart from which it's called. I've not tried it myself, but that's certainly how it looks as though it's working.

[Deleted]  

jjc,

thanks for the reply and for your previous research that i sited. i was mainly using it as an example of the type of solution i was looking for, but will keep your additional advice in mind when using it to change the tf.

Ilnur Iksanov
5906
Ilnur Iksanov  
databasedna:

How Do You Programmatically Open A New Chart?


#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);
#import

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

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void start()
{

// New charts opens from the "Market Watch" window with the DEFAULT.TPL template.

   ChartWindow("GOLD");
}

//+------------------------------------------------------------------+
//| Open a new chart                                                 |
//+------------------------------------------------------------------+
int ChartWindow(string SymbolName)
{
   int hFile, SymbolsTotal, hTerminal, hWnd;

   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);

   for(int i = 0; i < SymbolsTotal; i++)
   {
      if(FileReadString(hFile, 12) == SymbolName)
      {
         PostMessageA(hTerminal, WM_COMMAND, 33160, 0);
         return(0);
      }
      PostMessageA(hWnd, WM_KEYDOWN, VK_DOWN, 0);
      FileSeek(hFile, 116, SEEK_CUR);
   }

   FileClose(hFile);

   return(-1);
}
[Deleted]  

Hi Ilnur,

I found your post, thank you it is very helpful. I have open chart but i do not know how attach to chart EA. Can you please show to me how to do this.

Thanks

This is what i am doing

int ChartWindow(string SymbolName)

{

int hFile, SymbolsTotal, hTerminal, hWnd;


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);


for(int i = 0; i < SymbolsTotal; i++)

{

if(FileReadString(hFile, 12) == SymbolName)

{

PostMessageA(hTerminal, WM_COMMAND, 33160, 0);

int MessageNumber = RegisterWindowMessageA("MetaTrader4_Internal_Message");

PostMessageA(hTerminal, MessageNumber, 14, "myEA");

return(0);

}

PostMessageA(hWnd, WM_KEYDOWN, VK_DOWN, 0);

FileSeek(hFile, 116, SEEK_CUR);

}


FileClose(hFile);


return(-1);

}

William Roeder
25322
William Roeder  
anvarb:
I have open chart but i do not know how attach to chart EA.

how to attach an EA to a chart programmatic - MQL4 forum https://www.mql5.com/en/forum/131566

Don't double post.