• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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
    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 Dan_D_Trader, Yesterday, 03:29 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by asmmbillah, Today, 12:06 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by babouin77, Yesterday, 08:56 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by EminiTrader, Today, 11:05 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by bosajin, Today, 05:43 AM
          1 response
          20 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X