Auto open chart when a trade is running

 

Hi,

I would like that when I take a trade, it automatically open the corresponding chart in my MT4 and when the trade is closed, the chart auto-close. 

So that the only opened charts are the ones where a trade is currently running.

Does anyone know how I could manage to do that?

 
ChartOpen(), ChartClose(). Read the documentation.
 

I have found this code but this doesnt seem to work well:

//+------------------------------------------------------------------+
//|                                                     switcher.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

#import "user32.dll"
   int GetParent(int hWnd);
   int SendMessageA(int hWnd, int Msg, int wParam, int lParam);
#import

#define WM_MDINEXT   548

extern int SlideShowSeconds = 15;

void start()
{
   while (!IsStopped()) {
      int hMDI = GetParent(GetParent(WindowHandle(Symbol(), Period())));
      SendMessageA(hMDI, WM_MDINEXT, 0, 0);

      Sleep(SlideShowSeconds * 1000);
   }