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

RoundToTickSize

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

    RoundToTickSize

    Hi, I am trying to use this command but can't figure out how to do it correctly. NT8 Help Guide says only "NEEDS EXAMPLE" . I am trying to limit the decimals in my Ninjascript output table and wanted to use this command. Any idea how to accomplish that? Thank you so much

    #2
    Hello JBU1314,

    Do you have a link to the help guide page that has the text needs example?

    Are you trying to print to the output window?
    (New -> Output Window)

    (myDouble.ToString())
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      Thanks for the feedback, I tying to print to output window.
      (myDouble.ToString()) - I put this in front of my code I want to print?

      Somehow I cant get the full link but it is easy to find:
      NT8 Helpguide - Ninjascript - Alphabetical Reference - R - RoundToTickSize

      Comment


        #4
        Hello JBU1314,

        No, you would use Print() to print. And use .ToString() on a double when printing this or concatenating with another string.

        myDouble is an example of a variable name. This would be whatever variable you are trying to print.

        Below is a link to a video that demonstrates prints.
        Describes the elements of a string.Format() call. Used to debug a script to understand behavior.


        Below I am providing the link to the help guide page in question.


        As an example try:
        Print(Instrument.MasterInstrument.RoundToTickSize( 100.31).ToString());
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you!

          Comment


            #6
            Chelsea, I am trying to implement your suggestion but cant seem to make much progress. Here my code:
            I want to round to 2 decimals with date / time /etc. I have shortcut i use:

            private void P(string msg)
            {
            Print(Time[0].ToShortDateString() + " " + Time[0].ToShortTimeString() + ":" + msg);
            }

            So a sample message I want to round is the current ATR level at entry:
            P("ATR at Entry is:" + _atr[0]);
            Where would I implement the rounding command? I tried everything and there is no example in the help guide.
            Thanks

            Comment


              #7
              Thank you for these added details JBU1314. To print a decimal out to 2 places, we can use a format string :
              Code:
              [FONT=Courier New]Print([B]String.Format([/B]"ATR at Entry is: [B]{0:0.00}[/B]"[B],[/B] _atr[0][B])[/B]);[/FONT]
              This publicly available MSDN link has more information on format strings.
              Learn how to create a custom numeric format string to format numeric data in .NET. A custom numeric format string has one or more custom numeric specifiers.
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by JBU1314 View Post
                Chelsea, I am trying to implement your suggestion but cant seem to make much progress. Here my code:
                I want to round to 2 decimals with date / time /etc. I have shortcut i use:

                private void P(string msg)
                {
                Print(Time[0].ToShortDateString() + " " + Time[0].ToShortTimeString() + ":" + msg);
                }

                So a sample message I want to round is the current ATR level at entry:
                P("ATR at Entry is:" + _atr[0]);
                Where would I implement the rounding command? I tried everything and there is no example in the help guide.
                Thanks
                Code:
                P("ATR at Entry is: " + RoundToTickSize(_atr[0]));
                Last edited by koganam; 01-27-2017, 12:34 PM.

                Comment


                  #9
                  Thank you. This works great

                  Comment


                    #10
                    Hi Koganam,
                    Thanks for the response but this does not seem to work. Any advice? Rounding to TickSize of course would be best.

                    Comment


                      #11
                      To clarify JBU1314, koganam is giving instructions on how to round the actual value to the nearest tick, and that advice can be combined with mine. I am not actually affecting the value; rather, my advice affects how the data is displayed.

                      If you would like to display data to the nearest tick rounded to 2 decimal places, that is

                      Code:
                      [FONT=Courier New]Print(String.Format("ATR at Entry is: {0:0.00}", RoundToTickSize(_atr[0])));[/FONT]
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by JBU1314 View Post
                        Hi Koganam,
                        Thanks for the response but this does not seem to work. Any advice? Rounding to TickSize of course would be best.
                        What is your output? What doesn't work exactly?
                        What do you expect/want to see?

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by trilliantrader, Today, 03:01 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post trilliantrader  
                        Started by pechtri, 06-22-2023, 02:31 AM
                        9 responses
                        122 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by frankthearm, 04-18-2024, 09:08 AM
                        16 responses
                        67 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by habeebft, Today, 01:18 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by benmarkal, Today, 12:52 PM
                        2 responses
                        19 views
                        0 likes
                        Last Post benmarkal  
                        Working...
                        X