I have downloaded a sample indicator for streamwriter in NT7 and wanted to use it in a multi time frame manner.
Here below the code. Its doesnt work at all when adding a PeriodeType. Any idea why???
protected override void Initialize()
{
CalculateOnBarClose = true;
Add(PeriodType.Day, 1);
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
double AtrZero;
if(ATR(1).Value.ContainsValue(0)) // checks whether the DataSeries contains a value
AtrZero = Math.Round(ATR(1).Value.Get(CurrentBar),2);
else
AtrZero = 0.0;
double AtrDay;
if(ATR(BarsArray[1],1).Value.ContainsValue(0))
AtrDay = Math.Round(ATR(BarsArray[1],1).Value.Get(CurrentBar),2);
else
AtrDay = 0.0;
try
{
if (CurrentBar == 0)
sw = File.AppendText(path);
sw.WriteLine(Time[0]+ " " + Time[0].DayOfWeek.ToString() + " " + AtrZero+ " " + AtrDay);
}
catch (Exception e)
{
Log("You cannot write and read from the same file at the same time. Please remove SampleStreamReader.", NinjaTrader.Cbi.LogLevel.Error);
throw;
}
}
protected override void OnTermination()
{
if (sw != null)
{
sw.Dispose();
sw = null;
}
}

Comment