NexusFi: Find Your Edge


Home Menu

 





StreamWriter and System IO Aggro...


Discussion in NinjaTrader

Updated
    1. trending_up 4,604 views
    2. thumb_up 5 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 3 attachments




 
Search this Thread
  #1 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801

Hi all,

I'm trying to add some new functionality to my ExportData strategy. As it is, it will write the DateTime format to a file based on your systems settings. Current code is:

 
Code
string data = (Time[0] + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + Volume[0]);
 
if (splitDateTime == true)
{
//Replace the space in DateTime with the DataSeparator
data = data.Replace(@" ",dataSeparator);
}
 
sw.WriteLine(data);
So Time[0] outputs a DateTime struct based on your Windows settings. I would like to add an enum that allows the user to choose an output format of choice, using (for example)

 
Code
string data = (Time[0].ToString("yy-MM-dd HH:mm:ss") etc etc (pseudocode)
I know I can't use special characters in enums and I can work around that. My issue is that something as basic as this:

 
Code
bool x = true;
 
if(x)
{
string data = (Time[0] + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + Volume[0]);
}
... outputs a blank file (actually one that only has carriage returns).

So I can hard-code the output DateTime format but any time I try to give the user an option that is called either in OnStartUp() or OnBarUpdate() I get a blank output file.

Any thoughts I what I could be doing wrong?


Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Irans Answer Due Today: Peace Surges to 33.5%, Invasion …
Prediction Markets & Event Contracts
Hormuz Surges From 14% to 26.5% Intraday as Irans Answer …
Prediction Markets & Event Contracts
The June 15 Resolution Trap: Irans Agreed Text Still Pri …
Prediction Markets & Event Contracts
Penalties in Budapest, Peace Deadline in Tehran: Arsenal …
Prediction Markets & Event Contracts
Peace Deal Forward Curve: May 22%, June 51%, December 81 …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801


Full code attached.


Attached Files
Elite Membership required to download: ExportData.cs
Started this thread Reply With Quote
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,577


MXASJ View Post
So I can hard-code the output DateTime format but any time I try to give the user an option that is called either in OnStartUp() or OnBarUpdate() I get a blank output file.

Any thoughts I what I could be doing wrong?

Wild guess - the file isn't being opened or closed in the right order, maybe check your Print() statements to make sure they contain data, and if so, then it's definitely an issue with how the file is opened or closed as data is being written to it. Assuming you checked the Log tab for errors? The path resides in the Users\Documents directory (write access)?

Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801

Thanks Mike. Making some positive progress with this in OnBarUpdate():

 
Code
switch(dateTimeFormat)
{
case MyDateTime.PCTimeFormat:
{
string data = (Time[0] + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + Volume[0]);
if (splitDateTime == true)
{
//Replace the space in DateTime with the DataSeparator
data = data.Replace(@" ",dataSeparator);
}
 
sw.WriteLine(data);
 
break;
}
case MyDateTime.ISO8601Basic:
{
string data = (Time[0].ToString("yyyyMMdd HHmmss") + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + Volume[0]);
if (splitDateTime == true)
{
//Replace the space in DateTime with the DataSeparator
data = data.Replace(@" ",dataSeparator);
}
 
sw.WriteLine(data);
break; 
}
case MyDateTime.ISO8601Extended:
{
string data = (Time[0].ToString("yyyy-MM-dd HH:mm:ss") + dataSeparator + Open[0] + dataSeparator + High[0] + dataSeparator + Low[0] + dataSeparator + Close[0] + dataSeparator + Volume[0]);
if (splitDateTime == true)
{
//Replace the space in DateTime with the DataSeparator
data = data.Replace(@" ",dataSeparator);
}
 
sw.WriteLine(data);
break; 
}
 
}


Started this thread Reply With Quote
  #6 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 801

Still needs a bit of testing and cleanup but if anyone wants to try my latest ExportData strategy and take a particular look at DateTime output formats that would be great. Open to suggestions on ways to make it better.

cs file attached.


Attached Thumbnails
Click image for larger version

Name:	Dialog.jpg
Views:	272
Size:	96.8 KB
ID:	26440  
Attached Files
Elite Membership required to download: ExportData.cs
Started this thread Reply With Quote
Thanked by:




Last Updated on December 2, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts