Announcement

Collapse
No announcement yet.

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").
            http://www.ninjatrader-support.com/v...ead.php?t=3823

            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").
              http://www.ninjatrader-support.com/v...ead.php?t=3823

              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 MidenThur, Today, 12:52 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post MidenThur  
                  Started by seseoraf, Today, 12:51 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post seseoraf  
                  Started by Rosario, Today, 12:50 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Rosario
                  by Rosario
                   
                  Started by kemoyums, Today, 12:38 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post kemoyums  
                  Started by MartynBashi, Yesterday, 11:01 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post MartynBashi  
                  Working...
                  X