NexusFi: Find Your Edge


Home Menu

 





StreamWriter and System IO Aggro...


Discussion in NinjaTrader

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




 
Search this Thread

StreamWriter and System IO Aggro...

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

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?
Are there any eval firms that allow you to sink to your …
Traders Hideout
Deepmoney LLM
Elite Quantitative GenAI/LLM
Better Renko Gaps
The Elite Circle
Build trailing stop for micro index(s)
Psychology and Money Management
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


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,398 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537


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 Twitter 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: 800

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: 800

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:	203
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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts