Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get the price from the drawn ray

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

    Get the price from the drawn ray

    Good day
    I programmed a ray drawing! The question is how can I get these prices relative to the bar by the rays?
    preferably would like to see an example implementation
    Thank !

    #2
    Hello oscsoft,

    Thanks for your post.

    To determine the price level of the ray, on each bar after the ray has been drawn, you would need to project where the ray will be. You can do this by using the slope of the ray to calculate the run rate. I've created an example indicator to show a ray being drawn and then calculating its price level and then drawing a dot at that price level to visually confirm. You will need to apply the indicator to a live chart. I've also added a screenshot of what to expect.


    Click image for larger version

Name:	Yprojectedline.PNG
Views:	418
Size:	37.5 KB
ID:	1053525


    [ATTACH]n1053526[/ATTACH]
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      thank you very much
      that's what I need

      Comment


        #4
        I changed the code of the provided ninjascript "YAxisProjectionOfLine" to work on logarithmic values. But as you can see in the picture the yellow dots do not match the ray. What is the problem here?

        I am aware that log values become negative below one. But the ray and the yellow dots start diverging way above one.

        How can I get the current ray value if the scale is set to log scale?

        Click image for larger version

Name:	Log.png
Views:	277
Size:	170.8 KB
ID:	1204235

        Code:
        public class YaxisProjectionofLine : Indicator
            {
                private int x1Bar, x2Bar, x1bbar;
                private double y1, y2;
                private bool doItOnce = true;
                private int distance = 50;
        
                ...
        
                protected override void OnBarUpdate()
                {
                    if (CurrentBar < distance)
                    {
                        return;
                    }
        
                    if (doItOnce)  // on the first live bar, draw a ray starting from the low 5 bars ago to the high of the current bar
                    {
                        x1Bar   = distance;
                        x2Bar = 0;
                        y1      = Low[distance];
                        y2      = Low[0];
                        x1bbar  = CurrentBar - distance;
                        Draw.Ray(this, "test" + CurrentBar, true, x1Bar, y1, x2Bar, y2, Brushes.Magenta,
                            DashStyleHelper.Solid, 2);
                        doItOnce = false;
                    }
        
                    if (!doItOnce)
                    {
                        // First calculate slope of line
                        double runrate = (y2 - y1) / distance;
                        double runrateLog = (Math.Log10(y2) - Math.Log10(y1)) / distance;
                        // Now project the slope to new bar
                        double projecty = runrate * (CurrentBar - x1bbar);
                        double projectyLog = Math.Pow(10, runrateLog * (CurrentBar - x1bbar));
                        // to demonstrate that we know where the ray line is
                        // Linear
                        //Draw.Dot(this, "t1" + CurrentBar, true, 0, projecty + y1, Brushes.Red);
                        //Draw.Line(this, "line1", true, CurrentBar - x1bbar, y1, 0, projecty + y1,
                        //  Brushes.Red, DashStyleHelper.Dash, 3);
                        // Log
                        Draw.Dot(this, "t1Log" + CurrentBar, true, 0, projectyLog * y1, Brushes.Gold);
                        Draw.Line(this, "line1Log", true, CurrentBar - x1bbar, y1, 0, projectyLog * y1,
                            Brushes.Lime, DashStyleHelper.Dash, 3);
                        // so to test for price crossing the ray, you would use the projecty + y1 as the Y value to test
                        // for example if (Close[0] > (projecty+y1)
                    }
                }
            }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mattbsea, Today, 05:44 PM
        0 responses
        4 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        31 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,282 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        20 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Working...
        X