Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,789 views
    0 likes
    Last Post aligator  
    Started by Jimmyk, 01-26-2018, 05:19 AM
    6 responses
    837 views
    0 likes
    Last Post emuns
    by emuns
     
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,293 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    13 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    11 responses
    63 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X