I cannot understand why NT8 continues to say "BarsPeriodTime.Minute doesn't exist in current context" can you help me please?
//
// Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Xml.Serialization;
#endregion
// Add this to your declarations to use StreamWriter
using System.IO;
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class SampleStreamWriter : Indicator
{
private string path;
private StreamWriter sw; // a variable for the StreamWriter that will be used
private double myadx = 0;
protected override void OnStateChange()
{
if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Minute, 1440);
}
else if(State == State.SetDefaults)
{
Calculate = Calculate.OnBarClose;
Name = "Sample stream writer";
path = NinjaTrader.Core.Globals.UserDataDir + "MyExportFile.txt"; // Define the Path to our test file
}
// Necessary to call in order to clean up resources used by the StreamWriter object
else if(State == State.Terminated)
{
if (sw != null)
{
sw.Close();
sw.Dispose();
sw = null;
}
}
}
protected override void OnBarUpdate()
{
if (ToDay(Times[0][0]) != ToDay(Times[0][1]))
{
sw = File.AppendText(path); // Open the path for writing
sw.WriteLine(ToDay(Times[0][0]).ToString("dd/MM/yyyy") + ";" + ToTime(Times[0][0]).ToString("HH:mm:ss") + ";" + ADX(5)[0]); // Append a new line to the file
sw.Close(); // Close the file to allow future calls to access the file again.
}
}
}
}

Comment