Indicators: Change Timeframes with Hotkeys - page 2

 

Hi guys,


Even with the updated indicator, when im using it while EA is running its making they system very slow...


The EA im running is - PZ trade pad EA


The same scenario while im running another EA - Trade Manger 4 lite.

 

Hello, Thanks for the hotkey indicator its really helpful but there is a problem, when you draw any Horizontal or Vertical lines it will disappear if you change the timeframe. 

Please advice. 

Thank you.

 
magickmystik # :

Oi, como é que eu não posso usar o teclado numérico, número 1, 2, etc?

eu só posso usar o número 1,2 etc em cima do teclado principal

é certo acontecer assim?

obrigada

Hi!

You can make the following modification to the original code. (see image "Modification.png")

But you are not limited to this modification, you can use the key codes you prefer and thus choose the physical keyboard character you prefer to use as a shortcut in MT4. (see image "Key Codes.png")

God bless you!

Files:
 
Marco vd Heijden #:

Use the

Function with the respectively

ENUM_CHART_EVENT

ID

Description

CHARTEVENT_KEYDOWN

Keystrokes


Plese see: https://www.mql5.com/en/docs/constants/chartconstants/enum_chartevents

And scroll down for example.

In this case it succeeds to remove

in

Function.

See below


Thank you, I added a switch on `TAB` to swap in all open charts.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property description   "The indicator will change the timeframe of the chart with key press"
#property description   "1 - M1, 2 - M5, 3 - M15, 4 - M30, 5 - H1, 6 - H4, 7 - D1, 8 - W1, 9 - MN"
#property strict

#property indicator_chart_window

#define KEY_MONTHLY 57
#define KEY_WEEKLY 56
#define KEY_DAILY 55
#define KEY_4HOUR 54
#define KEY_1HOUR 53
#define KEY_5MIN 50
#define KEY_30MIN 52
#define KEY_15MIN 51
#define KEY_1MIN 49
#define KEY_CHARTFIX 48
#define KEY_P 80


#define KEY_MODE 9 // TAB
string ALL_CHARTS_GLOB_VAR = "__TFHOTKEY_ALL_CHARTS";
//+------------------------------------------------------------------+
// Custom indicator initialization function
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   return(rates_total);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void _ChartSetSymbolPeriod(ENUM_TIMEFRAMES tf)
  {
   if(GlobalVariableGet(ALL_CHARTS_GLOB_VAR))
     {
      Print("switching all charts");
      for(long chartID = ChartNext(0); chartID > -1; chartID = ChartNext(chartID))
        {
         ChartSetSymbolPeriod(chartID, ChartSymbol(chartID), tf);
        };
     }
   else
      ChartSetSymbolPeriod(0, NULL, tf);
  }

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_KEYDOWN)
     {
      switch(int(lparam))
        {
         case KEY_MONTHLY:
            _ChartSetSymbolPeriod(43200);
            break;
         case KEY_WEEKLY:
            _ChartSetSymbolPeriod(10080);
            break;
         case KEY_DAILY:
            _ChartSetSymbolPeriod(1440);
            break;
         case KEY_4HOUR:
            _ChartSetSymbolPeriod(240);
            break;
         case KEY_1HOUR:
            _ChartSetSymbolPeriod(60);
            break;
         case KEY_5MIN:
            _ChartSetSymbolPeriod(5);
            break;
         case KEY_30MIN:
            _ChartSetSymbolPeriod(30);
            break;
         case KEY_15MIN:
            _ChartSetSymbolPeriod(15);
            break;
         case KEY_1MIN:
            _ChartSetSymbolPeriod(1);
            break;
         case KEY_CHARTFIX:
           {
            bool isFixed=ChartGetInteger(0,CHART_SCALEFIX,true);
            if(!isFixed)
              {
               ChartSetInteger(0,CHART_SCALEFIX,true);
              }
            else
              {
               ChartSetInteger(0,CHART_SCALEFIX,false);
              }
           }
         break;
         case KEY_P:
           {
            bool isFixed=ChartGetInteger(0,CHART_SHOW_PRICE_SCALE,true);
            if(!isFixed)
              {
               ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,true);
              }
            else
              {
               ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,false);
              }
           }
         break;
         case KEY_MODE:
           {
            GlobalVariableSet(ALL_CHARTS_GLOB_VAR, !GlobalVariableGet(ALL_CHARTS_GLOB_VAR));
           }
         break;
        }
      ChartRedraw();
     }
  }
//+------------------------------------------------------------------+
 

Hey guys

I modified the code for MT5

//+------------------------------------------------------------------+
//|                                                     hotkey01.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
//void OnStart()
  //{
//---
   
  //}
//+------------------------------------------------------------------+
#property description   "The indicator will change the timeframe of the chart with key press"
#property description   "1 - M1, 2 - M5, 3 - M15, 4 - M30, 5 - H1, 6 - H4, 7 - D1, 8 - W1, 9 - MN"
#property description   "By Vahid Tavakoli and Hashem Moradmand"

#property indicator_chart_window

#define KEY_MONTHLY '9'
#define KEY_WEEKLY '8'
#define KEY_DAILY '7'
#define KEY_4HOUR '6'
#define KEY_1HOUR '5'
#define KEY_30MIN '4'
#define KEY_15MIN '3'
#define KEY_5MIN '2'
#define KEY_1MIN '1' //

#define KEY_CHARTFIX 48
#define KEY_P 80

//+------------------------------------------------------------------+
// Custom indicator initialization function
//+------------------------------------------------------------------+
int OnStart()
{
return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
        const int prev_calculated,
        const datetime &time[],
        const double &open[],
        const double &high[],
        const double &low[],
        const double &close[],
        const long &tick_volume[],
        const long &volume[],
        const int &spread[])
{
return(rates_total); 
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+

void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//printf(char(id));
if(id==CHARTEVENT_KEYDOWN)
        {
        switch(int(lparam))
                {
                case KEY_MONTHLY:ChartSetSymbolPeriod(0,NULL,PERIOD_MN1);
                break;
                case KEY_WEEKLY:ChartSetSymbolPeriod(0,NULL,PERIOD_W1);
                break;
                case KEY_DAILY:ChartSetSymbolPeriod(0,NULL,PERIOD_D1);
                break;
                case KEY_4HOUR:ChartSetSymbolPeriod(0,NULL,PERIOD_H4);
                break;
                case KEY_1HOUR:ChartSetSymbolPeriod(0,NULL,PERIOD_H1);
                break;
                case KEY_30MIN:ChartSetSymbolPeriod(0,NULL,PERIOD_M30);
                break;
                case KEY_15MIN:ChartSetSymbolPeriod(0,NULL,PERIOD_M15);
                break;
                case KEY_5MIN:ChartSetSymbolPeriod(0,NULL,PERIOD_M5);
                break;
                case KEY_1MIN:ChartSetSymbolPeriod(0,NULL,PERIOD_M1);
                break;
                case KEY_CHARTFIX:
                        {
                        bool isFixed=ChartGetInteger(0,CHART_SCALEFIX,true);
                        if(!isFixed)
                                {
                                ChartSetInteger(0,CHART_SCALEFIX,true);
                                }
                        else
                                {
                                ChartSetInteger(0,CHART_SCALEFIX,false);
                                }
                        }
                break;
                case KEY_P:
                        {
                        bool isFixed=ChartGetInteger(0,CHART_SHOW_PRICE_SCALE,true);
                        if(!isFixed)
                                {
                                ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,true);
                                }
                        else
                                {
                                ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,false);
                                }
                        }
                break;
                }
        ChartRedraw();
        }
}
 
Your code
bool isFixed=ChartGetInteger(0,CHART_SHOW_PRICE_SCALE,true);
  if(!isFixed)
          {
          ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,true);
          }
  else
          {
          ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,false);
          }
  }
Simplified
bool isFixed=ChartGetInteger(0,CHART_SHOW_PRICE_SCALE,true);
ChartSetInteger(0,CHART_SHOW_PRICE_SCALE,!isFixed);