Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intermittent "Sequence contains no elements" error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Intermittent "Sequence contains no elements" error

    Hi NT Support,


    I would like to report that intermittently, once or twice a week. I run in to this exception below in an indicator that paints a shade in the chart for extended trading hours.

    The error comes from NT libraries.


    Time Category Message
    4/16/2020 2:25:36 PM NinjaScript OnBarUpdate Exception: System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.Max(IEnumerable`1 source) at NinjaTrader.Gui.Chart.ChartControl.get_PanelWidthP ixels() at NinjaTrader.Gui.Chart.ChartControl.get_CanvasRight () at NinjaTrader.Gui.Chart.ChartControl.GetXBySlotIndex (Double slotIndex) at NinjaTrader.Gui.Chart.ChartControl.GetXByBarIndex( ChartBars chartBars, Int32 barIndex) at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.C reateChartAnchor(NinjaScriptBase ownerNinjaScript, Int32 barsAgo, DateTime time, Double y) at NinjaTrader.NinjaScript.DrawingTools.Draw.Region(N injaScriptBase owner, String tag, Int32 startBarsAgo, DateTime startTime, Int32 endBarsAgo, DateTime endTime, ISeries`1 series1, ISeries`1 series2, Double price, Brush outlineBrush, Brush areaBrush, Int32 areaOpacity, Int32 displacement) at NinjaTrader.NinjaScript.DrawingTools.Draw.Region(N injaScriptBase owner, String tag, Int32 startBarsAgo, Int32 endBarsAgo, ISeries`1 series, Double price, Brush areaBrush, Int32 areaOpacity, Int32 displacement) at NinjaTrader.NinjaScript.Indicators.jPivots.OnBarUp date()

    Here is the code fragment:

    protected override void OnBarUpdate()
    {
    if (!isIntraday)
    return;

    try
    {
    (...)

    // Premarket/Extended High Low
    if (isPreMarketHours || isExtendedHours)
    {
    // Paint Extended Hours
    if (ChartControl != null && this.Count > 0)
    Draw.Region(this, "region" + CurrentBar, 0, -1, new Series<double>(this), ((double)0xFFFF), Brushes.LightCyan, 100);
    }

    (...)
    }
    catch (Exception ex)
    {
    NinjaScript.Log(String.Format("OnBarUpdate Exception: {0}", ex.ToString()), LogLevel.Error);
    }
    }

    Thank you!

    #2
    Hi jmneto, thank you for your post.

    From the snippet, it looks like the use of -1 for the endBarsAgo property is causing this problem. Doing that to plot into the future is not recommended. We recommend using SharpDX to draw into the future portion of a chart.

    We have an example here that demonstrates drawing a region with SharpDX:
    This indicator was ported from the Ichimoku Cloud indicator for NinjaTrader 7. The Cloud&#8217;s points are constructed identically to the NinjaTrader 7 indicator, however the points are then used to construct new SharpDX PathGeometry Figures. 3/24/2021: Modified the Adjust Chart Margins feature so users are prompted when the indicator wants to change the Chart&#8217;s Right [&#8230;]


    Please let me know if I can assist any further.

    Disclaimer:
    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    574 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X