PDA

View Full Version : Indicator: Using StreamReader to read from a text file


NinjaTrader_Josh
09-30-2007, 11:42 PM
Sometimes you may have data stored outside of NinjaTrader that you want to bring in and use for calculations. Using StreamReader will allow us to bring in the data stored in text files and allow us to do manipulations with them.

This reference sample demonstrates the following concepts:

Opening a text file with StreamReader
Parsing Open-High-Low-Close data with date stamps from a file
Determining current day Open-High-Low-Close after reading data from the text file with StreamReader

Important methods and properties used include:

StreamReader (http://msdn2.microsoft.com/en-us/library/system.io.streamreader.aspx)
ReadLine (http://msdn2.microsoft.com/en-us/library/system.io.streamreader.readline.aspx)

Other methods and properties of interest include:

StringReader (http://msdn2.microsoft.com/en-us/library/system.io.stringreader%28VS.90%29.aspx)
TextReader (http://msdn2.microsoft.com/en-us/library/system.io.textreader%28VS.90%29.aspx)

Import instructions:

Download the file contained in this thread to your PC desktop
From the Control Center window, select the menu File > Utilities > Import NinjaScript
Select the downloaded file