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

ChartAnchor.UpdateFromPoint() returns unequal Y coordinates?

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

    ChartAnchor.UpdateFromPoint() returns unequal Y coordinates?

    Hello

    I am trying to use ChartAnchor.UpdateFromPoint() to draw perfectly horizontal ray cast price lines from a drawing tool using an endAnchor set to the same price as the startAnchor point. I am also rounding the excessive decimal places off.. So same times in should be same times out - perfect horizontal line right?

    Both anchor.GetPoint()s come back with equal Y values DrawingTool.GetExtendedPoint() returns a point with equal Y values. But once you use endAnchor.UpdateFromPoint() to copy it the new endAnchor extended out in time are not perfectly straight their prices come back at least 0.00002 different?

    Thus crooked ray casts. I have to manually correct endAnchor.UpdateFromPoint() result... is there a bug in ChartAnchor.UpdateFromPoint()?


    Code:
    protected void syncEdgeAnchor() {
        // "Tool" is a direct reference to a DrawingTool extended class.
        var startAnchor = Tool.StartAnchor;
        var endAnchor = Tool.EndAnchor;
        var chartControl = Tool.ChartControl;
        var chartPanel = Tool.ChartPanel;
        var chartScale = Tool.ChartScale;
    
        roundPrice( startAnchor );
        endAnchor.Price = startAnchor.Price;
    
        var startPoint = startAnchor.GetPoint( chartControl, chartPanel, chartScale );
        var endPoint = endAnchor.GetPoint( chartControl, chartPanel, chartScale );
        var edgePoint = /*Drawing*/Tool.GetExtendedPoint( startPoint, endPoint );
        var hideAnchor = IsRight() ? anchorWidth : -anchorWidth;
              edgePoint.X = edgePoint.X + hideAnchor;
    
        endAnchor.UpdateFromPoint( edgePoint, chartControl, chartScale );
    [B]// endAnchor.Price = startAnchor.Price; <--- I have to add this line to render perfectly straight lines.[/B]
    }
    
    protected static void roundPrice( ChartAnchor anchor ) {
        anchor.Price = Math.Round( anchor.Price, 5 );
    }
    Last edited by SmartArtsStudio; 05-17-2021, 11:27 PM.

    #2
    Hello SmartArtsStudio,

    Do you have a simplified test script that can demonstrate?

    Also, print the values after each of these lines to the output window, save these to a text file, and attach with your post so we can see at which point the numbers are becoming incorrect.
    https://ninjatrader.com/support/foru...121#post791121

    To confirm, you are expecting the startAnchor.GetPoint() and endAnchor.GetPoint() to be exactly the same, and these are not the same?

    Or is GetExtendedPoint() specifically returning different values for each of these?

    The Horizontal Drawing tool only uses one anchor point. So what logic is setting a second anchor point to the y value of the first anchor point? Is this being manually set with mouse clicks?

    Does your drawing tool need two anchor points? Could this instead be a horizontal line that extends only left or only right?


    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm
    Last edited by NinjaTrader_ChelseaB; 05-18-2021, 10:50 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea

      Similar Horizontal Drawing tool which takes the mouse click as the first startAnchor point copies the price to endAnchor then gives it the panel width for its X. I was copying this method originally but for some reason worked fine for for dragging but not for scrolling.
      This code does basically the same, takes the mouse click as the first startAnchor point copies the price to endAnchor, its X default 0 now makes 2 points on the same Y axis.

      I'm not using the NT8 editor while an excellent addition. I use Jetbrains Rider to debug so I can see everything at once.

      So it is ChartAnchor.UpdateFromPoint() specifically that takes in a price I have specifically rounded to 5 decimal places and returns a close price but also not rounded. The additional decimal places multiplied by time shows up not straight surprisingly quickly.

      I'm not too concerned about it because its fixed with one extra line of code and it just occurs to me now that it name is updateFromPoint not copyFromPoint but I do think the most peoples expectation will be copyFromPoint and thought I'd let you know in case that was the intended behavior.

      I am happy to use the provided export instructions to email it to you with the specific file name and line number to set your break point, and brief instructions that will have you trigger it in 3 clicks.

      Thanks



      Comment


        #4
        Hello SmartArtsStudio,

        The HorizontalLine class does not use the EndAnchor and sets the IsBrowsable of this to false. Only one anchor is used for the logic with this.

        UpdateFromPoint() is not used at all in the @Lines.cs file. Is this absolutely necessary for your script?

        Are you certain that the rounding is not causing the issue as this is changing the values?

        Please add prints for the behalf of sharing information.

        Print these values to the output window along with labels as demonstrated in the video linked in the post on using prints to understand behavior, and save this to a text file and post the text file with your reply.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea

          Yes you are correct about Horizontal Line. I was thinking start/endAnchor Points but typing anchors. 2 Points are used in render method cast of 1 anchor using panel width for second X..

          As I mentioned it is not a big concern because I can correct UpdateFromPoint() result once I have its X, and there are other ways to do this.
          I am just letting you guys know that I was surprised to find it does not copyFromPoint which is the implication of the name in case that was the intended behavior... it is doing something else

          Below you can follow the progress all the Y coordinates are equal. This isn't a particularly bad variation it fluctuates I have seen a larger and also a smaller variations.
          They may look insignificant in numbers but plot them against time they are not insignificant..

          Of course I am assuming GetPoint() is accurate... I have no way to compare Price to Co-ordinates.

          Click image for larger version  Name:	updateFrom_Problem.PNG Views:	0 Size:	138.1 KB ID:	1156534
          Last edited by SmartArtsStudio; 05-18-2021, 01:21 PM.

          Comment


            #6
            Hello SmartArtsStudio,

            In the logic I am seeing edgePoint is used for the UpdateFromPoint() call. This is a different object created with Tool.GetExtendedPoint() and may have a different value than startAnchor price.

            If the second Y value is not necessary, and the line is extended from a single point to the edge of the chart. Perhaps use only one anchor?

            Coordinate values can be converted to and from price with:

            Last edited by NinjaTrader_ChelseaB; 05-18-2021, 02:27 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by thanajo, 05-04-2021, 02:11 AM
            3 responses
            467 views
            0 likes
            Last Post tradingnasdaqprueba  
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            10 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,236 views
            0 likes
            Last Post sidlercom80  
            Started by thread, Yesterday, 11:58 PM
            0 responses
            4 views
            0 likes
            Last Post thread
            by thread
             
            Started by jclose, Yesterday, 09:37 PM
            0 responses
            9 views
            0 likes
            Last Post jclose
            by jclose
             
            Working...
            X