Correct the following programming errors

 

Code for switching between continuous time frames (indicator or script) Code to switch from the M1 time frame to the M5 time frame and then back to the M1 time frame again, and so on constantly. Meaning Every minute, the indicator or script switches the chart from the M1 time frame to the M5 time frame and then back to the M1 time frame.

With every minute, the indicator or script switches the chart from the M1 time frame to the M5 time frame and then back to the M1 time frame.

//+------------------------------------------------------------------+
//|                                                      TimeSwitcher|
//|                                              Copyright 2024, YourCompany|
//|                                       https://www.yourcompany.com|
//+------------------------------------------------------------------+
#property strict

input ENUM_TIMEFRAMES TimeFrames[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_H1}; // Define the time frames to switch between

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1); // Start the timer
   return INIT_SUCCEEDED;
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer(); // Stop the timer
  }
//+------------------------------------------------------------------+
//| Expert tick function                                            |
//+------------------------------------------------------------------+
void OnTimer()
  {
   static int currentTF = 0;
   
   if(currentTF >= ArraySize(TimeFrames))
      currentTF = 0;
   
   ChartSetInteger(0, CHART_FOREGROUND,true); // Ensure the chart is in foreground
   PeriodSet(TimeFrames[currentTF]); // Switch to the next time frame
   currentTF++; // Move to the next time frame for the next switch
  }
//+------------------------------------------------------------------+
رمز للتبديل بين الأطر الزمنية المستمرة (المؤشر أو البرنامج النصي) رمز للتبديل من الإطار الزمني M1 إلى الإطار الزمني M5 ثم العودة إلى الإطار الزمني M1 مرة أخرى، وهكذا باستمرار. بمعنى أنه في كل دقيقة، يقوم المؤشر أو البرنامج النصي بتبديل الرسم البياني من الإطار الزمني M1 إلى الإطار الزمني M5 ثم يعود إلى الإطار الزمني M1. مع كل دقيقة، يقوم المؤشر أو البرنامج النصي بتبديل الرسم البياني من الإطار الزمني M1 إلى الإطار الزمني M5 ثم العودة إلى الإطار الزمني M1.
Files:
1712754950020.jpg  3663 kb
1712754950004.jpg  3500 kb
 
Lwy Bydh:

Code for switching between continuous time frames (indicator or script) Code to switch from the M1 time frame to the M5 time frame and then back to the M1 time frame again, and so on constantly. Meaning Every minute, the indicator or script switches the chart from the M1 time frame to the M5 time frame and then back to the M1 time frame.

With every minute, the indicator or script switches the chart from the M1 time frame to the M5 time frame and then back to the M1 time frame.

Your code is not correct, you need the adjustment to switch between the M1 and M5 timeframes every minute continuously/

Do not use Chat GPT to code for you, i can see this code was not hand written, you will not learn like this and your code will have mistakes with the syntax. Learn to code!!

We will help you if you have shown efforts to code it yourself, but we will not correct mistakes made by AI

 
Your code tries to switch every second, not every minute.