Chart Title Modification

I just learn how to make a title with only date, time and candle timer.

>_SECTION_BEGIN("Time Left");
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();
SecsLeft	= SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo	= TimeFrame - SecsLeft;

Title = "{{DATE}}" + "    " +NumToStr( SecsToGo, 1.0, False ) + " / " + NumToStr( TimeFrame, 1.0 );
_SECTION_END();

Result:

as1

I'm very please with the result, but then i found out when minimize the chart some of the title being cut:

as2

I search solution for this and a lot of them using this code:

`pxwidth = ` `Status` `(` `"pxwidth"` `);`
`pxheight = ` `Status` `(` `"pxheight"` `);`
`GfxSetBkMode`
`GfxSelectFont`
`GfxSetTextColor`
`GfxSetTextAlign`

I try some of them and put it on my formula, but i can't get the logic on using it. A lot of them showing fancy ribbon. I just want to make a simple fill background for my title.

Did I read wrong code that i must use?
Did i gone to far looking those ribbon?
Is there a simple code fill Title background and not missing while chart width being minimize?

Can someone help me?

Thank You.

https://www.amibroker.com/guide/afl/setchartoptions.html

chartWrapTitle you can use this Flag to wrap the title and prevent being "cut" or truncated at the right edge of chart.

You can also use new line in you string if you want to format yourself.

str = "My first line" + "\n" + "My second line";
// \n will indicate newline

Another good example of color is to encode it like shown here

https://www.amibroker.com/guide/afl/encodecolor.html

Title = "This is written in " + EncodeColor( colorViolet ) + "violet color " 
        + EncodeColor( colorGreen ) + "and this in green";
3 Likes

Wow fast replay @travick tnx, i will try it and update about it soon. Appreciate it.

@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)

1 Like

New update

@travick

  1. I already Used these function before
    "\n"
    and not like it to much, becoz the length of the title while minimize is just right not until the right price line cut it like the picture show

    as2
    and for:
    chartWarpTitle is good but almost the same with "\n"; having second line

  2. For Encodecolor i just understand it as changing Text color for title, and don't know how to use it for those text backgroud color????

Back to my earlier question:

  1. Make title have a background color
  2. Make title not cut by right price line, and cut only by edge of the chart.

I really confuse which code i must use to do it. :disappointed_relieved:

What in my imagination is like :

title

Edit by photoshop LOL

Generally, there are two approaches one can take but everything depends on your Level of proficiency.
What I mean is you can't keep repeating you are relatively new to AFL and then suddenly start describing an advanced concept.

Sometimes, if you are learning its a different thing, but if it isn't worth the time, use a faster approach and move on.
For the level of customization you are talking about, you can use GFX functions.
Read the manual, understand all the approaches and then do it.

You can do it with GFX, and detect the length of string and adjust the wrapping on your own.

Search the forum if you can get closer examples.

Plottext() has an option for Background-Color but I don't think it will wrap the way you want.

1 Like

First @fxshrat, your are wrong. My base code i got is from:
https://www.inditraders.com/amibroker/2955-countdown-timer.html

And what i put here is what i use after tweaking it, as i start to understand the logic of their formula. And found what i need for my project:
project

So do i need to include my basecode source before i tweak it here?
If yes then i'll do it now and then.

@travick Thanks, indeed i'm still newbie. I don't know which are advance or simple coding. My approach of learning my self is by looking others made coding and learn what i need after try to understand it and if i'm stuck i go to this forum.

Like my project here:

project

Those title text color will not be there without your info @travick
Those MACD 3 colors before become ribbon like now r your info @travick and @beppe

Others i learn it my self, using made coding and tweek it. If my way is wrong then sorry.

1 Like

Don't make me getting annoyed. A guy being total beginner and telling me I am wrong. I am not wrong.
The site I posted above is original creator website of that code. It is site being part of AMIBROKER.COM!

It takes just few seconds to look up source of your posted code of post #1 or any code at google (well that code you posted I didn't even need to look up since it is known to me for years). Of course copy&pasting is easier and quicker than taking the time respecting actual code authors.

If you come here then you better start reading here and here first.

It is matter of respect to post original reference.
Do we understand each other?


And that Indian site you posted is just another copy&paste artistry site (nothing more nothing less).

BTW, since you come from that indian traders website... do you use cracked AmiBroker (which AB version do you use actually?) or which one?

3 Likes

@fxshrat You are not wrong if u see it from the original creator, I'm using other web as my basecode source. Nothing to discuss about it.

I know I'm newbie, i just want to have learning environment as i just use amibroker.

I try amibroker just recently as my trial using to amibroker for charting. And i use Free version amibroker to explore possibility on charting.

And the coding i use already tweak not the original one, from my understanding if i copy paste and use it as per original i need to include the source. Looks like I'm wrong.

I understand smart people get easily annoyed by newbie. And i'm sorry for that.
English is not my main language and AFL coding is a new things for me also.

By the way Amibroker is very interesting may be next month i'll start using the paid version to combine with my IB account.

@Fxshart Sorry, not mean to annoyed you and thanks for the information.

1 Like

Coding Source:
GFx Guide from http://www.amibroker.com/guide/h_lowlevelgfx.html
GFx Sample from Title Font Size
Timeleft Sample from http://www.amibroker.org/userkb/2008/02/18/real-time-bar-period-timing-2/

I finally made it and really it's fun to learn new things.

Capture

Title = "MyTitle";

_SECTION_BEGIN("Time Left");
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();
SecsLeft	= SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo	= TimeFrame - SecsLeft;

//
{
_N( MyTitle = DateTimeToStr(SelectedValue(DateTime()))  + "    " +NumToStr( SecsToGo, 1.0, False ) + " / " + NumToStr( TimeFrame, 1.0 ));
	
	GfxSetBkMode( 2 );
	GfxSetTextAlign( 0 | 0 );
	GfxSetBkColor( colorBlue );
	GfxSetTextColor( colorWhite);
	GfxSelectFont( "Arial", 9, 700, 0, 0, 0 );
	GfxTextOut( MyTitle, 0, 0 );
}

_SECTION_END();

I would to say thanks to @fxshrat and @travick. Without you guys, it wouldn't be possible.

If there are mistake in my coding feel free to comment, Appreciate it.

2 Likes