Congestion zone include at least 3 candle sticks that the next candle has an opening and closing price within the previous candle
it gets compiled but i get error in logs
error on calling onbarupdate method on bar 12, index was outside of the bounds of array
how do i go about it?
thank you
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class congestionbox : Indicator
{
private double[] closingPrices = new double[0];
// private double[] aCZ = new double[0];
private bool congestionCondtion;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "congestionbox";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
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;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 10 )
return;
#region congestion
congestionCondtion = (Close[1] >= Low[2] && Close[1] <= High[2] && Open[1] >= Low[2] && Open[1] <= High[2]);
Print("congestionCondtion"+congestionCondtion + Time[0]);
if(congestionCondtion)
{
closingPrices.SetValue(Open[1], closingPrices.Length);
closingPrices.SetValue(Close[1], closingPrices.Length);
}
else if (closingPrices.Length < 6)
{
closingPrices = new double[0];
}
if (closingPrices.Length >= 6 && !congestionCondtion)
{
double maxCP = closingPrices.Max();
double minCP = closingPrices.Min();
Draw.Rectangle(this, "CongestionZone", closingPrices.Length/2, minCP - TickSize, 1, maxCP + TickSize, Brushes.Blue);
closingPrices = new double[0];
}
#endregion
}
}
}

Comment