On a website i found this code to create a bar counter indicator but it starts since the 1st bar. How can i change it so it reset to 0 on the 5 minute chart when the market opens?
namespace NinjaTrader.NinjaScript.Indicators
{
public class MyFirstIndicator : Indicator
{
#region Indicator Name / Description
private string iProductVersion = " v1.0.1";
private string iProductName = "My First Indicator";
private string iProductDescrption = string.Empty;
public override string DisplayName { get { return string.Format("{0} {1}", iProductName, iProductVersion); } }
#endregion
private double iOffset = 0;
private int iOffsetTicks = 1;
[NinjaScriptProperty]
[Display(Name = "01. Text Offset (ticks)", Description = "Description of input goes here", GroupName = "01. Indicator Parameters", Order = 1)]
public int OffsetTicks
{
get { return iOffsetTicks; }
set { iOffsetTicks = Math.Max(0, value); }
}
protected override void OnStateChange()
{
if(State == State.SetDefaults)
{
// Name / Description
Name = string.Format("{0} {1}", iProductName, iProductVersion);
Description = iProductDescrption;
// Visuals
IsOverlay = true;
IsAutoScale = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
BarsRequiredToPlot = 1;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ShowTransparentPlotsInDataBox = false;
ScaleJustification = ScaleJustification.Right;
// Misc
IsChartOnly = false;
Calculate = Calculate.OnBarClose;
IsSuspendedWhileInactive = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
}
else if(State == State.DataLoaded)
{
iOffset = iOffsetTicks * TickSize;
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < 0)
return;
if(IsFirstTickOfBar)
{
string xCB = CurrentBar.ToString();
if(CurrentBar % 2 == 0)
Draw.Text(this, "Even " + xCB, xCB, 0, High[0] + iOffset);
else
Draw.Text(this, "Odd " + xCB, xCB, 0, Low[0] - iOffset);
}
}
}
}
Comment