@Miko2,
Listen... if you copy&paste code not being yours then you better add the source of creation!
The original main code comes from here:
http://www.amibroker.org/userkb/2008/02/18/real-time-bar-period-timing-2/
Just changing the title does not make it your code creation.
So we add link
_SECTION_BEGIN("Time Left");
/// @link http://www.amibroker.org/userkb/2008/02/18/real-time-bar-period-timing-2/
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
// Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
// Edit by Miko or ...
/// @link https://forum.amibroker.com/t/chart-title-modification/11232
Title = "{{DATE}}" + " " +NumToStr( SecsToGo, 1.0, False ) + " / " + NumToStr( TimeFrame, 1.0 );
_SECTION_END();
Now, here comes the thing...
That upper code has not been required anymore for many years! It is old and outdated.
All that is needed is inbuilt Status function with status code "lastbartimeleft"
"lastbartimeleft" - returns number of seconds to the completion of current last bar. Works for time-based bars only. Note that for proper operation this requires database timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)
So "new" code doing the "same" thing as upper code is following one (and it is just a one-liner to get SecToGo result):
_SECTION_BEGIN("Time Left");
/// Replacement of outdated code from here
/// @link http://www.amibroker.org/userkb/2008/02/18/real-time-bar-period-timing-2/
// not required for real-time plugins, charts are refreshed by plugin
// RequestTimedRefresh(1);
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
/// read carefully here
/// @link https://www.amibroker.com/guide/afl/status.html
SecsToGo = Status( "lastbartimeleft" );
// Title output changed using formatting
Title = StrFormat("{{DATE}} %g / %g", SecsToGo, Interval());
_SECTION_END();
Difference between both codes:
If bar is not up to date anymore then the Status(..) code will show negative value.
As for realtime plugins there is another Status code:
"lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). Also added Status("lastrtupdate") - time of last RT stream update Depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. Note that most data sources send weird (not current) datetime stamps on weekends. Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)