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 format for output window

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

    print format for output window

    Hello,

    I want to ask please how the print format of price/double in output window and chart can be determined in a strategy or indicator. Because without its printing depending from price like x.xxxx.xx or x.xxx.x or x.xxxx so there is no clear vertical position of the following columns to the right. What has to be added to the print code in the script to have always x.xxx.xx. (Please note, the question is not about "." or ",")

    In the attached screenshot its to see how it looks now.

    Thank you!
    Tony
    Attached Files
    Last edited by tonynt; 09-20-2020, 10:08 AM. Reason: translation error

    #2
    Start here.
    Drill down into the links, study the code, experiment as necessary, the answers are there.

    Hint:
    Everywhere you want to print 'price', you would use 'FormatPrice(price)' instead.

    Comment


      #3
      Hello tonynt,

      bltdavid is giving good advice. Below is a link to the help guide on FormatPrice().


      You can also use numeric format strings with your print.
      In this article, learn to use standard numeric format strings to format common numeric types into text representations in .NET.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hello,

        thank you for your reply. Another question concerning the output window. How can one have an output window for ES, and another one for CL and one for 6E pls? I have coded in a script to print me what I need and want to bring up the output window ES beside ES chart, the output window with CL beside CL chart...

        Thank you!
        Tony

        Comment


          #5
          Hello Tony,

          Unfortunately, there is only one output window and this only has two tabs.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello,

            thank you for your reply. OK. Is it then possible to plot it the same way in the chart? Now I have it also in the chart but always showing "only" the last value, can one have the printing/plotting same as in output window in the chart (I mean row below row... with incoming new numbers...eg the bid ask from the top in T&S)

            Thank you!
            Tony

            Comment


              #7
              Hello Tony,

              You could accumulate the messages with newlines to a string. Then use Draw.TextFixed() to draw the string on the chart.

              string myString;

              myString += "\r\n" + Close[0];

              Draw.TextFixed(this, "tag1", myString, TextPosition.TopRight);

              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello,

                thank you for your reply. I´m not sure if I understand, sorry. As I wrote I use it in the chart already (with draw.textfixed). But how can I have plotting always a new new line so that the value before is always one row lower - instead of updating at the exact same xy-position. I mean the new value can be on the same xy-position but the value from before should be below. Would this be possible? And I allow to add a question in this concern: if this would work, would this use a lot of cpu? (because text plotting uses sometimes a lot of cpu as I saw in utm)

                Thank you!
                Tony
                Last edited by tonynt; 09-21-2020, 09:22 AM. Reason: inaccurate translation

                Comment


                  #9
                  Hello Tony,

                  New lines can be added with "\r\n" the \r is return the \n is new line.

                  Calling draw methods does use CPU. It would depend on how frequently the draw method is being called.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    thank you for your reply. You wrote above that there are 2 tabs in the output window: how can I plot in tab2, so I can run the code for 2 instruments, each plotting in one of the tabs.

                    Thank you!
                    Tony

                    Comment


                      #11
                      Hello Tony,

                      You can set the PrintTo to .OutputTab2.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello,

                        thank you for your reply. Is it possible to open output window 2 times? Or to float tab2?

                        Thank you!
                        Tony

                        Comment


                          #13

                          Hello Tony,

                          Unfortunately, there is only one output window and this only has two tabs. It is not possible to open two output windows.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            I'd like to recommend a different approach.

                            Tony, design your own 'Print' function that writes its output
                            to a log file. Start simply with something like this,

                            Code:
                            private void DebugOutput(string format, params object[] args)
                            {
                                Print(string.Format(format, args));
                            }
                            The 'params' feature makes it much easier to create formatted output,
                            for example, call it like this,

                            Code:
                            DebugOutput("Bar={0} Time='{1}' {2}", CurrentBar, Time[0].ToString("M/d/yy ddd HH:mm:ss"), msg);
                            And use it in a higher level wrapper, like this,

                            Code:
                            private void Debug(string format, params object[] args)
                            {
                                string msg = string.Format(format, args);
                                DebugOutput("Bar={0} Time='{1}' {2}", CurrentBar, Time[0].ToString("M/d/yy ddd HH:mm:ss"), msg);
                            }

                            Then migrate DebugOutput to writing to a stream,

                            Code:
                            private StreamWriter DebugOutputStream = null;
                            private string = DebugOutputFileName = null;
                            private void DebugOutput(string format, params object[] args)
                            {
                                if (DebugOutputStream == null)
                                {
                                    DebugOutputFileName = [COLOR=#27ae60]<your code>[/COLOR];
                                    DebugOutputStream = File.AppendText(DebugOutputFileName);
                                }
                            
                                DebugOutputStream.WriteLine(string.Format(format, args));
                            }
                            It sounds like you want the filename to be instrument specific,
                            which is straightforward to do, so modify <your code> to taste.

                            Ok, so why do all this?
                            What's the big deal?

                            Easy.
                            The point is: create separate debug output files, so that you can
                            watch them all separately, using a separate program.

                            Download one of the many Windows 'tail' programs to watch the
                            output of each log file.

                            I use BareTail, which has a free version, and a pro version for $25.

                            Start BareTail three times, once on each log file, and now you have
                            three separate 'output windows' ... Problem solved!

                            BareTail even has configurable color highlighting, so you can colorize
                            important lines when they appear. I really love that feature.

                            Enjoy!

                            [EDIT: Also, BareTail supports tabs, so you can tail as many files as
                            you want inside one invocation, each file would appear in its own tab.]
                            Last edited by bltdavid; 09-22-2020, 11:53 AM.

                            Comment


                              #15
                              Hello bltdavid,

                              thank you for your reply!! I think this will be to difficult for me because I have no idea what-where-...

                              Best regards
                              Tony

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by kulwinder73, Today, 10:31 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post kulwinder73  
                              Started by terofs, Yesterday, 04:18 PM
                              1 response
                              23 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by CommonWhale, Today, 09:55 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Gerik, Today, 09:40 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post Gerik
                              by Gerik
                               
                              Working...
                              X