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

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
    Paul H.NinjaTrader Customer Service

    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)); 
                        }
                    }
                }
        Paul H.NinjaTrader Customer Service

        Comment


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Tim-c, Today, 02:10 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          2 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          50 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          10 responses
          399 views
          1 like
          Last Post beobast
          by beobast
           
          Started by lorem, Yesterday, 09:18 AM
          5 responses
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X