I'v tried to use the OnStartUp() method in my UserDefinedIndicatorMethods file, but it doesn't work since it seems to be called after the OnBarUpdate() method is called by usual indicators.
I have created a custom method that uses a List that I would like to get populated only once "on start up" before this method is called by any indicator. How can I trigger a single call "on start up" (to another custom method) that parses my input textfile to the List?
A second question is if it's ok to use StreamReader in a method as shown in the outline below?. Is it correct to Dispose StreamReader at the end of the method?
using System.Collections.Generic;
using System.IO;
#endregion
namespace NinjaTrader.Indicator
{
partial class Indicator
{
private List <HolidaySession> holidaySessionList; // Declare variable to store List
private string holidaySessionTextFile2012 = "HolidaySessionLists2012.txt"; // Input text file name
protected override void OnStartUp()
{
// Call method to populate holidaySessionList
holidaySessionList = ParseHolidaySessionInputTextFile(holidaySessionTextFile2012);
}
// Method to parse input text file
public List<HolidaySession> ParseHolidaySessionInputTextFile(string fileName)
{
List<HolidaySession> holidaySessionListTemp = new List<HolidaySession>();
System.IO.StreamReader sr = new System.IO.StreamReader(fileLocation);
// Loop to parse text file
// Disposes resources used by the StreamReader
if (sr != null)
{
sr.Dispose();
sr = null;
}
return holidaySessionListTemp;
}
// Get Holiday Adjusted Session Begin and End Time in Local Time Zone
public void SessionGetNextTrueBeginEnd(DateTime day, out DateTime sessionBegin, out DateTime sessionEnd)
{
//List <HolidaySession> holidaySessionList is built in OnStartup()
}
}
}
posieidon_sthlm

Comment