I would like to pull some data out of ninjatrader using StreamWriter with Market Analyzer. However, When I run the code Nothing happens but if I run the code on the Chart tap as an indicator it works.
Here is my StreamWriter Code.
protected override void OnStateChange()
{
if(State == State.SetDefaults)
{
Calculate = Calculate.OnPriceChange;
Name = "Sample stream writer";
path = NinjaTrader.Core.Globals.UserDataDir + "MyTestFile.txt";
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
}
// Necessary to call in order to clean up resources used by the StreamWriter object
else if(State == State.Terminated)
{
if (sw != null)
{
sw.Dispose();
sw = null;
}
}
}
protected override void OnBarUpdate()
{
/* 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
{
// If file at 'path' doesn't exist it will create the file. If it does exist it will append the file.
if (CurrentBar == 0)
sw = File.AppendText(@"C:\Data\"+ Instrument.MasterInstrument.Name+".csv");
//py2
// This is the output of all lines. The output format is as follows: Date Open High Low Close
sw.WriteLine(helpexample(Close)[0]);
}
catch (Exception)
{
// Outputs the error to the log
Log("You cannot write and read from the same file at the same time. Please remove SampleStreamReader.", NinjaTrader.Cbi.LogLevel.Error);
throw;
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "helpexample";
Calculate = Calculate.OnPriceChange;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
BarsRequiredToPlot = 0; // u need to put this here
AddPlot(new Stroke(Brushes.Firebrick, 2), PlotStyle.Line, "Line");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
Value[0] = (EMA(200)[0]);
}

No wonder no one saw this.
... Furthermore, I reinstalled NT8 beta and imported the original streamwriterNT8 . The same thing happens . When I go Market Analyzer load streamwriter. All I get is 3 dots "..." Nothing happens.
Comment