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

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
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by WHICKED, Today, 02:02 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by selu72, Today, 02:01 PM
    0 responses
    1 view
    0 likes
    Last Post selu72
    by selu72
     
    Started by f.saeidi, Today, 12:14 PM
    8 responses
    21 views
    0 likes
    Last Post f.saeidi  
    Started by Mikey_, 03-23-2024, 05:59 PM
    3 responses
    49 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Started by Russ Moreland, Today, 12:54 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X