Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnRender event error

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

    OnRender event error

    I have a strategy which displays drawing objects to the screen such as trendlines using SharpDX in the OnRender() event.

    The methods that are invoked in OnRender() are surrounded by try catch blocks to avoid an exception causing the strategy to crash.

    The following error occurred causing the strategy to disable while running in simulation trading mode:
    04/06/2021 15:25 Default Disabling NinjaScript strategy 'MNQInfinity3EngineRealtimeStrategyMLNet4Gradient/234252824'
    04/06/2021 15:25 NinjaScript Failed to call OnRender for 'MNQInfinity3EngineRealtimeStrategyMLNet4Gradient' : 'Index was outside the bounds of the array.'
    The code for OnRender() is shown below, Please advise on where the error causing the crash may have occured.


    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    if (CurrentBar < 20)
    return;

    if (State == State.Historical)
    return;

    if (Bars == null || chartControl == null)
    return;

    if (!IsVisible)
    return;

    // RenderTarget is always full panel, so we need to be mindful which sub ChartPanel we're dealing with
    // always use ChartPanel X, Y, W, H - as ActualWidth, Width, ActualHeight, Height are in WPF units, so they can be drastically different depending on DPI set

    if (!IsInHitTest)
    {

    previousAntialiasMode = RenderTarget.AntialiasMode;

    try
    {

    DrawRenkoSignals(chartControl, chartScale);
    }
    catch (Exception ex)
    {
    LogOnRenderErrors(string.Concat("DrawRenkoSignals: ", ex.Message, " Time = ", DateTime.Now.ToString()));

    }

    try
    {

    DrawBullishEnd(chartControl, chartScale);
    }
    catch (Exception ex)
    {
    LogOnRenderErrors(string.Concat("DrawBullishEnd:", ex.Message, " Time = ", DateTime.Now.ToString()));

    }

    try
    {

    DrawBullishPB(chartControl, chartScale);
    }
    catch (Exception ex)
    {
    LogOnRenderErrors(string.Concat("DrawBullishPB:", ex.Message, " Time = ", DateTime.Now.ToString()));

    }

    try
    {

    DrawBearishEnd(chartControl, chartScale);
    }
    catch (Exception ex)
    {
    LogOnRenderErrors(string.Concat("DrawBearishEnd:", ex.Message, " Time = ", DateTime.Now.ToString()));

    }

    try
    {

    DrawBearishPB(chartControl, chartScale);
    }
    catch (Exception ex)
    {
    LogOnRenderErrors(string.Concat("DrawBearishPB:", ex.Message, " Time = ", DateTime.Now.ToString()));

    }

    try
    {

    DrawDottedLines(chartControl, chartScale);
    }
    catch (Exception ex)
    {
    LogOnRenderErrors(string.Concat("DrawDottedLines:" , ex.Message, " Time = ", DateTime.Now.ToString()));

    }





    RenderTarget.AntialiasMode = previousAntialiasMode;
    }

    base.OnRender(chartControl, chartScale);


    }


    #2
    Hi mballagan, thanks for your post.

    The exception is likely coming from one of the methods that you have called in OnRender. If you use Visual Studio debugging and cause this exception to happen while visual studio is attached to the NinjaTrader process and it should break at the exact line causing the exception:

    https://ninjatrader.com/support/help..._debugging.htm

    Best regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X