NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-24-2009, 03:21 PM   #1
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default StreamWriter

Another question on the StreamWriter. I have your StreamWriter Sample. If I want to use it inside a strategy, can I just call it as an indicator?

Since the overload is IDataSeries, should I just put the DataSeries I want to print out to the file?
stefy is offline  
Reply With Quote
Old 08-24-2009, 03:26 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Not sure what you mean. The sample is just a sample. Not sure if you would actually want to call the sample. You can use StreamWriter just the same in a strategy as you can in an indicator. Might be easier that way.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-24-2009, 04:06 PM   #3
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

I meant, in your sample you print out Open, High, Low, Close.
If I want to StreamWrite the Cumulative PNL of my strategy, can I just change your sample accordingly (changing the fields I want to print out) and then just insert StreamWriter into my strategy, as if it were an indicator?
The syntax would be StreamWriter()?
stefy is offline  
Reply With Quote
Old 08-25-2009, 07:08 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

That should work. The syntax would be incorrect as that is not the indicator name though. The term "StreamWriter" is also already used by C# so you likely can't name your indicator that.
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-25-2009, 11:29 AM   #5
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm using StreamWriter now to print out to a file the PnL of a Strategy. Since I cannot reference the PnL from an Indicator, I'm adding the StreamWriter to the strategy itself.
I followed your sample and added System.IO and in Variables System.IO.StreamWriter sw, then after the strategy code, the try catch block.

It compiles but in the Log I get "Error on calling OnBarUpdate method: object reference not set to an instance of an object".

What can be wrong? The strategy also doesn't run (all zeroes).
stefy is offline  
Reply With Quote
Old 08-25-2009, 11:44 AM   #6
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You will need to use try-catch blocks throughout your code to try and find where the error is being generated from. Please also see this tip if you are using IOrders. http://www.ninjatrader-support2.com/...ead.php?t=4226
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
StreamWriter with Live Strategy tony900hwk Strategy Development 41 01-11-2010 02:25 PM
Streamwriter/reader questions Burga1 General Programming 13 05-20-2008 12:53 PM
Indicator: Using StreamWriter to write to a text file Jim-Boulder Strategy Development 1 02-11-2008 02:41 PM
Indicator: Using StreamWriter to write to a text file NinjaTrader_Josh Reference Samples 0 09-30-2007 10:38 PM


All times are GMT -6. The time now is 08:40 AM.