Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing Tool : disappear on color change.

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

    Drawing Tool : disappear on color change.

    Hello Team NT8.

    I am developing a drawing tool and everything working fine as expected.

    But when i try to change the Drawing Tool's color , width or dashstyle from Drawing Tool Object Properties window, instance of drawing tool object from chart disappear , though its name in property dialogue window still remain visible.

    What can be the reason for this ?
    Devdas
    NinjaTrader Ecosystem Vendor - Devdas

    #2
    Ok,

    Got resolved.

    Error was in OnRender() on color/width/dashstyle change.

    That lead me to think that logic behind drawing tool creation had to repeat in OnRender() also to reevaluate Anchors values on color/width/dashstyle change. Added the code lines for logic in OnRender() corrected the behavior.

    Is this supposed to do like this ?
    I see this in Regression Tool's OnRender() method also.
    Devdas
    NinjaTrader Ecosystem Vendor - Devdas

    Comment


      #3
      Hello devdas,

      The lines do need to be drawn each time OnRender is called or they would disappear.

      The RegressionChannel anchors are updated by using the mouse. Once the anchors are set, each time on render is called (such as when the chart is scrolled or the range or scale changes) the x and y points do need to be recalculated based on where the chart has been scrolled to so that the lines for the regression channel are rendered in the correct place.

      If the RegressionChannel did not update the x and y values the drawing object would not scroll with the chart.

      The brushes for the lines are saved within Stroke objects and are re-supplied to the DrawLine() call but are not recreated with each render pass but are instead set in OnStateChange when the State is State.SetDefaults (or when the user sets them).


      (A temporary brush is used to do a hit test which happens when the user clicks on the chart and tells the object that it is selectable)


      Can you clarify which logic you are referring to that is used in the RegressionChannel that causes an error?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post

        Can you clarify which logic you are referring to that is used in the RegressionChannel that causes an error?
        I am not saying any error in Regression Channel.

        My Drawing Tool is on similar code structure as Regression Channel , in which Anchors are re-calculated from bars object on each mouse move. So all that part scrolling, scaling and mouse move works fine with my tool. It was disappearing only when trying to change color/width/dashstyle from Object Property Window. I am using a Path Geometry to draw my Drawing Object.

        I saw the line in Regression Channel's OnRender() method as below

        Code:
        // get a list of new y positions for each line in the channel
        			Point[] regressionPoints = CreateRegressionPoints(chartControl, chartScale);
        			if (regressionPoints == null)
        				return;
        Call to CreateRegressionPoints() here, (when it has been already called in SetAnchorsToRegression() via OnMouseDown and OnMouseMove) , seems unnecessary. But when i added similar Anchor recalculation code in my Drawing Tools OnRender() then disappearing behavior on color/width/dashstyle change corrected.

        So is call to CreateRegressionPoints() here in OnRender() indirectly force handles the Color/width/DashStyle change ?
        Last edited by devdas; 01-04-2016, 02:59 PM.
        Devdas
        NinjaTrader Ecosystem Vendor - Devdas

        Comment


          #5
          Hello devdas,

          There is a difference between setting the anchors to a time (so that as you move the chart the time on these stay the same), and then getting the x and y values of where those anchors are moved to on the chart.

          When you render something you will only have the x and y coordinates. If you used the same x and y coordinates as you rendered each time a drawing object would never move. As the chart is scrolled, the x and y values need to be given for where those anchors are on the chart. However, most drawing objects will not move the anchor points. They will only return the x and y values of the already set anchor points. This would be how the line, or trend channel, or gannfan, etc..., work.

          The RegressionChannel specifically is more complicated than that. This drawing tool is unique in that as you move the object left and right, the y value of each end point as well as the distance from the center changes. The CreateRegressionPoints is logic to calculate where the anchor points will be moved to on the y axis when the object is moved. This is based on the data on the chart. This has to move both the anchors based on the regression calculation as well as set the x and y values for the end points on all 3 lines. The outer lines also have to have a calculated distance from where the inner line is that changes based on the data within the end point anchors.

          The line tool does not do any of that.

          So, if your script needs to calculate where the anchors are moved to, then yes you would need code to move the anchors. If your script is not going to calculate a new y position for the anchors based on the data on the chart, then no, you do not need to reset the anchors.
          Last edited by NinjaTrader_ChelseaB; 01-04-2016, 03:45 PM.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post

            There is a difference between setting the anchors to a time (so that as you move the c
            So, if your script needs to calculate where the anchors are moved to, then yes you would need code to move the anchors. If your script is not going to calculate a new y position for the anchors based on the data on the chart, then no, you do not need to reset the anchors.

            Hello ChelseaB,

            I understand what you are emphasizing on recalculation of Anchors and infact similar complexity in Anchors is in my Drawing Tool as in Regression channel.

            I noticed a small difference between Regression Channel and My Drawing Tool in deciding the Anchor's location. Regression Channel is using local array in calculating regression points each time whenever it needed. But i have used a global dictionary to fill the detail of anchor's location.

            Now here is another difference between Regression Channel and my Tool. Regression Channel and all available Drawing tool more or less use fix number of Anchors ( StartAnchor, MiddleAnchor(optional) and EndAnchor ) which are IEnumerable. But my Drawing tool dont know in advance how many Anchors will be needed to draw the drawing tool ( Hence i cant IEnunerate my Anchors in advance) . So it uses a supporting Dictionary which used to hold and add newly created Anchors during the Building/Editing/Moving process. Because it is global dictionary , it never need to call recalculation logic explicitly in OnRender(). And hence this was perfect and working fine.

            But problem arose as i said, on changing the Color/Width/DashStyle of Drawing Tool which gets corrected only when i explicitly call recalculation logic in OnRender().

            I have attached a pic of my drawing tool code showing relevant parts of code, please have look and tell me why i needed recalculation logic in OnRender().
            Attached Files
            Devdas
            NinjaTrader Ecosystem Vendor - Devdas

            Comment


              #7
              devdas,

              In the RegressionChannel, changing the anchor points does not change the UpperChannelStroke.BrushDX, UpperChannelStroke.Width, or upper channel UpperChannelStroke.StrokeStyle.

              The vector will change if your end points change.

              If you have multiple segments to your object you will need multiple rendered lines.


              However, I'm not sure that changing a brush, width float, or strokeStyle, would have anything to do with the number of anchors there are.

              Is the error occurring when calling RenderTarget.DrawLine?

              What is the error you are getting?
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kevinenergy, 02-17-2023, 12:42 PM
              117 responses
              2,766 views
              1 like
              Last Post jculp
              by jculp
               
              Started by Mongo, Today, 11:05 AM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by traderqz, Today, 12:06 AM
              9 responses
              16 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by SightCareAubetter, Today, 12:50 PM
              0 responses
              2 views
              0 likes
              Last Post SightCareAubetter  
              Started by Skifree, Today, 03:41 AM
              5 responses
              14 views
              0 likes
              Last Post Skifree
              by Skifree
               
              Working...
              X