Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get strategy to get the ray price of the current bar.

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

    Get strategy to get the ray price of the current bar.

    Hello,

    I have found examples to get a strategy to detect manually drawn lines/rays/etc, and to get the price of the start/end anchors of a ray, but I haven't been able to figure out how to get the price of a manually drawn ray at the current bar. Any help would be greatly appreciated!

    Thank you.

    #2
    Hello RobotSyndicate,

    Thanks for your post.

    You would need to use the start and end anchor points of the ray and then calculate, on a bar by bar basis the price value of the ray using the slope of the ray. Here is a link to a forum thread that has a demonstration of this process: https://ninjatrader.com/support/foru...-the-drawn-ray

    Comment


      #3
      Thank you for the tips. Now I am trying to get the price of the anchors for the manually drawn ray as follows:

      if (DrawObjects["UpperTrendLine"] != null && DrawObjects["UpperTrendLine"] is DrawingTools.Ray)
      {
      upstartBarPrice = UpperTrendLine.StartAnchor.Price;
      upendBarPrice = UpperTrendLine.EndAnchor.Price;
      }

      and when I compile is tells me that the name 'UpperTrendLine' does not exist in the current context, I assume because it is supposed to be a manually drawn line. Am I doing this incorrectly? Or how can I compile this?

      ALSO, I'm trying to calculate the slope of the manually drawn ray to project a price that I adjust a MIT order along. I cant figure out how get how many bars ago the anchors are. I see that <ChartAnchor>.BarsAgo does not work for manually drawn rays. I am using tick bars, so i don't believe that <ChartAnchor>.Time would be helpful... Is there another way to do this?


      Thanks again!
      Last edited by RobotSyndicate; 03-18-2020, 02:27 AM.

      Comment


        #4
        Hello RobotSyndicate,

        Thanks for your reply.

        To answer both questions, here is an example you can test with of looping through the draw objects collection, then if a specific name ("RayMine"), to then create a temp draw object to pull the start/end info from.

        Code:
                protected override void OnBarUpdate()
                {
                    foreach (DrawingTool draw in DrawObjects.ToList())
                      {                
                        if (draw.Tag == "RayMine")
                        {
                            DrawingTools.Ray temp = draw as DrawingTools.Ray;
        
                                Print("startYPrice: " + temp.StartAnchor.Price); 
                                Print("startXTime: " + temp.StartAnchor.Time);
                                Print("startXBarsAgo: " + (CurrentBar - temp.StartAnchor.SlotIndex)); // works for manual or script drawn!
                                Print("endYPrice: " + temp.EndAnchor.Price);
                                Print("endXTime: " + temp.EndAnchor.Time);
                                Print("endXbarsago: " + (CurrentBar - temp.EndAnchor.SlotIndex)); 
                        }
                    }
                }

        Comment


          #5
          Thank you SO much! This is exactly what I needed. 10/10!

          Comment


            #6
            Hi PaulH,
            When I run the code in your Post #4, I get this error msg: Object reference not set to an instance of an object. Running in NT8, 8.1.3.1 64-bit.
            Pls help, TQ.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            110 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            59 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            37 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            41 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            78 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X