I create a strategy whose purpose is to write into text certain indicator values, in the example below - the "High" values.
However, I notice that the last bar indicator value is not printed. Therefore, I cannot get the latest reading, which is the most important.
Any idea how to solve it?
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
using System.IO;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Write Bar State
/// </summary>
[Description("Write Bar State")]
public class alvBarWriteBarState : Strategy
{
#region Variables
private bool bInit = true;
private string Inst = "";
private string path = "";
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
BarsRequired = 30;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (bInit)
{
Inst = Instrument.MasterInstrument.Name;
path = @"C:\Users\Celebes\Documents\NinjaTrader 7\db\barstate\" + Inst + ".csv";
File.WriteAllText(path, "Time,BarState" + Environment.NewLine);
bInit = false;
}
File.AppendAllText(path, ToDay(Time[0]) + "," + High[0] + Environment.NewLine);
}
#region Properties
#endregion
}
}

Comment