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

Sample FileReadWrite Indicator

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

    Sample FileReadWrite Indicator

    Hey,


    I got the SampleReadWrite Indicator from Ninjatrader and I'm trying to change the code so the filename matches the instrument that the indicator is applied to:

    Here's the part of the code:

    Code:
    #region Variables
    		private int		date				= 0;
    		private double	currentOpen			= 0;
    		private double	currentHigh			= 0;
    		private double	currentLow			= 0;
    		private double	currentClose		= 0;
    		private bool	currentOpenSaved 	= false;
    		private bool	currentLowSaved		= false;
    		
    		// This sets the path in which the text file will be created.
    		private string	path				= Cbi.Core.UserDataDir.ToString() + "SampleFileReadWrite-MyTestFile.txt";
            #endregion
    I somehow need to get the Instrument variable into the filename.

    Anybody have any ideas? Koganam?

    CSR's - Please don't respond with "we have third party indicator creators who will gladly take your money." I get it but I need my money right now!

    live logic and long prosper
    Attached Files
    Last edited by stockgoblin; 05-03-2013, 10:12 AM.

    #2
    WOW!!!

    This is great!!! This SampleFileReadWrite.cs Indicator can be used in the Market Analyzer, which can take instrument lists, making a batch export of data possible and I can actually get Weekly data from it!!!!! YES YES YES. I did manage to make a Daily to Weekly data converter in Excel but this is way easier!!!! Yes!

    Just need to get the file name to represent the particular instrument now.

    This is so much easier than the Export feature in the Historical Data Manager.

    Long live analysis!

    Comment


      #3
      You can use Instrument.MasterInstrument.Name in order to get the name of the instrument:


      Once you have that, you can pass it to your File name string.
      MatthewNinjaTrader Product Management

      Comment


        #4
        Nice! I'll start looking into the syntax of doing that. Do you know of any other indicators that do something similar that I could look at for reference?

        I wish:

        could include some examples for a starting point.

        Comment


          #5
          I do not know of any indicators off the top of my head.
          MatthewNinjaTrader Product Management

          Comment


            #6
            Any clues for me on how to incorporate

            Instrument.MasterInstrument.Name

            into

            private string path = Cbi.Core.UserDataDir.ToString() + "SampleFileReadWrite-MyTestFile.txt";

            Comment


              #7
              Instrument.MasterInstrument.Name returns a string.

              So you can just add that to your string path

              Are you creating the file using StreamWriter, or just using reading an existing file?

              MatthewNinjaTrader Product Management

              Comment


                #8
                yea, i did try that:

                private string path = Cbi.Core.UserDataDir.ToString() + Instrument.MasterInstrument.Name + "SampleFileReadWrite-MyTestFile.txt";

                but I get "An object reference is required for the non-static field, method, or property"

                Streamwriter is used in the indicator :

                // Add this to your declarations to use StreamWriter and StreamReader
                using System.IO;

                and the indicator does write the file but to the same filename regardless of instrument.

                i take it i have to declare something?
                Attached Files
                Last edited by stockgoblin; 05-03-2013, 12:57 PM.

                Comment


                  #9
                  I see in the Market Analyzer indicator: Instrument.cs they:

                  protected override void Initialize()
                  {
                  CalculateOnBarCloseConfigurable = false;
                  DataType = typeof(string);
                  RelativeColumnWidth = 2;
                  RequiresBars = false;
                  Text = Instrument.FullName;
                  }

                  /// <summary>
                  /// </summary>
                  /// <returns></returns>
                  public override string ToString()
                  {
                  return "Instrument";
                  }

                  perhaps I need to do something similar?

                  Comment


                    #10
                    You can also use Instrument.FullName if you wish. This will return the expiry if you're using futures to.

                    However you would need to call this property some place that the bars object has already been called. Where you're setting the path name in the region variables, there are no bars yet. You'd need to use something like OnStartUp()

                    Please see my SampleStreamWriter for an example of how to do this (look around line 56)
                    Attached Files
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      You absolutely Rock!

                      Thank-you. I got it... and just in time for my analysis of weekly data!! You saved me hours and hours this weekend. No longer do I have to sit there and export each instruments data, one at a time, in daily format and then convert them to Weekly using an excel program I made.

                      Now I just load a market analyzer, put in an instrument list and all the data text files appear instantly!

                      Thank-you. Have a kick ass weekend man. I appreciate your help tremendously. You really saved me hours and hours of tedious work!!

                      rock on

                      Comment


                        #12
                        Oh, one more thing:

                        The format of Today(Time[0]) is giving me 19960119 (Year, Month, Day)

                        in:

                        string ohlc = ToDay(Time[0]) + " " + Open[0] + " " + High[0] + " " + Low[0] + " " + Close[0] + " 333" + Environment.NewLine;

                        What can I do to get it to output the date stamp in (Month Day Year) instead?
                        Last edited by stockgoblin; 05-03-2013, 02:09 PM.

                        Comment


                          #13
                          You would want to use Time[0].ToString("D") which would give you Month Day Year

                          More information on this can be found below:


                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            Originally posted by stockgoblin View Post
                            yea, i did try that:

                            private string path = Cbi.Core.UserDataDir.ToString() + Instrument.MasterInstrument.Name + "SampleFileReadWrite-MyTestFile.txt";

                            but I get "An object reference is required for the non-static field, method, or property"

                            Streamwriter is used in the indicator :

                            // Add this to your declarations to use StreamWriter and StreamReader
                            using System.IO;

                            and the indicator does write the file but to the same filename regardless of instrument.

                            i take it i have to declare something?
                            Change the line:
                            Code:
                            private string path = Cbi.Core.UserDataDir.ToString() + "SampleFileReadWrite-MyTestFile.txt";
                            to:
                            Code:
                            private string fileName = DataFile.txt;
                            private string path = Cbi.Core.UserDataDir.ToString();
                            Then reassign the filename in OnStartUp()
                            Code:
                             
                            fileName = Instrument.MasterInstrument.Name + ".txt";
                            path += fileName;
                            Last edited by koganam; 05-05-2013, 11:58 AM.

                            Comment


                              #15
                              Exporting chart data to txt file including instrument name and barsize

                              Hi guys,

                              Exporting the chart data including the instrument name works great.
                              Now I would likt to add the barsize to the file name.
                              I use tick data charts and minute charts.

                              Could you point me in the right direction, because I can't find the right syntax in the help guides?

                              Thanks,
                              Aad

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Belfortbucks, Today, 09:29 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Belfortbucks  
                              Started by zstheorist, Today, 07:52 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post zstheorist  
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              151 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Working...
                              X