Need help printing 2 superimposed titles on a chart

A normal title at the top left-hand side of a chart might look something like this:

_SECTION_BEGIN( "Price" );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} \nOpen %g \nHigh %g
\nLow %g \nClose %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )
) ) );

I would like to slap another, say an indicator, on top of the price chart which currently has the title above. I would like to have the new title (my indicator title) to start printing in row 1, except that I want the second chart title to start printing, not covering up the first title, but start printing at the column location where the first chart title ends. So let's say in my first title, the last character is at column 120, I want the title of my second chart to start printing at column 122, otherwise, it would cover up the first title in row 1. I don't know how to do this, please help. Thanks.

You just have to place token {{VALUES}} differently.

_SECTION_BEGIN( "Price" );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} {{VALUES}} \nOpen %g \nHigh %g \nLow %g \nClose %g (%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 )) ) );
Plot( C, "", colorDefault, styleBar );
_SECTION_END();

_SECTION_BEGIN( "Indicator" );
Plot( MACD(), "MACD", colorRed, styleOwnScale );
_SECTION_END();

14

What is token {{VALUES}} about?

{{VALUES}} inside Title string will be replaced by automatic-values generated by Plot function calls

http://www.amibroker.com/kb/2015/02/13/customizing-chart-titles/

1 Like

Thank you kindly fxshrat for your comment. The above solution certainly worked. What I want is a little bit more specific (btw, I have read the included customizing-chart-titles link fully, but still cannot find the solution I wanted). I also noticed you didn't include a Title variable in the second section, the "Indicator" section. What I want to see is something like this: the first _SECTION_BEGIN (where the "Title" variable is defined) can be left where it is. In the second section, in the _SECTION_BEGIN area, say I want to prefix the "MACD = -0.63790" with, say, "THIS IS A MACD = -0.63790". Now, here is where the issue starts. If I defined a second Title variable, even when it is inside the _SECTION_BEGIN, _SECTION_END() of the second section, it will still overwrites the first Title area (even if I put a bunch of spaces before the literal MACD). The MACD in the example above worked, because a second Title variable was not defined. Hope I said it clearly enough. Thanks. Thus, I am still looking for a solution.

What for? Post#2 does what you asked for.

And second argument of Plot is plot title and added to Title variable if token is set!

So what's the problem?

_SECTION_BEGIN( "Price" );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} {{VALUES}} \nOpen %g \nHigh %g \nLow %g \nClose %g (%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 )) ) );
Plot( C, "", colorDefault, styleBar );
_SECTION_END();

_SECTION_BEGIN( "Indicator" );
Plot( MACD(), "THIS IS A MACD", colorRed, styleOwnScale );
_SECTION_END();

Why overcomplicating things with second Title variable?

14


Of course it does that if you reassign to Title var like this

Title = ...

Then it will overwrite previous one. It simply behaves like other variables where you would re-assign few lines later.

To not overwrite you may add previous Title via += operator

Title += StrFormat("\nThis is MACD = %g", MACD());

or to prevent Error 29 if there wasn't another Title initialized before

Title = VarGetText("Title") + StrFormat("\nThis is MACD = %g", MACD());

But If you want over-complication with two times Title you may do like this

_SECTION_BEGIN( "Price" );
_N( Title = StrFormat( "\nOpen %g \nHigh %g \nLow %g \nClose %g (%.1f%%)", O, H, L, C, SelectedValue( ROC( C, 1 )) ) );
Plot( C, "", colorDefault, styleBar );
_SECTION_END();

_SECTION_BEGIN( "Indicator" );
indicator = MACD();
_N( Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} This is MACD = %g %s", indicator, VarGetText("Title")));
Plot( indicator, "MACD", colorRed, styleOwnScale );
_SECTION_END();

14

If you want to differ by color in title then you may use EncodeColor() function.


BTW,

Important info missing in 1st post:

"Looking for more complicated way of doing it".

4 Likes

Thank you very much for all your great answers, my apology for asking somewhat of a vague question. I realized I may not have phrased the question correctly. Thanks again.

Hi fxshrat, the solutions you provided for here are great resources for anyone who wants to master the AFL language proficiently. Thank you!