MT4 Offline chart candle countdown

 

Is there an indicator or some way to install an offline chart on MT4, that will accurately countdown remaining time on the candle time frame selected?

Seems the ones I found, cannot count, for example a M2 time frame, or other non-normal time frame offered by MT4.

 
Stan Bland:

Is there an indicator or some way to install an offline chart on MT4, that will accurately countdown remaining time on the candle time frame selected?

Seems the ones I found, cannot count, for example a M2 time frame, or other non-normal time frame offered by MT4.

You can try this custom indicator in MT4. Code attached for reference.

It should display a countdown (in seconds) until the next candle for any custom timeframe (for example, M2 when you set CustomPeriodMinutes to 2)
//+------------------------------------------------------------------+
//|                                             CustomCountdown.mq4  |
//|                    Custom countdown timer for any timeframe      |
//+------------------------------------------------------------------+
#property indicator_chart_window

extern int CustomPeriodMinutes = 2; // Custom period in minutes

//+------------------------------------------------------------------+
//| CustomCountdown Initialization                                   |
//+------------------------------------------------------------------+
int init()
{
   // No indicator buffers needed
   return(0);
}

//+------------------------------------------------------------------+
//| CustomCountdown Deinitialization                                 |
//+------------------------------------------------------------------+
int deinit()
{
   // Clear the chart comment when the indicator is removed
   Comment("");
   return(0);
}

//+------------------------------------------------------------------+
//| CustomCountdown Start Function                                   |
//+------------------------------------------------------------------+
int start()
{
   // Get the current server time
   datetime currentTime = TimeCurrent();
   // Convert the custom period to seconds (e.g., 2 minutes = 120 seconds)
   int periodSeconds = CustomPeriodMinutes * 60;
   
   // Determine the start of the current candle by rounding down
   datetime candleStart = (currentTime / periodSeconds) * periodSeconds;
   // The candle ends at candleStart plus the period length
   datetime candleEnd = candleStart + periodSeconds;
   
   // Calculate the remaining time (in seconds) until the next candle begins
   int timeRemaining = candleEnd - currentTime;
   
   // Create and display the countdown text on the chart
   string countdownText = "Time remaining: " + timeRemaining + " sec";
   Comment(countdownText);
   
   return(0);
}
 
Why did you post your MT4 question in the General section (a miscellaneous catch-all category) instead of the MQL4 section, (bottom of the Root page)?
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
moved to MQL4 and MetaTrader 4
 
William Roeder #:
Why did you post your MT4 question in the General section (a miscellaneous catch-all category) instead of the MQL4 section, (bottom of the Root page)?
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
moved to MQL4 and MetaTrader 4
I'm sorry. My over site, as I didn't notice. I will pay more attention next time.
 
Sivakumar Paul Suyambu #:

You can try this custom indicator in MT4. Code attached for reference.

It should display a countdown (in seconds) until the next candle for any custom timeframe (for example, M2 when you set CustomPeriodMinutes to 2)

This is what I am looking for. Thank you. Is there a way to change which corner it is in, and font size/color?