Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Printing to output window

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

    Printing to output window

    Good Afternoon/Morning;

    I am trying to print data to the output window.

    My code is as follows:


    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class CSVPrinter : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }

    protected override void OnStartUp()
    {
    //Print your header
    Print("Date,Time,Open,High,Low,Close");
    }
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Print your data for each bar
    Print("," + Time[0] + "," + Open[0] + "," + High[0] + "," + Low[0] + "," + Close[0]);
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    However I get this as my printout:
    Date,Time,Open,High,Low,Close
    29/12/2011 21:00:00,1.2937,1.2965,1.2937,1.2964
    29/12/2011 22:00:00,1.2963,1.2964,1.2958,1.2961
    29/12/2011 23:00:00,1.2961,1.2962,1.2948,1.2951
    30/12/2011 00:00:00,1.2951,1.2955,1.2942,1.2953

    But I am trying to get this:
    Date,Time,Open,High,Low,Close
    29/12/2011, 21:00:00,1.2937,1.2965,1.2937,1.2964
    29/12/2011, 22:00:00,1.2963,1.2964,1.2958,1.2961
    29/12/2011, 23:00:00,1.2961,1.2962,1.2948,1.2951
    30/12/2011, 00:00:00,1.2951,1.2955,1.2942,1.2953

    How do I get it to print the comma between the data and the time.?

    Any help will be appreciated. Thank you in advance.



    aafwintb

    #2
    Hello aafwintb,
    Please use the below code to print as per your format.

    Code:
    Print(Time[0].ToString("dd/MM/yyyy") + "," + Time[0].ToString("HH:mm:ss") + "," + Open[0] + "," + High[0] + "," + Low[0] + "," + Close[0]);

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks joydeep;

      Tried that but still get the same output:

      Date,Time,Open,High,Low,Close
      29/12/2011 21:00:00,1.2937,1.2965,1.2937,1.2964
      29/12/2011 22:00:00,1.2963,1.2964,1.2958,1.2961
      29/12/2011 23:00:00,1.2961,1.2962,1.2948,1.2951

      Comment


        #4
        Problem solved , thank you and have a good day Joydeep.

        Comment


          #5
          Hello aafwintb,
          The attached code gives me this print:

          11/04/2012,14:15:00,1357.75,1370.5,1357.5,1364
          12/04/2012,14:15:00,1364.25,1386.25,1363.25,1386
          13/04/2012,14:15:00,1385.75,1388.5,1363.75,1365
          16/04/2012,14:15:00,1366,1375.25,1360.5,1364
          17/04/2012,14:15:00,1364.25,1388.75,1359.25,1383.5

          Please let me know if I can assist you any further.
          Attached Files
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            where does it print during live testing

            a related issue, when running S. Analyzer the Print goes to out, where does it go when doing realtime testing?

            Comment


              #7
              Hello anwar,
              The Print function will print out the logs in the Output window (Tools>Output Window) whether the code is running live or via the Strategy Analyzer.
              JoydeepNinjaTrader Customer Service

              Comment


                #8
                Hi, I want to print to output window data from strategy analyzer. This data are from Periods - Day of week - Cum Profit, DD, % Win and Avg. Trade. Can anybody help me? Thanks

                Comment


                  #9
                  Hi Igipop,

                  Thank you for posting and welcome to the forums!

                  You can use Print from the Strategy Analyzer using the same Print() method.

                  Additionally, you can use StreamWriter.IO to write to a separate text file from the back test.
                  Below is a reference sample on using StreamWriter -
                  http://www.ninjatrader.com/support/f...ead.php?t=3475

                  Please note that printing in the Strategy Analyzer can take a longer time to process the strategy when calculating and may see NInjaTrader going into a Non-Responsive state because of this.

                  Let me know if I can be of further assistance.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Sorry, but I don´t understand how I can use Print() method from strategy analyzer. Can you post some example for it? Are you think about grid? I use
                    Print("Total maximal drawdown " + Performance.AllTrades.TradesPerformance.Currency.D rawDown); it work ok, but i don know how can I use
                    Print("statistics by day of week " + Performance.AllTrades.ByDayOfWeek); but it is not correct because result in output window is: statistics by day of week System.Collections.SortedList
                    Last edited by igipop; 10-11-2013, 12:13 PM.

                    Comment


                      #11
                      Igipop,

                      Your print statements will be printed to the Output window, Tools -> Output Window.

                      What do you expect to be printed out from the print statements?
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        I want to print to output window :
                        monday - cum. profit, DD, % win, avg. trade
                        tuesday - cum. profit, DD, % win, avg. trade
                        wednesday - cum. profit, DD, % win, avg. trade
                        thursday - cum. profit, DD, % win, avg. trade
                        friday - cum. profit, DD, % win, avg. trade

                        Comment


                          #13
                          Igipop,

                          These values are available from the Periods Tab after you run a backtest. You can right click inside the window -> Grid -> Print, to print out those values rather than having them print to the Output Window and not drain computer resources running those print statements during the backtest.
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            ok I Know it, but when I run oprimization in strategy analyzer I have around 200 results and I need work with this data. then I must click on tab Periods -> Day of week then right click grid -> export to excel and I must do it 200 times. I want export these data to file. is it posible? I have already one question. when I made optimization and I save this data after reload these data I see only basic results of any results but when I click on tab Periods -> Day of week I dont see any results. So I need run optimization again. Excuse my english .
                            Attached Files
                            Last edited by igipop; 10-14-2013, 10:56 AM.

                            Comment


                              #15
                              Igipop,

                              The only other way would be to use the StreamWriter.IO that I mentioned in post #9.

                              I am not aware of away to export the grid from the periods tab via script.
                              Cal H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Sparkyboy, Today, 10:57 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Sparkyboy  
                              Started by TheMarlin801, 10-13-2020, 01:40 AM
                              21 responses
                              3,917 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Started by timmbbo, 07-05-2023, 10:21 PM
                              3 responses
                              152 views
                              0 likes
                              Last Post grayfrog  
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              30 responses
                              812 views
                              1 like
                              Last Post grayfrog  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X