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

On Render method error influenced by changes in other indicators.

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

    On Render method error influenced by changes in other indicators.

    I have an indicator that looks for a particular price movement pattern and, if found, plots an arrow indicating direction and a variable length rectangle to indicate a relevant range of price levels.
    When I loaded the indicator on a chart with no other indicators present, it plotted correctly. I then added an EMA to the chart, and that generated the following error message for my indicator:
    Error on calling ‘On Render’ method on bar 7169. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    The rectangle disappeared, leaving only the arrow.
    I then changed the color of the EMA line, which caused a recalculation of both indicators. The rectangle then reappeared and there was no error message. I then changed the thickness of the EMA line. Once again, the error message was generated, and the rectangle was removed. I then changed the color of the EMA line again and the rectangle reappeared, with no error message.
    I decided to check if the issue occurred with other indicators, so I removed the EMA from the chart. That caused the rectangle to disappear again with the same error message. I then added a Stochastic indicator to the chart, and the rectangle reappeared.
    Can you explain why making changes to the EMA and Stochastic would influence the success or failure of the On Render method in my indicator?
    How can I determine if the indicator is attempting to write to protected memory?

    ​Thanks in advance for any help.

    #2
    Hello Scotty33,

    Thank you for your post.

    So I may accurately assist you, please answer all of the following questions:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-22, AAPL, EURUSD, etc.
    • What interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
    • If you comment out the logic that draws the arrow and rectangle, do you still see the errors when adding/modifying/removing the EMA/Stochastic indicators? This should help to understand if the underlying cause has to do with how these objects are being drawn/rendered or if it is a different part of your code.
    • Are you creating these objects with the Draw() methods or with custom rendering logic in OnRender()?
    I look forward to your reply.

    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hello Emily,
      Thanks for your reply. Here are the answers to your questions:
      • v8.0.28.0 64-bit
      • CL 12-23
      • 30 seconds
      • When I comment out the OnRender section of the code, I don't see the errors. The arrows are still displayed, as they are plotted using Draw(), but the rectangles obviously don't appear..
      • For the arrows I use Draw() and for the rectangles I use custom rendering logic in OnRender().

        Let me know if you need more information.

      Comment


        #4
        Originally posted by Scotty33 View Post
        Hello Emily,
        Thanks for your reply. Here are the answers to your questions:
        • v8.0.28.0 64-bit
        • CL 12-23
        • 30 seconds
        • When I comment out the OnRender section of the code, I don't see the errors. The arrows are still displayed, as they are plotted using Draw(), but the rectangles obviously don't appear..
        • For the arrows I use Draw() and for the rectangles I use custom rendering logic in OnRender().

          Let me know if you need more information.
        Thank you for that information.

        The Best Practices for SharpDX Resources from the following page should be kept in mind:


        There is a note about the error you are receiving on that page as well:
        • "Critical: Attempting to use an object which has already been disposed can lead to memory corruption that NinjaTrader may not be able to recover. Attempts to use an object in this manner can result in an error similar to: Error on calling 'OnRender' method on bar 0: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
        I suspect this likely applies to your situation; you may be attempting to use a resource that has been disposed of. You can add checks whether something is disposed or not using the DisposeBase.IsDisposed property:

        The snippet from that page is as follows:
        Code:
        SharpDX.Direct2D1.Brush customDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue);
        
        
        // checks the object is not disposed of before using
        if(!customDXBrush.IsDisposed)
        {
          RenderTarget.DrawLine(startPoint, endPoint, customDXBrush);
          customDXBrush.Dispose();
        }
        ​
        After taking a look at those best practices and implementing whichever items apply to your situation with OnRender() for your rectangle, this should help to identify the cause and add a solution to prevent the errors you have been seeing.

        Please let us know if we may be of further assistance.
        Emily C.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        834 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,290 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        9 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        62 views
        0 likes
        Last Post halgo_boulder  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        8 views
        0 likes
        Last Post Option Whisperer  
        Working...
        X