Change Timeframe on chart fuction or script

 

Hi is there a way for change Timeframe only on select chart?

I found this script but it changes Timeframe on all charts.

//+------------------------------------------------------------------+
//|                                                    ChgTF-All.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, zznbrm"
#property show_inputs

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

extern int eintTF = PERIOD_M5;
                   
int start()
{      
   bool blnContinue = true;   
   int intParent = GetParent( WindowHandle( Symbol(), Period() ) );   
   int intChild = GetWindow( intParent, 0 );  
   int intCmd; 
   
   switch( eintTF )
   {
      case PERIOD_M1:   intCmd = 33137;  break;
      case PERIOD_M5:   intCmd = 33138;  break;
      case PERIOD_M15:  intCmd = 33139;  break;
      case PERIOD_M30:  intCmd = 33140;  break;
      case PERIOD_H1:   intCmd = 35400;  break;
      case PERIOD_H4:   intCmd = 33136;  break;
      case PERIOD_D1:   intCmd = 33134;  break;
      case PERIOD_W1:   intCmd = 33141;  break;
      case PERIOD_MN1:  intCmd = 33334;  break;
   }
   
   if ( intChild > 0 )   
   {
      if ( intChild != intParent )   PostMessageA( intChild, 0x0111, intCmd, 0 );
   }
   else      blnContinue = false;   
   
   while( blnContinue )
   {
      intChild = GetWindow( intChild, 2 );   
   
      if ( intChild > 0 )   
      { 
         if ( intChild != intParent )   PostMessageA( intChild, 0x0111, intCmd, 0 );
      }
      else   blnContinue = false;   
   }
   
   // Now do the current window
   PostMessageA( intParent, 0x0111, intCmd, 0 );
}

I try to modify the script but does't work... it appears a Popup: "Do you really want to stop the script?" Does anybody kwow the reason?

//+------------------------------------------------------------------+
//|                                                ChgTF-All-Mod.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, zznbrm"
#property show_inputs                                                       //Evita di aprire la schermata dei parametri all'avvio

#import "user32.dll"
   int      PostMessageA(int hWnd,int Msg,int wParam,int lParam);
   int      GetWindow(int hWnd,int uCmd);
   int      GetParent(int hWnd);
#import
                                                                              //Eliminate le variabili per le finestre figli
extern int eintTF = PERIOD_M30;
                   
int start()
{      
   bool blnContinue = true;   
   int intParent = GetParent( WindowHandle( Symbol(), Period() ) );   
   int intCmd; 
   
   switch( eintTF )
   {
      case PERIOD_M1:   intCmd = 33137;  break;
      case PERIOD_M5:   intCmd = 33138;  break;
      case PERIOD_M15:  intCmd = 33139;  break;
      case PERIOD_M30:  intCmd = 33140;  break;
      case PERIOD_H1:   intCmd = 35400;  break;
      case PERIOD_H4:   intCmd = 33136;  break;
      case PERIOD_D1:   intCmd = 33134;  break;
      case PERIOD_W1:   intCmd = 33141;  break;
      case PERIOD_MN1:  intCmd = 33334;  break;
   }
   
   
   // Now do the current window
   PostMessageA( intParent, 0x0111, intCmd, 0 );                              //Abilita il comando solo sulla finestra genitore, cioè quella aperta al momento
Files:
 
 

I use this to change the chart on my EA if it's not on the right one (M15 in this case)

 

//+------------------------------------------------------------------+
//|                                                          CTF.mq4 |
//|                                            Copyright ©2013 PaulB |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

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

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init(){

if(Period()!=PERIOD_M15)
{
   int intParent = GetParent( WindowHandle( Symbol(), Period() ) ), intCmd;
   switch( PERIOD_M15 )
   {
      case PERIOD_M1:   intCmd = 33137;  break;
      case PERIOD_M5:   intCmd = 33138;  break;
      case PERIOD_M15:  intCmd = 33139;  break;
      case PERIOD_M30:  intCmd = 33140;  break;
      case PERIOD_H1:   intCmd = 35400;  break;
      case PERIOD_H4:   intCmd = 33136;  break;
      case PERIOD_D1:   intCmd = 33134;  break;
      case PERIOD_W1:   intCmd = 33141;  break;
      case PERIOD_MN1:  intCmd = 33334;  break;
   }
   PostMessageA( intParent, 0x0111, intCmd, 0 );
}

return(0);}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){


return(0);}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start(){

return(0);}
//+------------------------------------------------------------------+
 
 
Since February 3, 2014 (Build 600) we can now use ChartSetSymbolPeriod - Chart Operations - MQL4 Reference
Reason: