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

Print() syntax

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

    Print() syntax

    I'd like to print out different values in colums, something like
    Print(variable1, variable2, variable3).
    What is the correct syntax I can use?
    More generally, do you have a link for C# function references?

    Thank you

    #2
    Print(variable1 + " " + variable2 + " " + variable3);

    If you only wanted to print one variable you could do this:
    Print(variable1.ToString());

    MSDN and google are great places to find information on C#.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Anything similar to printf()?

      Any ability to insert variables with %d, %s, etc. into the strings?

      I have looked on Google...

      Comment


        #4
        In C# you do not need to use the % syntaxing for the variables like in C. You can just call your variable and use .ToString() on it to get it to print.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Aligning prices

          In the help file, it says:

          Tips
          1. You can align prices to be formatted for easier debugging such as Low[0].ToString("0.00"). So if you have
          12.5
          12.75
          you would get
          12.50
          12.75

          Is there any way to apply this with interspersed text and variables?

          For example, can I get the code below to print out the average price in a XXXX.XX format so the time stamps line up?

          For that matter, is there a way to format the time stamp so the implied 0 in front of single digit hours shows?

          Print(Position.MarketPosition +" from "+ Position.AvgPrice +" at " + Time[0].ToString());

          Currently I get:
          Long from 1299.5 at 8/12/2008 9:30:00 AM
          Long from 1295.75 at 8/12/2008 11:00:00 AM

          And I would like it to look like:
          Long from 1299.50 at 8/12/2008 09:30:00 AM
          Long from 1295.75 at 8/12/2008 11:00:00 AM

          Thank you,

          DK

          Comment


            #6
            Hi,

            You will want to use Position.AvgPrice.ToString("N2").


            To format your DateTime object please see this article: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thank you for the links.

              Is there any way to have 2 different formats on one line?

              For example, in your post from your first link is there any way to combine:
              Print(“Formatted to 2 decimal places: ” + c.ToString(“N2”));
              Print(“Formatted to 3 decimal places: ” + c.ToString(“N3”));

              so that the line in the output window reads:
              Formatted to 2 decimal places: 10.26 Formatted to 3 decimal places: 10.257

              instead of having it print on a different line each time?

              Thanks.





              Originally posted by NinjaTrader_Josh View Post
              Hi,

              You will want to use Position.AvgPrice.ToString("N2").


              To format your DateTime object please see this article: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

              Comment


                #8
                Sure, just put all the text into one Print() line.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  You can also try stuff like this to simulate %s/printf from C/C++:

                  Code:
                  Print(String.Format("Close:{0} High:{1:0.00}", Close[0], High[0]));
                  See here for some more examples: http://msdn.microsoft.com/en-us/library/fht0f5be.aspx

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mjairg, 07-20-2023, 11:57 PM
                  3 responses
                  213 views
                  1 like
                  Last Post PaulMohn  
                  Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                  4 responses
                  544 views
                  0 likes
                  Last Post PaulMohn  
                  Started by GLFX005, Today, 03:23 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post GLFX005
                  by GLFX005
                   
                  Started by XXtrader, Yesterday, 11:30 PM
                  2 responses
                  12 views
                  0 likes
                  Last Post XXtrader  
                  Started by Waxavi, Today, 02:10 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Working...
                  X