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

Printing to a file

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

    Printing to a file

    Is there a simple way of getting ninja to print to a file? For example say I have an indicator that produces 1 for a higher daily close, I would like
    to output this to a file with details such as date etc. I know that this can be done with C# programming but is there a simple way to do this. It would aid greatly in analysis of the markets.

    #2
    SampleStreamWriter

    OK I have found the Samplestreamwriter example and have used it to output data. In the indicator there is a variable:-

    privatestring path = Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";

    I would like to amend the location the file is saved in, so that I have a ninja test directory for example. How do I do this? I presume that it is not just a case of amending the
    above line as there are probably other references to the path variable in the 'Ninjaascript generated code' section.

    Thanks

    Comment


      #3
      Originally posted by MicroAl View Post

      privatestring path = Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";
      The above will write a file to the My Documents/Ninja Folder

      I use:
      private string path = @"F:\" + "ES " + String.Format("{0:yyMMdd ddd}",DateTime.Now) + ".csv";

      Which will create a file named "ES 090311 Wed" for yesterdays data.

      The ".csv" extension allows me to open the file easily in Open Office Calc or Excel

      F:\ is my memory stick drive (I would rather have errors on my Mem Stick and not on my hard drive) and lowers the rear and tear on the hard drive.

      This my not be the best way to do it but it works on my computer. Disclaimer: I am a trader first and a horrible code hack second.

      Hope this helps.

      TAJ

      Comment


        #4
        Micro,

        you may want to reference this post for some background information.

        I have found the following works for me
        Code:
        //Variables
        private bool logFileInit = false;
        private FileStream file;
        private StreamWriter sw;
        
        //OnBarUpdate method
        //*******************************
        //          CREATE LOG FILE
        //*******************************
        if(!logFileInit)
        {
                logFileInit = true;
        
                try
                {
                    if(file == null)
                        file = new FileStream("C:\\test.txt", FileMode.OpenOrCreate, FileAccess.Write);
                    if(sw == null)
                        sw = new StreamWriter(file);
                 }
                 catch(Exception ex)
                 {
                     Print(ex.ToString());
                 }                
        }
        
        //To use it
        sw.Write("your text");
        
        
        //********************************
        //   DISPOSE METHOD -- CLEAN UP OBJECTS
        //   To Properly dispose of it when finished to 
        //   prevent file locking, etc
        //********************************
        public override void Dispose()
        {
             //******************
             //  Clean up resources 
             //******************            
                    
             try
             {
                if(sw != null)
                {
                     // Close the stream writer
                    sw.Close();
                }
                        
                if(file != null)
                {
                    // Close the file writer
                    file.Close();
                }
              }
              catch (Exception e)
              {
                 Print(e.ToString());
              }
        
              //Removes all draw objects
              RemoveDrawObjects();
        
              //call base
              base.Dispose();
        }
        hope this helps.
        mrlogik
        NinjaTrader Ecosystem Vendor - Purelogik Trading

        Comment


          #5
          Printing to a file

          Thanks to both of you. I certaintly have plenty to look at over the weekend.

          One for the Ninja Administrators. Through the wizards you can fairly easily
          use the menus etc to set up some complicated strategies. Why not add a facility for market analysis? Ie something that allows a user to check for market patterns and obtain a printout. Eg a user could select to find how many times and on what dates a higher close followed a previous higher close etc. Could be an additional selling point!

          Comment


            #6
            Thanks for the input MicroAl, like a pattern data mining tool...
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Pattern Data Mining

              Yes that would be a very useful addition.

              While I consider your product to be excellent in many respects, a couple of things do let it down in actual trading. One, the simple inability to draw a line, right click and set an alert (is there a problem with patents here?)

              The other is concerning workspaces. For the newbie traders among us who have not got the room for multiple monitors etc, a simple way of pointing and clicking on a tab to change a displayed workspace etc is essential especially when day trading and a fast decision is required. If there is a key sequence which does this I apologise but I have not seen one and have read on the forum that key macros are not supported.

              Comment


                #8
                For the workspaces try pressing Shift + F3 to cylce to the next active one.

                Thanks for the suggestion on adding an alert to the drawn lines.

                You can also check into this indicator - http://www.ninjatrader-support2.com/...id=125&catid=1
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Ninja just gets better!

                  Thanks, that is just what I wanted.

                  Regards

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Mestor, 03-10-2023, 01:50 AM
                  16 responses
                  389 views
                  0 likes
                  Last Post z.franck  
                  Started by rtwave, 04-12-2024, 09:30 AM
                  4 responses
                  31 views
                  0 likes
                  Last Post rtwave
                  by rtwave
                   
                  Started by yertle, Yesterday, 08:38 AM
                  7 responses
                  29 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by bmartz, 03-12-2024, 06:12 AM
                  2 responses
                  22 views
                  0 likes
                  Last Post bmartz
                  by bmartz
                   
                  Started by funk10101, Today, 12:02 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post funk10101  
                  Working...
                  X