So
1/ why does it do this ?
2/ how do remove this issue in order to access my series just liek the regular OHLC ?
here is the error:
Print_0000000=14473 0 14473 14473
Print_1=14473 0 14473 14473
Print_2=14473 0 3936,5 3934,75 3936,5 3934,75
Indicator 'MyCustomIndicator': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
#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 MyCustomIndicator : Indicator
{
private Series<double> MY_CLOSE;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyCustomIndicator";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
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;
AddPlot(Brushes.Orange, "MY_PLOT");
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
MY_CLOSE = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
MY_FILLING(MY_CLOSE);
MY_FUNCTION(MY_CLOSE);
}
private void MY_FILLING(Series<double> MY_SERIES)
{
MY_SERIES[0]=Close[0];
}
private void MY_FUNCTION(Series<double> MY_SERIES)
{
if(CurrentBar<1)
{
Print("Print_0000000="+Bars.Count+" "+CurrentBar+" "+Close.Count+" "+MY_SERIES.Count);
};
Print("Print_2="+Bars.Count+" "+CurrentBar+" "+Close[CurrentBar+1]+" "+Close[CurrentBar]+" "+Close[0+1]+" "+Close[0]);
Print("Print_3="+Bars.Count+" "+CurrentBar+" "+Close[CurrentBar+1]+" "+Close[CurrentBar]+" "+Close[0+1]+" "+Close[0]+" "+MY_SERIES[CurrentBar+1]+" "+MY_SERIES[CurrentBar]+" "+MY_SERIES[0+1]+" "+MY_SERIES[0]);
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> MY_PLOT
{
get { return Values[0]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private MyCustomIndicator[] cacheMyCustomIndicator;
public MyCustomIndicator MyCustomIndicator()
{
return MyCustomIndicator(Input);
}
public MyCustomIndicator MyCustomIndicator(ISeries<double> input)
{
if (cacheMyCustomIndicator != null)
for (int idx = 0; idx < cacheMyCustomIndicator.Length; idx++)
if (cacheMyCustomIndicator[idx] != null && cacheMyCustomIndicator[idx].EqualsInput(input))
return cacheMyCustomIndicator[idx];
return CacheIndicator<MyCustomIndicator>(new MyCustomIndicator(), input, ref cacheMyCustomIndicator);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.MyCustomIndicator MyCustomIndicator()
{
return indicator.MyCustomIndicator(Input);
}
public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input )
{
return indicator.MyCustomIndicator(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.MyCustomIndicator MyCustomIndicator()
{
return indicator.MyCustomIndicator(Input);
}
public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input )
{
return indicator.MyCustomIndicator(input);
}
}
}
#endregion
PS: when I create a thread, I no longer have access to the toolbar to insert quotes, codes and so on. How do i get it back ?

Comment