NinjaTrader Support Forum  

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

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 02-13-2010, 04:34 AM   #1
malmaa
Member
 
Join Date: Dec 2009
Posts: 67
Thanks: 0
Thanked 0 times in 0 posts
Default StreamWriter

I have slightly modified example "SampleStreamWriter". First option works, but my code doesn't.
I am trying to write data to my file at user defined location. It doest write at the same time no error message. How to write to a file at user defined location?
Any help please?
Regards,

Code:
protectedoverridevoid Initialize()
{
// path = Cbi.Core.UserDataDir.ToString() + Instrument.FullName + ".txt";
path = "D:\\ForexData\\Ninja" + Instrument.FullName + ".txt";
CalculateOnBarClose =
true;
}
malmaa is offline  
Reply With Quote
Old 02-13-2010, 09:43 AM   #2
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

This works for me:
privatestring path2 = "C:\\AFolderName\\MyTestFile.txt";

Try starting over with the SampleStreamWriter file and just changing the one line above and this line (of course use a patht that will work on your computer):
sw = File.AppendText(path2);

Can you get that to work?
NinjaTrader_Ben is offline  
Reply With Quote
Old 02-14-2010, 06:40 AM   #3
malmaa
Member
 
Join Date: Dec 2009
Posts: 67
Thanks: 0
Thanked 0 times in 0 posts
Smile

Thankyou Ben for your reply.
I was missing two "\\" at the end of my path string. Its working now.
Thanks a lot.

Cheers,
malmaa is offline  
Reply With Quote
Old 09-11-2010, 03:37 AM   #4
Oil_Trader
Senior Member
 
Join Date: Aug 2010
Location: http://twitter.com/Oil_Trader
Posts: 141
Thanks: 0
Thanked 0 times in 0 posts
Default

How do I encapsulate an output sw.WriteLine(" This is Close Price "25" ");

it is reading it to behaving 2 quotation marks at "25"

there fore an error occurs during compile of the indicator.
Oil_Trader is offline  
Reply With Quote
Old 09-11-2010, 06:01 AM   #5
Oil_Trader
Senior Member
 
Join Date: Aug 2010
Location: http://twitter.com/Oil_Trader
Posts: 141
Thanks: 0
Thanked 0 times in 0 posts
Default

For the streamwriter, it seems to be writing the the next line below,

Is it possible to write on the line above?

Is it possible to overwrite the existing file with the new entry? By deleting the previous line?
Oil_Trader is offline  
Reply With Quote
Old 09-11-2010, 11:00 AM   #6
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

Oil_Trader, yes these are possible: to write something with quotes, please try putting an @ symbol in front of the string. As for how to overwrite the existing file, you'll have to review the MSDN documents on StreamWriter because I'm not intimately familiar with the process.
NinjaTrader_Austin is offline  
Reply With Quote
Old 09-13-2010, 01:24 PM   #7
Oil_Trader
Senior Member
 
Join Date: Aug 2010
Location: http://twitter.com/Oil_Trader
Posts: 141
Thanks: 0
Thanked 0 times in 0 posts
Default

Can you give a specific example?

This is what I am writing and yet is is saying ------> ) expected

this is my code

sw.WriteLine(@" SP500 ="1225.0" + NQ ");

as you can see, there are quotation marks within the parameter
Oil_Trader is offline  
Reply With Quote
Old 09-13-2010, 02:28 PM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello OilTrader,

You may have to use escape characters for the quotation marks. See the reference sample below for help with this:
Indicator: Manipulating string objects
NinjaTrader_RyanM 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 from a Strategy stefy Strategy Development 10 08-30-2009 08:46 PM
StreamWriter stefy General Programming 5 08-25-2009 11:44 AM
Streamwriter/reader questions Burga1 General Programming 13 05-20-2008 12:53 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 10:33 AM.