I'm trying to read dates from a txt file and put any single date in an array when opening the indicator.
This code OnStartUp should read the file and put dates into array:
protected override void OnStartUp() { if (File.Exists(path)) { /* The try-catch block is used for error handling. In this case it is used to ensure you only have one stream object operating on the same file at any given moment. */ try { // Sets the file the StreamReader will read from sr = new System.IO.StreamReader(path); string line; // Read lines while ((line = sr.ReadLine()) != null) { string [] arrayDate = line.Split(new Char[] {' '}); int Counter = 0; foreach(string s in arrayDate) { //put dates into array DateTime dt = DateTime.ParseExact(s, "dd/MM/yyyy",provider); arrayDateA[Counter] = new DateTime(dt.Year,dt.Month,dt.Day); Print(dt.ToString()+"---"+Counter.ToString()+"---"+arrayDateA[Counter].ToString()+"---"+dt.Year.ToString()); Counter++; } } sr.Close(); } catch (Exception e) { // Outputs the error to the log Log("You cannot write and read from the same file at the same time. Please remove SampleStreamWriter.", NinjaTrader.Cbi.LogLevel.Error); Print(e.ToString()); throw; } // If file does not exist, let the user know } else { Print("File does not exist."); } }
protected override void OnBarUpdate() { if (CurrentBar < 1) return; Print(arrayDateA[1].ToString()); }
Thanks.
Comment