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

  • 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").


    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").


    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 jxs_xrj, 01-12-2020, 09:49 AM
6 responses
3,290 views
1 like
Last Post jgualdronc  
Started by Touch-Ups, Today, 10:36 AM
0 responses
7 views
0 likes
Last Post Touch-Ups  
Started by geddyisodin, 04-25-2024, 05:20 AM
8 responses
61 views
0 likes
Last Post NinjaTrader_Gaby  
Started by Option Whisperer, Today, 09:55 AM
0 responses
8 views
0 likes
Last Post Option Whisperer  
Started by halgo_boulder, 04-20-2024, 08:44 AM
2 responses
24 views
0 likes
Last Post halgo_boulder  
Working...
X