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

Attempted to read or write protected memory. This is often an indication that other m

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

    Attempted to read or write protected memory. This is often an indication that other m

    I am getting the following error and have exhausted all ideas on what might be the issue:

    Code:
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    I have attached an export of the Indicator. It's an attempt at a function to draw candlesticks.
    Attached Files
    Last edited by swcooke; 09-04-2018, 08:15 AM.

    #2
    Hello swooke,

    Thanks for your post.

    This error is typically seen with an issue with SharpDX resource management. At first glance, I see that you are (re)creating brushes in OnRenderTargetChange() and then disposing them immediately after. Brushes should be disposed of and then recreated in OnRenderTargetChange().

    If you do not wish to re-use brushes (advised best practice) and create the brushes in OnRender() before they are used, the brushes would need to be disposed of at the end of the OnRender() pass.

    I've provided links to further reading on SharpDX rendering and an example which draws candlesticks which could be used for further direction.

    SharpDX Rendering - https://ninjatrader.com/support/help..._rendering.htm

    HeikenAshi8 - https://ninjatrader.com/support/foru...tid=-1&lpage=1

    Additional examples on re-using SharpDX brushes can be found here - https://ninjatrader.com/support/foru...144#post509144

    Please let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      On a related note, I noticed that the HeikenAshi example you provided uses, for example, this for a down bar color:

      Code:
      [XmlIgnore]
      [Display(Name="BarColorDown", Description="Color of Down bars", Order=2, GroupName="Visual")]
          public Brush BarColorDown
         { 
           get { return barColorDown;}
           set { barColorDown = value;}
      }
      I am using this:

      Code:
        [XmlIgnore]
        [Display(Name = "Down Candle", GroupName = "Technology(XLK)", Order = 2)]
        public System.Windows.Media.Brush XlkDownCandleBrush {
          get {
           return xlkDownCandleBrush;
          }
          set {
           xlkDownCandleBrush = value;
           if (xlkDownCandleBrush != null) {
            if (xlkDownCandleBrush.IsFrozen) {
             xlkDownCandleBrush = xlkDownCandleBrush.Clone();
             xlkDownCandleBrush.Freeze();
            }
           }
          }
         }
      Is all of the complexity in my set block really needed? I realize the example shared was for example purposes but which way is correct for a production indicator?

      Comment


        #4
        Hello swooke,

        You may observe the syntax the NinjaScript code generators create for Brush properties for a minimalist implementation.

        For example, right click on the indicators folder in the NinjaScript Editor and select New Indicator. From the New Indicator Wizard, add a Brush property under Input parameters and then click Generate.

        Further reading on the syntax generated for Brushes and how they can be serialized can be found in the tip article below. Serialization is necessary to save the Brush to xml files. (So they can be saved in Templates and Workspaces)

        User Defined Brushes - https://ninjatrader.com/support/help...lor_inputs.htm

        I've also included reference for working with brushes to better understand when a brush would need to be frozen.

        Working with Brushes - https://ninjatrader.com/support/help...th_brushes.htm

        Please let us know if we can be of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by llanqui, Yesterday, 10:29 AM
        2 responses
        15 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by llanqui, Yesterday, 11:10 AM
        2 responses
        22 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by thumper57, 05-11-2024, 04:30 PM
        12 responses
        36 views
        0 likes
        Last Post thumper57  
        Started by eladlevi, Today, 08:41 AM
        3 responses
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by FAQtrader, 04-25-2024, 12:00 PM
        9 responses
        150 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X