How to get less digits showing on chart

Moderator: admin

How to get less digits showing on chart

Postby LordTwig » Sun Jun 27, 2010 11:54 am

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
Cheers
LordTwig
LordTwig
FXCodeBase: Confirmed User
 
Posts: 157
Joined: Fri Mar 12, 2010 3:15 am

Re: How to get less digits showing on chart

Postby Nikolay.Gekht » Mon Jun 28, 2010 10:53 am

use string.format lua function. e.g, for example:
string.format("%.2f", value);
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: How to get less digits showing on chart

Postby LordTwig » Tue Jun 29, 2010 6:32 am

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
Cheers
LordTwig
LordTwig
FXCodeBase: Confirmed User
 
Posts: 157
Joined: Fri Mar 12, 2010 3:15 am

Re: How to get less digits showing on chart

Postby Nikolay.Gekht » Tue Jun 29, 2010 8:37 am

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));
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: How to get less digits showing on chart

Postby LordTwig » Tue Jun 29, 2010 9:34 am

Thanks
LordTwig
Cheers
LordTwig
LordTwig
FXCodeBase: Confirmed User
 
Posts: 157
Joined: Fri Mar 12, 2010 3:15 am

Re: How to get less digits showing on chart

Postby LordTwig » Thu Jul 01, 2010 8:14 am

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)
Cheers
LordTwig
LordTwig
FXCodeBase: Confirmed User
 
Posts: 157
Joined: Fri Mar 12, 2010 3:15 am

Re: How to get less digits showing on chart

Postby Nikolay.Gekht » Thu Jul 01, 2010 2:37 pm

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.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: How to get less digits showing on chart

Postby LordTwig » Fri Jul 09, 2010 12:57 pm

Sorry for delay, just emailed you source.
Cheers
LordTwig
Cheers
LordTwig
LordTwig
FXCodeBase: Confirmed User
 
Posts: 157
Joined: Fri Mar 12, 2010 3:15 am


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 8 guests