Page 1 of 1

How to get less digits showing on chart

PostPosted: Sun Jun 27, 2010 11:54 am
by LordTwig
Hiya, can you tell me how to get less digits showing on chart when using "createtext"

There are about 15 digits behind the decimal, I want to only show eg 28 or 28.1 only, not the 28.967869584533333 that I am getting.

here is some of code that I am using for your guess at what I can do.

Profitdown = instance:createTextOutput ("Down", "Down", "PFdown", 10, core.H_Right, core.V_Bottom, instance.parameters.Normal_color, 0);

PFdown = low - close;
if PFdown > 0 then
Profitdown:set(period, source.median[period - 2], PFdown);
end

Tah
LordTwig

Re: How to get less digits showing on chart

PostPosted: Mon Jun 28, 2010 10:53 am
by Nikolay.Gekht
use string.format lua function. e.g, for example:
string.format("%.2f", value);

Re: How to get less digits showing on chart

PostPosted: Tue Jun 29, 2010 6:32 am
by LordTwig
Sorry, :( need more info, how and where do I place this "string.format("%.2f", value);" cannot find any examples here in forum, (I will look at other indicators to see if I find it)

Can you give a working example on it, in context to displaying with "createTextOutput" as none in SDK user guide, hmmm user guide does lack working examples in all aspects, maybe someone will attend to that....

It's funny :) how everyone assumes we are all programers here in this forum.

Cheers
LordTwig

Re: How to get less digits showing on chart

PostPosted: Tue Jun 29, 2010 8:37 am
by Nikolay.Gekht
The third parameter of the set method is a string. You placed a number, so, lua converted it "by default", with a maximum precision (as if you put tostring(PFdown)). To convert with the desired precision just use string.format instead of implicit tostring call. .2 is desired precision. If you want to have 4 digits - use string.format("%.4f", PFdown).

Code: Select all
Profitdown:set(period, source.median[period - 2], string.format("%.2f", PFdown));

Re: How to get less digits showing on chart

PostPosted: Tue Jun 29, 2010 9:34 am
by LordTwig
Thanks
LordTwig

Re: How to get less digits showing on chart

PostPosted: Thu Jul 01, 2010 8:14 am
by LordTwig
Hi Nikolay,
I am having problems in getting the 'createTextOutput' value to be at the ends of the bars in an 'Oscillator'. I have tried all manner of things but values seem to be quite fixed in one area. using core.V-Top, Centre, Bottom only moves value a couple of mm either way.(cm's away from ends of bars, and never below the negative line. Using "/010" does not create a line gap either. Using source.high[period] or source.low[period] has no affect either.

I was trying to get it to display value at either the top of oscillator bar and or at bottom of ocillator bar when it is negative (I have addlevels of +4, +3, +2, +1, 0, -1, -2, -3, -4)

I got a feeling 'createTextOutputsetup' is setup to be used more on charts than ocillator. (or I am missing something.(assigning values at the top or bottom of a 'candle' only)

Can you look at it and maybe do a simple demo positioning a value (high) at top (+) of ocillator bar and a value (low) at bottom (-)of oscillator bar. So (A) it is possible!..... and (B) so I can see what I am doing wrong.

Regards
LordTwig (yeah still progressing with pivot indicator 1200 lines and growing)

Re: How to get less digits showing on chart

PostPosted: Thu Jul 01, 2010 2:37 pm
by Nikolay.Gekht
Send me your source, please. It will be much easier for me to get the problem if I am be able to run it. You can sent it directly to my email: nikolay(dot)gekht(at)gehtsoftusa(dot)com.

Re: How to get less digits showing on chart

PostPosted: Fri Jul 09, 2010 12:57 pm
by LordTwig
Sorry for delay, just emailed you source.
Cheers
LordTwig