I'm trying to export OHLC data along with a few indicator values to a csv file. I've referenced the streamwriter indicator file here (https://ninjatrader.com/support/foru...xt-file?t=3475) and got it to work with just the OHLC data. But if I add an indicator value such as BuySellPressure.BuyPressure[0] I get 'BuySellPressure() is a method which is not valid in the given context'. I've tried a few different indicator plots all with similar results. This technique for exporting indicator values worked in NT7 but I cant seem to figure it out in NT8. Thanks.
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
using System.IO;
// Add this to your declarations to use StreamWriter
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class AStreamWriter : Indicator
{
private string path;
private StreamWriter sw; // a variable for the StreamWriter that will be used
protected override void OnStateChange()
{
if(State == State.SetDefaults)
{
Calculate = Calculate.OnBarClose;
Name = "Astream writer";
}
// 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;
}
}
else if(State == State.Configure)
{
path = "c:\\dataexport\\txt\\" + Instrument.FullName +".txt"; // Define the Path to our test file
}
}
protected override void OnBarUpdate()
{
sw = File.AppendText(path); // Open the path for writing
string data = (Time[0].ToString("MM/dd/yyyy;HH:mm:ss")) + ";" + Open[0] + ";" + High[0] + ";" + Low[0] + ";" + Close[0] + ";" + Volume[0] + ";" + BuySellPressure.BuyPressure[0];
sw.WriteLine(data);
sw.Close(); // Close the file to allow future calls to access the file again.
}
}
}

Comment