
#property strict
#property description "Hotkeys left,right To Cycle Through Market Watch Symbols."
#property description "Hotkeys up, down To Switch Timeframes."
#property indicator_chart_window
int NumSymbols=0;
string StringSymbolList[];
//+------------------------------------------------------------------+
int OnInit()
  {
   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)
  {
//---

  string Up_Key_Value;
   string Down_Key_Value;
   int enum_timeframes[]={1,5,15,30,60,240,1440,10080,43200};
   int p = Period();
   int i = ArrayBsearch(enum_timeframes,p);

   StringToUpper(Up_Key_Value);
   StringToUpper(Down_Key_Value);
   
   switch(id) 
     {
      case CHARTEVENT_KEYDOWN:
         if(38==lparam)
           {
            if(_Period<42300)
              {
               ChartSetSymbolPeriod(0,NULL,enum_timeframes[++i]);
              }
           }
         if(40==lparam)
           {
            if(_Period>1)
              {
               ChartSetSymbolPeriod(0,NULL,enum_timeframes[--i]);
              }
           }
     }
     
     
   if(id==CHARTEVENT_KEYDOWN)
     {
      //if want to change default hotkeys for next and previous symbol in market watch
      //use this website to find keycode https://keycode.info
      //https://keycode.info
      switch(int(lparam))
        {
         case 37://keycode for previous market watch symbol
            PrevSymbol();
            break;
         case 39://keycode for next market watch symbol
            NextSymbol();
            break;
        }
      ChartRedraw();
     }
  }
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
void NextSymbol()
  {
   int currentIndex;
   GetSymbols();
   currentIndex=GetIndex();
   currentIndex++;

   if(currentIndex>=NumSymbols)
     {
      ChartSetSymbolPeriod(0,StringSymbolList[0],0);
     }
   else
     {
      ChartSetSymbolPeriod(0,StringSymbolList[currentIndex],0);
     }
  }
//+------------------------------------------------------------------+
void PrevSymbol()
  {
   int currentIndex;
   GetSymbols();
   currentIndex=GetIndex();
   currentIndex--;

   if(currentIndex<0)
     {
      currentIndex=NumSymbols-1;
      ChartSetSymbolPeriod(0,StringSymbolList[currentIndex],0);
     }
   else
     {
      ChartSetSymbolPeriod(0,StringSymbolList[currentIndex],0);
     }
  }
//+------------------------------------------------------------------+
void GetSymbols()
  {
   int numSymbolsMarketWatch=SymbolsTotal(true);
   NumSymbols=numSymbolsMarketWatch;
   ArrayResize(StringSymbolList,numSymbolsMarketWatch);
   for(int i=0; i<numSymbolsMarketWatch; i++)
     {
      StringSymbolList[i]=SymbolName(i,true);
     }
  }
//+------------------------------------------------------------------+
int GetIndex()
  {
   int index=0;
   for(int i=0; i<NumSymbols; i++)
     {
      if(_Symbol==StringSymbolList[i])
        {
         index=i;
         break;
        }
     }
   return index;
  }
//+------------------------------------------------------------------+
