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

Error: coding OutlineStroke of user-drawn Region Highlight X

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

    Error: coding OutlineStroke of user-drawn Region Highlight X

    I would like to be able to alter the appearance of a user-drawn object, but attempting to change the OutlineStroke throws fatal errors. Here's one, although I have seen others as well:
    Failed to call OnRender() for chart object 'Region Highlight X': 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
    Code:
    RegionHighlightX myReg = null ;
    foreach (DrawingTool drawTool in DrawObjects)
    {
        if(drawTool.GetType().Name.ToString() == "RegionHighlightX")
        {
            myReg = (RegionHighlightX)drawTool ;
    
            [COLOR="Purple"]myReg.OutlineStroke = new Stroke(Brushes.White, 1) [/COLOR];// *** this line throws fatal error
            myReg.AreaBrush = Brushes.White ;// ok
            myReg.AreaOpacity = 5 ;// ok
            myReg.ZOrder = -1 ; // ok
            myReg = null ; // ok
        }
    }
    if (myReg != null) myReg.Dispose() ;// all done
    Steps to reproduce:
    1. Add an indicator with the above code in OnBarUpdate to a TickReplay chart
    2. Press Shift+F1 and draw a Region Highlight X
    3. Press F5 to attempt a NinjaScript Reload
    Last edited by tradesmart; 12-26-2016, 06:41 AM. Reason: added steps to reproduce + TickReplay

    #2
    Hello tradesmart,

    I've made a script to test this and found that the outline cannot be set historically in OnBarUpdate or in OnStateChange when State is in any state before State.Realtime when refreshing the script but does show when first adding the script.
    I've submitted a bug report about this.

    However, I am finding I can change the outline when clicking a button, or when changing this from OnRender.

    Attached is an example that demonstrates.
    Are you getting any errors when testing the button?
    If you uncomment the code in OnRender, do you see any errors when running the code in OnRender()?
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Attached is an example that demonstrates.
      Are you getting any errors when testing the button?
      If you uncomment the code in OnRender, do you see any errors when running the code in OnRender()?
      Thanks, Chelsea, for testing this. No errors encountered with either the button or OnRender().
      So, until the bug is fixed, would you suggest that I move my code from OnBarUpdate to OnRender, or eliminate the OutlineStroke edit entirely?

      Comment


        #4
        Hello tradesmart,

        That would be my suggestion for the time being.

        If you want this to only happen once, use a bool to prevent the code from executing in OnRender() repeately.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks!

          What I've decided to do is temporarily surface a property to choose the calling method, OnRender or OnBarUpdate, and then edit the OutlineStroke only for an OnRender call. I have other code alongside the draw object mods that populates and/or updates a dictionary of the anchor bars, so it needs to happen repeatedly to synchronize with user manipulation of the draw object(s).

          I was using Calculate.OnEachTick, thinking that OnBarUpdate processing might be a little less resource-intensive than OnRender, but I have to use OnRender anyway for the indicator's real job, so I guess it's a moot point.

          Even so, is there a significant difference in resource usage for OnBarUpdate vs. OnRender?

          Comment


            #6
            Hello tradesmart,

            If the logic is not executed because of a bool, then you would not have to worry about performance.

            OnBarUpdate updates either on each tick, or price change, or bar close depending on the setting. OnRender updates when the chart renders (meaning something changed).

            OnRender is going to trigger more unless nothing is moving on the chart.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes, that confirms my empirical observation of how "busy" each is when connected:
              1. OnRender: very busy
              2. OnBarUpdate OnEachTick: busy, but less so
              3. OnBarUpdate OnPriceChange: less busy than OnEachTick
              4. OnBarUpdate OnBarClose: least busy of all

              With this in mind, I always try to use the least busy option that performs the necessary task adequately. So, too, with TickReplay; only if I really, really must have historical bi/ask tick data.

              Comment


                #8
                Hello tradesmart,

                Below is a link to the help guide on Calculate and OnRender so you can know what triggers these and how often the would trigger.

                Calculate - http://ninjatrader.com/support/helpG.../calculate.htm

                OnRender - http://ninjatrader.com/support/helpG...s/onrender.htm
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by nightstalker, 05-04-2024, 02:05 PM
                5 responses
                52 views
                1 like
                Last Post nightstalker  
                Started by MSerag, Yesterday, 11:52 PM
                0 responses
                6 views
                0 likes
                Last Post MSerag
                by MSerag
                 
                Started by DynamicTest, Yesterday, 11:18 PM
                0 responses
                3 views
                0 likes
                Last Post DynamicTest  
                Started by dcriador, Yesterday, 01:43 AM
                3 responses
                20 views
                0 likes
                Last Post dcriador  
                Started by smartromain, Yesterday, 10:50 PM
                0 responses
                5 views
                0 likes
                Last Post smartromain  
                Working...
                X