DownloadRequesting debugging help for MT5 hotkey symbol changer

1
I have very limited knowledge of MQL5 but I've been trying to code a hotkey symbol changer because I haven't found any free options available online:

Code: Select all

//+------------------------------------------------------------------+
//|                                     keystroke_symbol_changer.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
//--- input parameters
input string   NextSymbolKey="KEY_RIGHT";
input string   PrevSymbolKey="KEY_LEFT";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
#define KEY_LEFT           37
#define KEY_RIGHT          39

int symbolIndex = 0;

int OnInit()
  {
 
    ChartSetInteger(ChartID(), CHART_EVENT_OBJECT_CREATE, true);
    ChartSetInteger(ChartID(), CHART_EVENT_OBJECT_DELETE, true);
    int total = SymbolsTotal(false); // Get the total number of symbols
    ArrayResize(symbols, total); // Resize the array to fit all symbols
    for(int i = 0; i < total; i++)
    {
        symbols[i] = SymbolName(i, false); // Get the name of the symbol and store it in the array
    }

    ChartRedraw();
    return(INIT_SUCCEEDED);
  }
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 OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_KEYDOWN){
    switch(lparam)
        {
            case KEY_RIGHT:
               {
                symbolIndex++; 
                string nextSymbol = symbols[symbolIndex]; 
                ChartSetSymbolPeriod(0, nextSymbol, PERIOD_D1); 
                break;
                }
            case KEY_LEFT:
                {
                symbolIndex--; 
                string prevSymbol = symbols[symbolIndex]; // Get the previous symbol
                ChartSetSymbolPeriod(0, prevSymbol, PERIOD_D1); // Change the symbol of the chart
                break;
                }
            default:
                Print("Some not listed key has been pressed");
        }
    ChartRedraw();
   }
  }
  
I have attached the errors that I am getting in the compiler. Any help would be appreciated.


Re: Requesting debugging help for MT5 hotkey symbol changer

2
HI. I can't help you with the code because I'm just learning this language.
I saw that no one has helped you yet and I would like to pass this video to you https://www.youtube.com/watch?v=v0RBnwdJ604 . I hope it helps to understand better
Minor bugs are fixed without updating the changelog and new replies. Check back from time to time for new minor releases. Thanks

All feedback is welcome, though never obligatory. What matters most is that you’re satisfied with my work.