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

Custom DrawingTool disappears after refresh chart

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

    Custom DrawingTool disappears after refresh chart

    Hi, I made a custom drawing tool. When I refresh the chart the custom drawing tool disappears, but it still in the list of Draw Objects. It is likely not being initialized correctly after a refresh (F5). I see that OnStateChange() is called a few times but the Anchors are not set until the State == State.Terminated. I don't see any mention of this in the documentation either. How am I supposed to initalize a custom DrawingTool after a refresh?

    #2
    Hello habibalex,

    There may be something in your custom code causing an issue.

    Is there an error appearing on the Log tab of the Control Center with your custom script?

    When reloading the current instance is cloned, along with all DrawingTool class properties, and the previous instance is terminated. In the new clone are you seeing the SetDefaults state with the Building Drawing State?

    Are you seeing OnRender() is updating? What is the DrawingState in OnRender()?
    Are you seeing IsVisibleOnChart() is updating? What is the DrawingState in IsVisibleOnChart()?

    Below is a link to an example custom drawing tool. Are you able to reproduce with this?




    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      OnRender was updating as was IsVisibleOnChart. It looks like SetDefaults and Terminated states run in OnStateChange on a chart refresh.

      What I did was add a bool recreate variable and set that to true when State == State.SetDefaults runs. Then when IsVisibleOnChart runs and recreate == true I re-calculate my indicator. I'm making an accumulated VWAP so I need the chart bar data to recreate it. Is this the right way to approach this?

      Also, if a new bar is drawn on the chart, how do I trigger my drawing tool to recalculate or add the new bar to the calculation?

      Finally, MouseDown doesn't seem to trigger all the time on the left half of my chart, but it triggers consistently on the right half when clicking near the line. Is there some logic based on the Anchors to determine when to fire the overridden OnMouseDown?
      Last edited by habibalex; 01-25-2023, 08:48 PM.

      Comment


        #4
        Hello habibalex,

        The instance on the chart is cloned which hits State.SetDefaults, and the current instance is destroyed which hits State.Terminated.

        What I did was add a bool recreate variable and set that to true when State == State.SetDefaults runs. Then when IsVisibleOnChart runs and recreate == true I re-calculate my indicator.
        Is this the code causing the issue?
        If you comment out this code does the behavior stop?

        The anchors are transferred to the new clone.
        What needs to be recalculated in State.SetDefaults?
        (Note that the example provided does not do any calculations in State.SetDefaults)


        Also, if a new bar is drawn on the chart, how do I trigger my drawing tool to recalculate or add the new bar to the calculation?
        Drawing tools are not designed to work this way. These are meant to have anchors that are attached to specific bars and would not move themselves.
        Perhaps you want an indicator that updates on every bar and calls the drawing tool method?

        That said, there is no bar update method for drawing tools, as they are not intended to be updated unless an anchor is moved with the mouse.
        It would not be recommended to do so, but you could add a BarsRequest and do updates with Update event.
        https://ninjatrader.com/support/help...arsrequest.htm

        Is there some logic based on the Anchors to determine when to fire the overridden OnMouseDown?
        No, there is not. OnMouseDown is an event coming from Windows Operating System telling our program the mouse button is down (being clicked) and that our UI object is under that mouse button. It fires anytime the mouse is down on the object.
        It's the other way around, the script uses this to calculate if the mouse coordinates are within the selection point area in the GetSelectionPoints() override.

        MouseDown doesn't seem to trigger all the time on the left half of my chart, but it triggers consistently on the right half when clicking near the line.
        With OnMouseDown, is your print at the top of the method outside of any conditions?

        Can you reproduce this with the example I provided you?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          For anyone that has this issue: The main error ended up being IsVisibleOnChart was not returning true causing it to disappear.

          Also, keep track of the number of bars you've calculated. Call GetAttachedToChartBars() to get the Bars series on the chart and update when bar length return is greater than the number of bars you calculated

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          938 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          3 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          2 views
          0 likes
          Last Post rocketman7  
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Working...
          X