Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Formatting Digits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Formatting Digits

    I have a Range predictor for Range Bars that calculates the projected high and low prices correctly, but I don't know how to get it to print a decimal place when the price is a whole number , 731.0 as opposed to 731.

    if(showValues)
    {
    DrawText("HighValue", true, " . " + (Low[0]+(1*TickSize)+ Bars.Period.Value*TickSize), 0, Low[0]+(10*TickSize)+ (Bars.Period.Value*TickSize) , 2, Color.White, new Font("Arial", 9), StringAlignment.Near, Color.White, Color.Black, 10);
    }
    Attached Files

    #2
    Originally posted by ThatManFromTexas View Post
    I have a Range predictor for Range Bars that calculates the projected high and low prices correctly, but I don't know how to get it to print a decimal place when the price is a whole number , 731.0 as opposed to 731.

    if(showValues)
    {
    DrawText("HighValue", true, " . " + (Low[0]+(1*TickSize)+ Bars.Period.Value*TickSize), 0, Low[0]+(10*TickSize)+ (Bars.Period.Value*TickSize) , 2, Color.White, new Font("Arial", 9), StringAlignment.Near, Color.White, Color.Black, 10);
    }
    Perhaps you can use the " .ToString("0.00") " format, as in the following example:

    Code:
    [FONT=Consolas][SIZE=2][COLOR=#f3f3f3][FONT=Consolas][SIZE=2][COLOR=#f3f3f3][FONT=Consolas][SIZE=2][COLOR=#f3f3f3][COLOR=black]Print[B]([/B]Time[B][[/B]0[B]][/B].ToString[B]() [/B]+[/COLOR][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][COLOR=black][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]"Closing price with a lot of decimals: "[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]+Close[B][[/B]0[B]][/B].ToString[B]([/B][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/COLOR][COLOR=black][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]"0.00000000"[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][B][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]));[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/B][/COLOR][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
    [/SIZE][/FONT][/SIZE][/FONT]
    which results in:
    Code:
    17-12-2008 12:45:00Closing price with a lot of decimals: 2434,70000000
    ( so it's .7000000 instead of .7 ). Off course, such a number of zero's is absurd, so ToString("0.00") woud be more than sufficient.

    Regards,

    Comment


      #3
      Thanks!

      Originally posted by J_o_s View Post
      Perhaps you can use the " .ToString("0.00") " format, as in the following example:

      Code:
      [FONT=Consolas][SIZE=2][COLOR=#f3f3f3][FONT=Consolas][SIZE=2][COLOR=#f3f3f3][FONT=Consolas][SIZE=2][COLOR=#f3f3f3][COLOR=black]Print[B]([/B]Time[B][[/B]0[B]][/B].ToString[B]() [/B]+[/COLOR][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][COLOR=black][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]"Closing price with a lot of decimals: "[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]+Close[B][[/B]0[B]][/B].ToString[B]([/B][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/COLOR][COLOR=black][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]"0.00000000"[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][B][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]));[/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/B][/COLOR][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]
      [/SIZE][/FONT][/SIZE][/FONT]
      which results in:
      Code:
      17-12-2008 12:45:00Closing price with a lot of decimals: 2434,70000000
      ( so it's .7000000 instead of .7 ). Off course, such a number of zero's is absurd, so ToString("0.00") woud be more than sufficient.

      Regards,
      Thanks, That worked!

      Code:
      DrawText("HighValue", true, "     " +  (Low[0]+(1*TickSize)+ Bars.Period.Value*TickSize)[B].ToString("0.0")[/B], 0, Low[0]+(Ticks*TickSize)+ (Bars.Period.Value*TickSize) , 2, Color.White, new Font("Arial", 9), StringAlignment.Center, Color.White, Color.Black, 10);

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by funk10101, Today, 09:43 PM
      0 responses
      3 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      36 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Started by yertle, Today, 08:38 AM
      6 responses
      26 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Started by algospoke, Yesterday, 06:40 PM
      2 responses
      24 views
      0 likes
      Last Post algospoke  
      Working...
      X