Code to arrange charts

To add comments, please log in or register
fxsquirrel
22
fxsquirrel  

Hi,

I'm writing a script to setup a workspace. From the main toolbar, if you select "Window" you get a dropdown list. I can't find the functions that perform these actions. Do they exist?

Tile Windows

Cascade

Tile Horizontally

Tile Vertically


Also is there any code to minimise and maximise a chart window?

Thanks.

kypa
1079
kypa  

I have this script for vertical cascade-like arrangement.

//+----------------------------------------------------------------------------------------------------+
//|                                                                                   windowresize.mq5 |
//+----------------------------------------------------------------------------------------------------+

#import "user32.dll"
   int GetParent(long hWnd);
   bool SetWindowPos(int hWnd, int hWndInsertAfter, int x, int y, int width, int height, uint uFlags);
   void keybd_event(int bVk, int bScan, int dwFlags, int dwExtraInfo);
#import

void OnStart()
  {
   if(ChartGetInteger(0,CHART_IS_MAXIMIZED,0)==1)
     {
      keybd_event(0x12,0,0,0);
      keybd_event(0x52,0,0,0);
      keybd_event(0x12,0,0x0002,0);
      keybd_event(0x52,0,0x0002,0);
     }

   long FirstChartID = ChartFirst();
   long SecondChartID = ChartNext(FirstChartID);
   long ThirdChartID = ChartNext(SecondChartID);
   long FourthChartID = ChartNext(ThirdChartID);

   long FirstChartHandle, SecondChartHandle, ThirdChartHandle, FourthChartHandle;
   int FirstChartParentHandle, SecondChartParentHandle, ThirdChartParentHandle, FourthChartParentHandle;

   ChartGetInteger(FirstChartID,CHART_WINDOW_HANDLE,0,FirstChartHandle);
   ChartGetInteger(SecondChartID,CHART_WINDOW_HANDLE,0,SecondChartHandle);
   ChartGetInteger(ThirdChartID,CHART_WINDOW_HANDLE,0,ThirdChartHandle);
   ChartGetInteger(FourthChartID,CHART_WINDOW_HANDLE,0,FourthChartHandle);

   FirstChartParentHandle=GetParent(FirstChartHandle);
   SecondChartParentHandle=GetParent(SecondChartHandle);
   ThirdChartParentHandle=GetParent(ThirdChartHandle);
   FourthChartParentHandle=GetParent(FourthChartHandle);

   SetWindowPos(FourthChartParentHandle,0,1288,0,640,958,0);
   SetWindowPos(ThirdChartParentHandle,0,900,0,640,958,0);
   SetWindowPos(SecondChartParentHandle,0,450,0,640,958,0);
   SetWindowPos(FirstChartParentHandle,0,0,0,620,958,0);
  }

//+----------------------------------------------------------------------------------------------------+

It is calibrated for 4 charts on a FHD screen. It's for MT5, for MT4 I think handles had to be declared as longs.

fxsquirrel
22
fxsquirrel  
kypa:

I have this script for vertical cascade-like arrangement.

It is calibrated for 4 charts on a FHD screen. It's for MT5, for MT4 I think handles had to be declared as longs.

Hey thanks for this, I'll have a go amending this for MQL4. 
William Roeder
20214
William Roeder  
kypa: for MT4 I think handles had to be declared as longs.

Don't think, read the documentation and be sure:

Returns the chart ID of the chart next to the specified one.
long  ChartNext(
   long  chart_id      // Chart ID
   );   
         ChartNext - Chart Operations - MQL4 Reference
Then write self-documenting code
#define CHART_ID long
   #define CHART_INVALID (CHART_ID) -1
To add comments, please log in or register