Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print() syntax

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

  • Anagoge
    replied
    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

    Leave a comment:


  • NinjaTrader_JoshP
    replied
    Sure, just put all the text into one Print() line.

    Leave a comment:


  • 8DTK8
    replied
    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

    Leave a comment:


  • NinjaTrader_JoshP
    replied
    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

    Leave a comment:


  • 8DTK8
    replied
    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

    Leave a comment:


  • NinjaTrader_JoshP
    replied
    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.

    Leave a comment:


  • RandyT
    replied
    Anything similar to printf()?

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

    I have looked on Google...

    Leave a comment:


  • NinjaTrader_JoshP
    replied
    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#.

    Leave a comment:


  • stefy
    started a topic Print() syntax

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by ghiasi123, Today, 10:17 AM
1 response
8 views
0 likes
Last Post NinjaTrader_Zachary  
Started by demarcog, Today, 09:50 AM
1 response
9 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by Martin89, Today, 09:53 AM
1 response
9 views
0 likes
Last Post NinjaTrader_Kate  
Started by timmbbo, Today, 09:10 AM
1 response
11 views
0 likes
Last Post NinjaTrader_Manfred  
Started by space_trader, 11-26-2020, 05:06 AM
3 responses
167 views
1 like
Last Post NinjaTrader_RyanS  
Working...
X