How to get the font size in dollars

as the function plottext the para y - is y-coordinate in dollars

I want to calculate the height of the font in dollers , in order to put the second line, will not cover the first line

which function i can get the font high in dollers

This is not the only possibility. Y co-ordinate in PlotText() can be expressed in dollars (price), but it can also be expressed in screen pixels. The same applies to X co-ordinate (Bar index, or pixels). Additionally bar/price co-ordinates can be fractional (for the greater precision). You can also use mixed modes. Read here:

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

Besides in AFL there are more possibilities of plotting/drawing text:

  1. PlotText() and PlotTextSetFont()
    AFL Function Reference - PLOTTEXT
    AFL Function Reference - PLOTTEXTSETFONT
  1. GfxTextOut()
    AFL Function Reference - GFXTEXTOUT

  2. GfxDrawText()
    AFL Function Reference - GFXDRAWTEXT

You should consider which way of plotting/drawing text is the best option in your case, because for example if you want to draw the text in some cell / rectangle and be able to format it, align, break the text into lines - like in the example below, you might use GfxDrawText() which takes care of all of those things automatically.

Text

4 Likes

I'm afraid I have to correct my previous post. GfxSetCoordsMode() allows to switch co-ordinate system for low-level gfx functions only. PlotText() of course doesn't belong to gfx functions. So yes - in this case X coordinates are expressed in bars and y coordinates in dollars (price). But still, for the greater precision, co-ordinates can be fractional.

Recently I've been using GFX functions a lot, along with GfxSetCoordsMode() - that's the reason for my confusion. Sorry for that :wink:

4 Likes

in my case want to do like this

Amibroker0005

and my code is

PlotText( "" + LowPoint[i] , i , L[i] - 0.8 , colorGreen ) ;
PlotText( "" + DownLevel , i , L[i] - 1.6 , colorGreen ) ; 
PlotText( "" + DownLevel1 , i , L[i] - 2.4 , colorGreen ) ;

and How to calculate font height in dollors to fix those fixed values 0.8 1.6 2.4

You do not need to do such complication because PlotText and PlotTextSetFont function do have an y-offset argument. And the distance keeps the same no matter which price value and symbol.

Plot( C, "Price", colorDefault, styleCandle );

yoff = 20; // y-offset for PlotText
fntsize = 9;// fontsize of text of PlotText

bi = Barindex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
for( i = fvb; i <= lvb; i++ ) {
	PlotText( "" + 1, i, L[i], colorRed, -1, -yoff );
	PlotText( "" + 2 , i, L[i], colorRed, -1, -2*yoff ); 
	PlotText( "" + 3 , i, L[i], colorRed, -1, -3*yoff );	
	
	PlotText( "" + 1, i, H[i], colorGreen, -1, yoff-fntsize );
	PlotText( "" + 2 , i, H[i], colorGreen, -1, 2*yoff-fntsize ); 
	PlotText( "" + 3 , i, h[i], colorGreen, -1, 3*yoff-fntsize );
}

244

5 Likes

that is good for me ,

However, I still have a little problem because PlotTextsetFont
The fontsize is set to point, but Y offset is in pixels, how the two are converted, or both refer to the same thing

Or how do I get fontsize in pixel

Then convert point to pixel if that makes you happy.

dpi = 96;
pixel = point * dpi / 72;
6 Likes

Thank you for solving my problem