I'm getting an error when using Draw.Line or Draw.Ray. But, the indicator works great when using Draw.HorizontalLine. I have been using the indicator for a long time with no issue, because it was using Draw.HorizontalLine. When I decided to change it to use Draw.Ray it would always throw a System.NullReferenceException: error. It seems the issue is with any Draw command that uses int ...BarsAgo (X coor. inputs).
One thing to note, it is being used inside the OnPositionUpdate(object sender, PositionEventArgs e) event.
private void OnPositionUpdate(object sender, PositionEventArgs e)
{
if(e.Position.Instrument.FullName != this.Instrument.FullName) return;
int newPositionCount = GetPositionCount();
if(newPositionCount == 0) // THIS IS BROKEN. WAIT FOR NT TO FIX if (e.MarketPosition == MarketPosition.Flat)
{
CheckAccountRealizedProfitLoss(accountCurrent);
if(ShowBreakevenLine)
{
breakEven = 0;
RemoveDrawObject(BreakevenLineName);
}
}
else if(ShowBreakevenLine)
{
SetBreakEven(newPositionCount);
double per = (numberBarsOnChart * PercentageLengthChart/100);
int startBarsAgo = (int)Math.Round( per, 0);
Print(String.Format("numberBarsOnChart = {0} \t % of bars = {1} \tstartBarsAgo = {2}", numberBarsOnChart, per, startBarsAgo));
try
{ [B]Draw.Ray(this, BreakevenLineName, true, startBarsAgo, breakEven, 0, breakEven, Brushes.Gold); }
catch(Exception e)[/B]
{ Print("FTB: Draw.Ray - "+e.ToString()); }
}
}
Draw.HorizontalLine(this, BreakevenLineName, breakEven, Plots[0].Brush, Plots[0].DashStyleHelper, (int)Plots[0].Width);
What prints out is this...
BREAKEVEN = 30503
numberBarsOnChart = 67 % of bars = 33 startBarsAgo = 33
FTB: Draw.Ray - System.NullReferenceException: Object reference not set to an instance of an object.
at NinjaTrader.Data.BarsSeries.GetTime(Int32 index)
at NinjaTrader.Data.BarsSeries.GetSessionEndTime(Int3 2 index)
at NinjaTrader.Data.Bars.GetSessionEndTime(Int32 index)
at NinjaTrader.NinjaScript.TimeSeries.get_Item(Int32 barsAgo)
at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.C reateChartAnchor(NinjaScriptBase ownerNinjaScript, Int32 barsAgo, DateTime time, Double y)
at NinjaTrader.NinjaScript.DrawingTools.Draw.DrawLine TypeCore[T](NinjaScriptBase owner, Boolean isAutoScale, String tag, Int32 startBarsAgo, DateTime startTime, Double startY, Int32 endBarsAgo, DateTime endTime, Double endY, Brush brush, DashStyleHelper dashStyle, Int32 width, Boolean isGlobal, String templateName)
at NinjaTrader.NinjaScript.DrawingTools.Draw.<>c__Dis playClass5c.<Ray>b__5b()
at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.D rawToggledPricePanel[T](NinjaScriptBase owner, Boolean isDrawOnPricePanel, Func`1 drawAction)
at NinjaTrader.NinjaScript.Indicators.FastTraderButto ns.DrawBreakEven()
Do Draw commands have to be invoked on the data thread?
Thanks.

Comment