Here's code of the Indicator:
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Orange, "This_Is_Plot1");
AddPlot(Brushes.Orange, "This_Is_Plot2");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
for (int x = 0; FVG.Count < 5 && x < 256; x++)
{
try
{
if (High[x] > _curHigh) FAILS ON THIS CHECK
_curHigh = High[x];
if (Low[x] < _curLow)
_curLow = Low[x];
bool isDownGap = Low[x + 2] > High[x] && !FVG.ContainsKey(Low[x + 2]) && High[x] > _curLow && Low[x + 2] > _curHigh;
bool isUpGap = High[x + 2] < Low[x] && !FVG.ContainsKey(High[x + 2]) && Low[x] < _curHigh && High[x + 2] < _curLow;
//Print(string.Format("IsDownGap: {0} High[x]: {2} Low[x+2]: {1} Current Low{3}", isDownGap, Low[x + 2], High[x], _curLow));
//Print(string.Format("IsUpGap: {0} Low[x]: {2} High[x+2]: {1} Current High{3}", isUpGap, High[x + 2], Low[x], _curHigh));
//Print(string.Format("FVG Gap Count: {0}", FVG.Count()));
// if(FVG.Count==NumberofGaps-1 && (isDownGap || isUpGap))
// FVG.Remove(FVG.Keys.Last());
if (isDownGap)
{
Print(string.Format("IsDownGap: {0} High[x]: {2} Low[x+2]: {1} Current Low{3}", isDownGap, Low[x + 2], High[x], _curLow));
Draw.Ray(this, string.Format("DownGapUpper{0}{1}", FVG.Count, Bars.BarsPeriod.Value), x + 2, Low[x + 2], x + 1, Low[x + 2], false, _templateDown);
Draw.Ray(this, string.Format("DownGapLower{0}{1}", FVG.Count, Bars.BarsPeriod.Value), x + 1, High[x], x, High[x], false, _templateDown);
Draw.Rectangle(this, string.Format("DownGap{0}{1}", FVG.Count, Bars.BarsPeriod.Value), x + 2, Low[x + 2], x, High[x], false, _templateDown);
Value[0] = Low[x + 2];
Value[1] = High[x];
FVG.Add(Low[x + 2], High[x]);
}
}
Here's the Strat Code:
else if (State == State.Configure)
{
//AddDataSeries(Data.BarsPeriodType.Day, 1);
}
else if (State == State.DataLoaded)
{
_myfvg = TestFVGIndicator();
AddChartIndicator(_myfvg);
}
}
protected override void OnBarUpdate()
{
if(State == State.Historical) return;
Here's the error:
Exception was thrown in ICTFVG Message: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index, Stack Trace: at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
at NinjaTrader.Data.BarsSeries.GetLow(Int32 index)
at NinjaTrader.Data.Bars.GetLow(Int32 index)
at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)
at NinjaTrader.NinjaScript.Indicators.TestFVGIndicato r.OnBarUpdate() in e:\Documents\NinjaTrader 8\bin\Custom\Indicators\TestFVGIndicator.cs:line 70
Comment