Equity and Cryptocurrency Price Formatting, IIF Then Question

How would I phrase IIF close => 1.00, then 2 decimal places , otherwise use the floating price value from the data vendor rather than specifying a strict number of decimal places and then convert that to a string for output.
//Keep Excel from scientific notation on small numbers by converting to text

Example two symbols:
BLFS is $36.00
CTXC-BTC is $0.000007 //Cryptocurrency
I'm sure there is an easy way in AFL as this get me an error.

customCloseformat = IIF(Close =>  1.00, 8.2 ,8.9);
_Close = Close;
_CloseText = NumToStr(_Close,customCloseformat ,True,False); //customCloseformat  incurs error

AddTextColumn(_CloseText,"CustomCloseDisplay");
Plot(__CloseText,"CustomCloseDisplay",1,64);

I could not figure out how to use the %g format specifier of c in AddColumn() , AddTextColumn(), or Plot() context either.
Thanks in advance

This will display a specific format, but I could figure out the (IIF Close >= 1.00, 1.2, %g) ...
IIF Then format for conversion to NumtoStr.

AddColumn( Close, "Close", format = 1.9, textColor = colorDefault, bkgndColor = colorDefault, width = -1, barchart = Null );

Thanks

For numbers you should always use ONLY AddColumn.

Do NOT use AddTextColumn for numbers!

It is recommended to use fixed format because it really looks ugly if numbers are displayed differently in different rows, but if you must, you can display different number of decimal places per symbol this way:

Filter= 1;
fmt = IIf( LastValue( Close ) < 10, 1.8, 1.2 );
AddColumn( Close, "Close", fmt ); 
2 Likes
Filter= 1;
fmt = IIf( LastValue( Close ) < 1.00, 1.9, 1.2 );
AddColumn( Close, "Close", fmt ); 

TJ,
This works perfect for AddColumn(), Thank you.

How do I convert that format to a variable _Newfmt to display appropriately in a
Plot() statement or insert into an AddTextColumn()
I don't see a format = after Plot(... as with AddColumn().
How do I truncate the variable to display only two digits if >= $1.00, otherwise display decimals without scientific notation. When I put a variable with very small crypto price into an AddTextColumn(), it will occasionally displays scientific notation, which I am trying to avoid.

Thanks in advance.

Plot uses automatic formating. But you can customize entire Title of chart as documented in the manual: Using graph styles, colors and titles in Indicator Builder

TJ,

Thank you. With your help, I believe this does it.

_SECTION_BEGIN("Custom Price Formats");
//Custom Price Formats

Filter= 1;
_RClose = Close;
fmt = IIf( LastValue( Close ) >= 1.00, 1.2, 1.9 );
AddColumn( _RClose, "Close", fmt );
//Plot(_RClose ,"Close",2,1);
_RRClose = NumToStr(_RClose,fmt);

AddTextColumn(_RRClose,"_RRClose");
_SECTION_END();

Thanks again.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.