![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
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()? |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
|
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). |
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |