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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    65 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    149 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    99 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    286 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X