How to select a Chart Window after open it? Symbol() show just Instrument which was opend before

 

How to select a Chart Window after open it? Symbol() show just Instrument which was opend before.

I want to write a script which open different Instruments, do a operation and then close the chartwindow again. But I was getting always the same data. The reason was everytime I open a new chart of an instrument, Metatrader 4 stuck at the chart which was opend before and the function Symbol() show not the new opened instrument chart.

Is there maybe a chart-select-function in Metatrader 4? I tried WindowRedraw(), but that solved the problem not. I also tried to change to another chart with simulating pressing "Ctrl+F6" buy using this code:

#import "user32.dll"
    void keybd_event(int bVk, int bScan, int dwFlags,int dwExtraInfo);
#import
#define  VK_F9 0x78                          // F9
#define  KEYEVENTF_KEYUP 0x0002   // key up
#define  VK_F6 0x75                          // F6
#define  VK_LCONTROL 0xA2             // Strg / Ctrl
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   printf("Symbol before: %s", Symbol());
  
   keybd_event(0xA2, 0, 1, 0);      // press left CTRL
   keybd_event(0x75, 0, 0, 0);      // press F6
   keybd_event(0xA2, 0, 0x0002, 0); // release left CTRL
   keybd_event(0x75, 0, 0x0002, 0); // release F6

printf("Symbol after: %s", Symbol());


}


but this solves also not the problem.


Have you any Idea?


Kind regards, Daniel.

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
long chartID = ChartOpen("EURUSD",PERIOD_H1); // open a chart.

// do something...

bool close = ChartClose(chart_ID);            // close chart.
 
Marco vd Heijden:

Thank you very much. You gave me the right hind. My function have to depend from iHigh an iLow and not from High and Low.

But I have another question. How to use ArrayMaximum with iHigh and ArrayMinimum with iLow?

 

Also these problem is solved:

void OnStart()
  {
//---
   double ArrayHigh[301]={0};
   for(int i; i<=300; i++)
   {
      if(iHigh("EURUSD",1,i)==0) break;
      ArrayHigh[i]=iHigh("EURUSD",1,i);
   }
   int IdxAtMaximum = ArrayMaximum(ArrayHigh,WHOLE_ARRAY,0);
   printf("IdxAtMaximum=%d",IdxAtMaximum);
   
   
  }


When a problem is charted, It is solved on the half way. Thank you Marco vd Heijden.

 

I suppose you can also check out:

iHighest(....
iLowest(....