Anyways this code was working very well, then eventually it would disappear from my charts. I tried recompiling the charts and reloading the ninjascript by pressing F5. It wouldn't work. I even tried a reset and repair of the database. I removed all ninja script assemblies so the list is clear.
Can anyone chime in on this?
#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.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class Breakout : Indicator
{
// #region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
// #endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
// Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
// Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// go long condition
if (Close[0] > Close[1])
{
if( Close[1] > Close[2] &&
Stochastics(7, 21, 3).K[0] > Stochastics(7, 21, 3).D[0]
&& AvgTimePerBar(.5,2).AverageTime[0] <=0.196
)
{
DrawArrowUp("Go long arrow" + CurrentBar, true, 0, Low[0] - 1, Color.Lime);
// DrawLine("Go long line" + CurrentBar, 3, Low[0], 0, Low[0], Color.Lime);
if ( AvgTimePerBar(.5,2).AverageTime[0] < 0.196)
{
DrawSquare("Go long" + CurrentBar, true, 0, Low[0] - 1, Color.Green);
}
}
}//if
// go short condition
else if (Close[0] < Close[1])
{
if (Close[1] < Close[2]
&& Stochastics(7, 21, 3).K[0] < Stochastics(7, 21, 3).D[0]
&& AvgTimePerBar(.5,2).AverageTime[0] <=0.196
)
{
DrawArrowDown( "Go short?" + CurrentBar, false, 0, High[0]+1 , Color.DarkRed);
// DrawLine("Go short line"+CurrentBar,3,GetCurrentBid(),0,GetCurrentBid(),Color.DarkRed);
if ( AvgTimePerBar(.5,2).AverageTime[0] < 0.196)
{
DrawSquare( "Go short square?" + CurrentBar, false, 0, High[0] + 1, Color.Orange);
}
}
}//else
}//on barupdate
#region Properties
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private Breakout[] cacheBreakout = null;
private static Breakout checkBreakout = new Breakout();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Breakout Breakout()
{
return Breakout(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Breakout Breakout(Data.IDataSeries input)
{
if (cacheBreakout != null)
for (int idx = 0; idx < cacheBreakout.Length; idx++)
if (cacheBreakout[idx].EqualsInput(input))
return cacheBreakout[idx];
lock (checkBreakout)
{
if (cacheBreakout != null)
for (int idx = 0; idx < cacheBreakout.Length; idx++)
if (cacheBreakout[idx].EqualsInput(input))
return cacheBreakout[idx];
Breakout indicator = new Breakout();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();
Breakout[] tmp = new Breakout[cacheBreakout == null ? 1 : cacheBreakout.Length + 1];
if (cacheBreakout != null)
cacheBreakout.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheBreakout = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.Breakout Breakout()
{
return _indicator.Breakout(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.Breakout Breakout(Data.IDataSeries input)
{
return _indicator.Breakout(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.Breakout Breakout()
{
return _indicator.Breakout(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.Breakout Breakout(Data.IDataSeries input)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.Breakout(input);
}
}
}
#endregion
Perhaps I made a change to the code and was forgetful about it. I feel like I don't know what I'm doing, but I have been testing this indicator on different settings and charts. It would always work up until now.

Comment