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 NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    48 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X