Hi, I was wondering if there is an script to change the timeframe of all charts open in MT5. I have the MT4 code but am not able to make it work in MT5. Any help will be appreciated.
Please get acquainted with the possibilities of this group of functions - Chart Operations.
You will be interested in the following functions:
1. ChartSymbol - Returns the symbol name of the specified chart
2. ChartPeriod - Returns the period value of the specified chart
3. ChartID - Returns the ID of the current chart.
4. ChartSetSymbolPeriod - Changes the symbol value and a period of the specified chart.
PS
Also, to perform some action will be useful following functions:
ChartFirst - Returns the ID of the first chart of the client terminal
ChartNext - Returns the chart ID of the chart next to the specified one
Please get acquainted with the possibilities of this group of functions - Chart Operations.
Hi Interesting..Thank you for the response. I have been able to create a script that works partially, and I think erroneously
Here is the script.
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property script_show_inputs
input ENUM_TIMEFRAMES eintTF = PERIOD_M5;
//CChart MyChart;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
long chartID;
chartID=ChartFirst();
while (chartID!=-1)
{
Print (ChartSymbol(chartID));
ChartSetSymbolPeriod(chartID, ChartSymbol(chartID), eintTF);
chartID=ChartNext(chartID);
}
}
However this does not change the timeframe of all the charts. It skips some of them. Per the script, it should print the symbol of all the charts. But it ik skips some of them. I ma also attaching a list of open charts using the Alt+W command and the output of the script. You can see that it is not printing the symbol of all charts. Can you help me out here please?
Hi Interesting..Thank you for the response. I have been able to create a script that works partially, and I think erroneously
Here is the script.
However this does not change the timeframe of all the charts. It skips some of them. Per the script, it should print the symbol of all the charts. But it ik skips some of them. I ma also attaching a list of open charts using the Alt+W command and the output of the script. You can see that it is not printing the symbol of all charts. Can you help me out here please?
Hi, Please look at my code.
I am sure that this code will help you in your work.
Example
//////////////////////////////////////////////////////////////////////////////// // Script program start function // //////////////////////////////////////////////////////////////////////////////// void OnStart() { //----------------------------------------------------------------------------// //Work variables ENUM_TIMEFRAMES TimeFrames; //TimeFrames string ChartSymbolName; //The symbol name for the specified chart long ChartFirstID; //The ID of the first chart of the client terminal long ChartNextID; //Identifier for of the new chart int Limit= CHARTS_MAX; int f; //----------------------------------------------------------------------------// //Checking parameters if(WorkPeriod == PERIOD_CURRENT) TimeFrames = _Period; else TimeFrames = WorkPeriod; //Synchronizing the timeframes of the charts ChartFirstID = ChartFirst(); //Processing of the main chart if(ChartPeriod(ChartFirstID)!= TimeFrames) { ChartSymbolName = ChartSymbol(ChartNextID); //Change the timeframe of the specified chart ChartSetSymbolPeriod(ChartFirstID,ChartSymbolName,TimeFrames); //Message for user PrintFormat("Change the timeframe of the chart %s. New period %s", ChartSymbolName,PeriodToStr(TimeFrames)); } //Processing of additional charts while(f<Limit) //We have certainly not more than 100 open charts { //Get the new chart ID by using the previous chart ID ChartNextID = ChartNext(ChartFirstID); if(ChartNextID<0) break; //Have reached the end of the chart list if(ChartPeriod(ChartNextID)!= TimeFrames) //Change the timeframe of the specified chart { ChartSymbolName = ChartSymbol(ChartNextID); //Change the timeframe of the specified chart ChartSetSymbolPeriod(ChartNextID,ChartSymbolName,TimeFrames); //Message for user PrintFormat("Change the timeframe of the chart %s. New period %s", ChartSymbolName,PeriodToStr(TimeFrames)); } //Let's save the current chart ID for the ChartNext() ChartFirstID = ChartNextID; // Do not forget to increase the counter f++; } //----------------------------------------------------------------------------// }
Hi is there a way for change Timeframe only on select chart (for Mql4)? I try to modify the indicator 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 }
Hi is there a way for change Timeframe only on select chart (for Mql4)? I try to modify the indicator but does't work... it appears a Popup: "Do you really want to stop the script?" Does anybody kwow the reason?
Hi Peperlizio,
Your MQL4 code there is not even an indicator, it's a script. With a script a window will pop out every time you change the time frame. I have indicator - not a script that change my time frame every n second and No window poping out.
If you want to change that script to Expert Advisor, just move it from script folder to expert folder.
If you want to change that script to indicator,
Move that script from scripts folder to indicators folder then delete this
#property show_inputs
Then add this at the same place
#property indicator_chart_window
Compile it and there will be no pop out window.
Hi Peperlizio,
Your MQL4 code there is not even an indicator, it's a script.
Hi onewithzachy! Yes, i wrote indicator but I wanted to say script... =) Thanks for the advice you're right, with an indicator the problem does not exist.
I create this indicator like example, if you move the cross the chart Timeframe change.
//+------------------------------------------------------------------+ //| 00 - ChgTF Prova.mq4 | //| Copyright © 2012, Peperlizio. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2012, Peperlizio." #import "user32.dll" int PostMessageA(int hWnd,int Msg,int wParam,int lParam); int GetWindow(int hWnd,int uCmd); int GetParent(int hWnd); #import #define VK_END 0x23 #define WM_COMMAND 0x0111 #define WM_KEYDOWN 0x0100 extern int Timeframe = PERIOD_M30; string tmp; string Prefix = "CNGTF"; #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { for (int i=ObjectsTotal()-1; i>=0; i--) { tmp = ObjectName(i); if (StringFind(tmp,Prefix) >= 0) ObjectDelete(tmp); } return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int TF, Windows; switch (Timeframe) { case PERIOD_M1: TF = 33137; break; case PERIOD_M5: TF = 33138; break; case PERIOD_M15: TF = 33139; break; case PERIOD_M30: TF = 33140; break; case PERIOD_H1: TF = 35400; break; case PERIOD_H4: TF = 33136; break; case PERIOD_D1: TF = 33134; break; case PERIOD_W1: TF = 33141; break; case PERIOD_MN1: TF = 33334; break; } tmp = Prefix+"+"; if (ObjectFind(tmp) == -1) { ObjectCreate(tmp,OBJ_LABEL,0,0,0); ObjectSetText(tmp,"+",12,"Arial",DarkOrange); ObjectSet(tmp,OBJPROP_XDISTANCE,10); ObjectSet(tmp,OBJPROP_YDISTANCE,10); ObjectSet(tmp,OBJPROP_CORNER,1); } if (ObjectGet(tmp,OBJPROP_XDISTANCE)!=10 || ObjectGet(tmp,OBJPROP_YDISTANCE)!=10) { ObjectSet(tmp,OBJPROP_XDISTANCE,10); ObjectSet(tmp,OBJPROP_YDISTANCE,10); if (Period() != Timeframe) { Windows = GetWindow( WindowHandle( Symbol(), Period() ),0); PostMessageA(Windows,WM_COMMAND,TF,0); PostMessageA(Windows,WM_KEYDOWN,VK_END,0); } } return(0); } //+------------------------------------------------------------------+
But doubt still remain... why first script (post n°1) works whit all charts and second script (post n°6) doesn't work with single chart? Theoretically Popup must also appear in first script! it's a mistery! =)
Hi onewithzachy! Yes, i wrote indicator but I wanted to say script... =) Thanks for the advice you're right, with an indicator the problem does not exist.
I create this indicator like example, if you move the cross the chart Timeframe change.
But doubt still remain... why first script (post n°1) works whit all charts and second script (post n°6) doesn't work with single chart? Theoretically Popup must also appear in first script! it's a mistery! =)
Hi Peperlizio,
It's weekend so there is no tick. Create this script below to send fake tick - and try again on Monday.
Pop out window only appear with script attached, because script is executed immediately without waiting for a tick.
See you on Monday.
#import "user32.dll" int PostMessageA(int hWnd,int Msg,int wParam,int lParam); int RegisterWindowMessageA(string lpString); #import //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- int hwnd=WindowHandle(Symbol(), Period()); int msg = RegisterWindowMessageA("MetaTrader4_Internal_Message"); PostMessageA(hwnd, msg, 2, 1); //---- return(0); } //+------------------------------------------------------------------+
hello, can you help me please?
hello, can you help me please?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I was wondering if there is an script to change the timeframe of all charts open in MT5. I have the MT4 code but am not able to make it work in MT5. Any help will be appreciated.