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 rhyminkevin, Today, 04:58 PM
    4 responses
    52 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Started by iceman2018, Today, 05:07 PM
    0 responses
    5 views
    0 likes
    Last Post iceman2018  
    Started by lightsun47, Today, 03:51 PM
    0 responses
    7 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    14 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    50 views
    0 likes
    Last Post futtrader  
    Working...
    X