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

Close of bar file output

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

    Close of bar file output

    hi guys, a noob here, trying to make it so NT prints a file in say c:\\test.txt file of the bar close value, thats it, if you could paste the whole script here that would be great thank you!

    #2
    vadimg,

    To help start you off, I've included some links below that you will find useful.

    We have two reference samples on this. Each method should suffice to write output to a file.

    System.IO : http://ninjatrader.com/support/forum...ead.php?t=3477

    StreamWriter : http://ninjatrader.com/support/forum...ead.php?t=3475

    Please let me know if I may assist further.
    Bobby Y.NinjaTrader Customer Service

    Comment


      #3
      right but the problem is i cant seem to write the path for the file output correctly can you do that here please?

      Comment


        #4
        vadimg,

        The code from StreamWriter outputs to the Documents folder:
        Code:
        private string path 			= Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";
        Cbi.Core.UserDataDir is a special variables that returns the windows user documents folder.

        To output to the C Drive, the path variable will have the following string:
        Code:
        private string path 			=  "C:\text.txt";
        Bobby Y.NinjaTrader Customer Service

        Comment


          #5
          Bobby, here is what i have but nothing happens, can you please paste the entire code for the indicator?


          string ohlc = ToDay(Time[0]) + ", " + Close[0] + Environment.NewLine;

          /* Creates the text file at the location determined in 'path' and puts the line 'ohlc' in.
          If file already exists it will append the line 'ohlc' onto the end. */
          File.AppendAllText("c:\text.txt", ohlc);




          Originally posted by NinjaTrader_BobbyY View Post
          vadimg,

          The code from StreamWriter outputs to the Documents folder:
          Code:
          private string path 			= Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";
          Cbi.Core.UserDataDir is a special variables that returns the windows user documents folder.

          To output to the C Drive, the path variable will have the following string:
          Code:
          private string path 			=  "C:\text.txt";

          Comment


            #6
            vadimg,

            After further testing, I've found that you are unable to write directly to the C:\ directory because the root of the C:\ Drive is protected from writes from all programs. Try writing to a sub-directory inside of the C:\ Drive such as C:\test\ or something like that. I've also included a sample script that prints closes to a file in the NinjaTrader 7 folder of your Documents folder. It should help you get started with what you'd like to do.
            Attached Files
            Bobby Y.NinjaTrader Customer Service

            Comment


              #7
              Bobby, i zipped up your cs file and imported into NT, now i go to edit it but cant find it under strategies or indicators. ?

              Comment


                #8
                Hello vadimg,


                I have attached a version of this indicator that can be imported by the platform.
                Here is a basic guideline of how to Import NinjaScripts.

                To import NinjaScripts you will need the original .zip file attached to this post.

                To Import
                1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
                2. From the Control Center window select the menu File> Utilities> Import NinjaScript
                3. Select the downloaded .zip file
                4. NinjaTrader will then confirm if the import has been successful.
                Once installed, you may add the indicator to a chart by:

                • Right click you chart > indicators > Select the Indicator from the list on the left > New > OK




                Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
                Attached Files
                Shawn B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you Bobby, when put in the file path it gives me an error
                  Indicator\WriteCloseToFiles.cs Unrecognized escape sequence CS1009 - click for info 43 51

                  if (CurrentBar == 0) sw = File.AppendText("c:\pricedata\test.txt");

                  Comment


                    #10
                    I saw what i did wrong i tried this too, but no files write


                    private string FileName = "Closes.txt"; //Name of text file
                    private string Path = @"c:\pricedata"; // Path to the text file that will be created.
                    private StreamWriter sw; // StreamWriter object
                    #endregion

                    #region Properties

                    [Description("")] [GridCategory("Parameters")]
                    public string _FileName { get { return FileName; } set { FileName = value; } }

                    #endregion

                    protected override void Initialize()
                    {
                    CalculateOnBarClose = true;
                    Overlay = true;
                    }

                    protected override void OnBarUpdate()
                    {
                    try
                    {
                    if (CurrentBar == 0) sw = File.AppendText(Path + FileName);

                    Comment


                      #11
                      oh i found the file in NT7 folder, ok i think i can work with this! just need to figure out how to properly put in the new folder path

                      Comment


                        #12
                        oki figured out how to change the file path!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by trilliantrader, Today, 08:16 AM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by bill2023, Yesterday, 08:51 AM
                        3 responses
                        20 views
                        0 likes
                        Last Post bltdavid  
                        Started by yertle, Today, 08:38 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by Mestor, 03-10-2023, 01:50 AM
                        15 responses
                        378 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by samish18, Yesterday, 08:57 AM
                        10 responses
                        28 views
                        0 likes
                        Last Post samish18  
                        Working...
                        X