> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# Using StreamWriter to write to a text file

Sometimes you may want to store information related to certain market conditions or trades outside of NinjaTrader. The formatting of the text file can also make for easy importing into Microsoft Excel in the future.

## Key concepts in this example

* Creating a text file with StreamWriter
* Writing Open-High-Low-Close data with date stamps to the file

## Important related documentation

* [StreamWriter](https://learn.microsoft.com/en-us/dotnet/api/system.io.streamwriter?view=netframework-4.8)
* [WriteLine](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.writeline?view=netframework-4.8)
* [StringWriter](https://learn.microsoft.com/en-us/dotnet/api/system.io.stringwriter?view=netframework-4.8)
* [TextWriter](https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter?view=netframework-4.8)

## Import instructions

1. Download the file contained in this Help Guide topic to your PC desktop
2. From the Control Center window, select the menu Tools > Import > NinjaScript
3. Select the downloaded file

[SampleStreamWriter\_NT8.zip](https://ninjatrader.com/support/helpGuides/nt8/samples/SampleStreamWriter_NT8.zip)