Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
streamreader
Collapse
X
-
Tags: None
-
Originally posted by staycool3_a View Posthttps://ninjatrader.com/support/foru...xt-file?t=3476
hi, can someone provide a sample file that may work with this? I've tried to use streamreader before using this example and could never figure out how to make it work properly b/c i have no idea what file format the text has to be in.. aka date type, separators etc
20180912 78.54 78.54 78.54 78.54
20180911 79.94 79.94 79.94 79.94
20180910 80.97 80.97 80.97 80.97
should be the format b/c in the indicator it uses:
ToDay(Time[0]) == date)
but I keep getting this error:
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at NinjaTrader.NinjaScript.Indicators.SampleStreamRea der.OnBarUpdate()
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at NinjaTrader.NinjaScript.Indicators.SampleStreamRea der.OnBarUpdate()
-
Hello staycool3_a,
Thanks for your post.
The code for the SampleStreamReader was changed some time ago to correct this issue and you may be using the older version. Please remove the file SampleStreamReader from your Ninjatrader and download the latest from here: https://ninjatrader.com/support/help...o_read_fro.htm
Here is an example of the text generated by SampleStreamWriter that would be able to be read in by SampleStreamReader:
10/1/2018 3:00:00 PM,73.29,75.77,72.95,75.3
10/2/2018 3:00:00 PM,75.42,75.91,74.93,75.23
10/3/2018 3:00:00 PM,75.12,76.9,74.3,76.41
10/4/2018 3:00:00 PM,76.18,76.47,73.88,74.33
10/5/2018 3:00:00 PM,74.67,75.22,73.83,74.34
10/8/2018 3:00:00 PM,74.4,74.58,73.07,74.29
10/9/2018 3:00:00 PM,74.21,75.28,74,74.96
10/10/2018 3:00:00 PM,74.66,75.08,72.38,73.17
Paul H.NinjaTrader Customer Service
Comment
-
thanks Paul. I got it to work. I'm curious, do you think there is a way to edit the file while it's being used or is that some just not possible. used= it's being used by an indicator. i wish i could update the data while it's being used
Comment
-
strategy analyzer run using streamrreader = 46 seconds
regular strategy analyzer test using data loaded as a instrument = 3 seconds
lol
Comment
-
Hello staycool3_a,
Thanks for your reply.
Regarding:
Originally posted by staycool3_a View Postthanks Paul. I got it to work. I'm curious, do you think there is a way to edit the file while it's being used or is that some just not possible. used= it's being used by an indicator. i wish i could update the data while it's being used
Doing a quick search on the internet I found: https://stackoverflow.com/questions/...t-streamreader
Regarding, "strategy analyzer run using streamrreader = 46 seconds regular strategy analyzer test using data loaded as a instrument = 3 seconds" This would not be surprising given the coding involved. On each OnbarUpdate() the file is opened, the contents are searched line by line and each line is broken up to find a matching date, if found further processing occurs. The example is only intended to demonstrate a capability.Paul H.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Paul View PostHello staycool3_a,
Thanks for your reply.
Regarding:
I suspect you would generate an exception error. While we have provided courtesy example uses of StreamReader and StreamWriter, these are not Ninjascript methods and further information would be outside our area of support. You can find more about the streamreader here: https://docs.microsoft.com/en-us/dot...ramework-4.7.2
Doing a quick search on the internet I found: https://stackoverflow.com/questions/...t-streamreader
Regarding, "strategy analyzer run using streamrreader = 46 seconds regular strategy analyzer test using data loaded as a instrument = 3 seconds" This would not be surprising given the coding involved. On each OnbarUpdate() the file is opened, the contents are searched line by line and each line is broken up to find a matching date, if found further processing occurs. The example is only intended to demonstrate a capability.
Comment
-
Hello staycool3_a,
If the data is what we have been discussing in this thread (OHLC bar data) then the only solution I could suggest would be to create a fake instrument and load your data into it. This would work with a stock instrument, it would work with a futures instrument (but you would have to create all the expiry months), it would not work with forex.
References:
Paul H.NinjaTrader Customer Service
Comment
-
I am writng a list to a cvs file
you need
Using System.IO;
public void writePullback()
{
string sDocumentFile = Path.Combine(Environment.ExpandEnvironmentVariable s("%userprofile%"), "Documents\\StrategyTradeFiles");
if (!Directory.Exists(sDocumentFile))
Directory.CreateDirectory(sDocumentFile);
string sTempString = "";
if (this.pivotList.Count > 0)
{
StreamWriter File = new StreamWriter(Path.Combine(Environment.ExpandEnviro nmentVariables("%userprofile%"), "Documents\\StrategyTradeFiles" + " " + Instrument.FullName + "Analysis.csv"));
for (int nTempCount = 0; nTempCount < this.pivotList.Count; nTempCount++)
{
sTempString = this.pivotList[nTempCount].PivotType.ToString() + "," +
this.pivotList[nTempCount].Time + "," +
this.pivotList[nTempCount].Ticks;
File.WriteLine(sTempString);
}
File.Close();
}
}
this function is for reading a list
public void ReadList(List<TradeInformation> TradeList)
{
string[] read;
char[] seperators = { ',' };
string sDocumentFile = Path.Combine(Environment.ExpandEnvironmentVariable s("%userprofile%"), "Documents\\MASTERTradeFile");
if (!Directory.Exists(sDocumentFile))
Directory.CreateDirectory(sDocumentFile);
string sPathName = Path.Combine(Environment.ExpandEnvironmentVariable s("%userprofile%"), "Documents\\MASTERTradeFile\\TradeList.csv");
if (File.Exists(sPathName))
{
StreamReader sr = new StreamReader(Path.Combine(Environment.ExpandEnviro nmentVariables("%userprofile%"), "Documents\\MASTERTradeFile1\\TradeList.csv")) ;
string data = sr.ReadLine();
read = data.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
DateTime tStartTime = DateTime.Parse(read[0]);
DateTime tEndTime = DateTime.Parse(read[1]);
double dStartPrice = double.Parse(read[2]);
double dEndPrice = double.Parse(read[3]);
this.TradeList.Add(new TradeInformation(tStartTime, tEndTime, dStartPrice, dEndPrice));
while ((data = sr.ReadLine()) != null)
{
read = data.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
tStartTime = DateTime.Parse(read[0]);
tEndTime = DateTime.Parse(read[1]);
dStartPrice = double.Parse(read[2]);
dEndPrice = double.Parse(read[3]);
this.TradeList.Add(new TradeInformation(tStartTime, tEndTime, dStartPrice, dEndPrice));
}
sr.Close();
}
}
Last edited by ballboy11; 10-15-2018, 09:39 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Jon17, Today, 04:33 PM
|
0 responses
1 view
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
5 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
||
Started by timmbbo, Today, 08:59 AM
|
2 responses
10 views
0 likes
|
Last Post
by bltdavid
Today, 04:10 PM
|
||
Started by alifarahani, Today, 09:40 AM
|
6 responses
41 views
0 likes
|
Last Post
by alifarahani
Today, 03:18 PM
|
||
Started by Waxavi, Today, 02:10 AM
|
1 response
20 views
0 likes
|
Last Post Today, 03:03 PM |
Comment