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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X