NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 05-31-2010, 07:06 AM   #1
williammanda
Member
 
Join Date: Jan 2009
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default Show more than 2 decimal places

Hello
I'm at a very early stage of learning NT script. I was able to find an indicator that I could modify and everything works except for one issue. The price will only show up to two decimals places and I need four. I'm referring to the price label and the scale (only showing 1.7 now, it needs to be 1.700, please see the "2 decimal" attachment). I only had to change the mathematical equation, no variables were added or changed. Also I have attached the modified indicator "Marketsentiment" which was taken from the "Spread" indicator. This is the line that I modified:

Code:
Value.Set((Instrument2Close[0] / (Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2)) / (Closes[Instrument1][0] / (Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2)));
This was the original line:

Code:
//Value.Set(Closes[Instrument1][0] * mul1 + Instrument2Close[0] * mul2);    // set output using synchronized data series
In years past declaring a variable type "real" would set it up to show decimal places but I don't see any declaration of that type. I using NT 7 beta 16. Any help would be apprecaited.
Thanks
Attached Images
File Type: png 2 decimal places.png (10.4 KB, 21 views)
Attached Files
File Type: cs MarketSentiment.cs (25.4 KB, 6 views)
williammanda is offline  
Reply With Quote
Old 05-31-2010, 07:18 AM   #2
williammanda
Member
 
Join Date: Jan 2009
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default

I found this:

Code:
public override string FormatPriceMarker(double price)
        {
            // Formats price values to 4 decimal places
            return price.ToString("N4");
        }
Will just inserting this do it? Or do I need to tie it to a variable?
williammanda is offline  
Reply With Quote
Old 05-31-2010, 08:25 AM   #3
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Yes, this should do the job for you, for example this SMA below would show 4 digits as well -

Code:
 
protectedoverridevoid OnBarUpdate()
{
Value.Set(SMA(20)[0]);
}
 
publicoverridestring FormatPriceMarker(double price)
 
{
// Formats price values to 4 decimal places
return price.ToString("N4");
}
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-31-2010, 10:05 AM   #4
williammanda
Member
 
Join Date: Jan 2009
Posts: 96
Thanks: 0
Thanked 0 times in 0 posts
Default

That worked!
TY!
williammanda is offline  
Reply With Quote
Old 03-03-2012, 08:22 AM   #5
rabcnesbit
Member
 
Join Date: Aug 2011
Posts: 45
Thanks: 11
Thanked 0 times in 0 posts
Default Atr

Hello,

I am trying to format ATR to 2 decimal places. I tried to use the code supplied by NT_Bertrand below, obviously will amend from 4 decimal to 2 decimals. I copied the code as it is into and NT Script, and got error CS0246, "The type or namespace name publicoverridestring could not be found (are you missing a using directive or an assembly reference?)" .
Referring to the help menu suggested I re-imported a 3rd party dll. I see this code was in reply to a question back in 2010, is this code still applicable to the current version of NT? If it is, then where do I import this 3rd party DLL from, or any other suggestion on a way to go about formatting the decimal places?

Thanks
Dan
rabcnesbit is offline  
Reply With Quote
Old 03-03-2012, 08:44 AM   #6
rabcnesbit
Member
 
Join Date: Aug 2011
Posts: 45
Thanks: 11
Thanked 0 times in 0 posts
Default Atr

Ok, I have come up with the following for what I want, though not sure how it's different from the code posted by NT_Bertrand. Of course, I am still at the very early learning stage of NTScripts and C#

Code:
Value.Set(Math.Round(ATR(14)[0],2));
rabcnesbit is offline  
Reply With Quote
Old 03-05-2012, 02:00 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Glad to hear you found a working solution fro you Dan, could you please post or email me the script you tried setting up with the overridden string example I posted? I would then gladly take a look.
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Snipet: Show to show one Dropdown InstrumentList selectable in chart jatubio General Programming 19 07-31-2012 10:12 AM
NT Strategy places Orders in the past Obi Strategy Development 1 04-08-2009 11:52 AM
TradeStation Reentrancy Error - places orders for wrong symbol Idruna Automated Trading 3 02-12-2009 12:28 PM
Is there a way to see 2 decimal places in SMA? gsmaster Charting 1 05-02-2008 12:25 PM
Finding decimal places sbgtrading General Programming 3 11-25-2007 07:29 PM


All times are GMT -6. The time now is 12:12 AM.