Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calc angle between two lines

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

    Calc angle between two lines

    Is it possible to code an indicator that will calculate the angle between a line drawn through the last 3 or 4 price bars and a second line drawn between two moving averages?

    Basically I will have two lines on the screen and wish to calculate the anlge between them.

    Been reviewing the forum but have not found anything that may help me understand how to do this.

    Thanks

    #2
    wmaria, it is certainly possible to code such an indicator if the lines are drawn programmatically (with NinjaTrader 6.5) and with NT7, it is possible to programmatically access user-drawn objects.

    Just because it is possible does not necessarily mean it will be easy though. You will have to determine how far the line travels in the x direction (time/bars) and the y direction (price) and then if you take the inverse tangent of how far the line travels in the y direction divided by how far it goes in the y direction you will get the angle of the slope of the line. The change in Y divided by the change in X is the slope.

    There is a function though built into NinjaTrader called Slope() which can do most of this for you if you can "fool" it by feeding it a data series. If not, you'll have to resort to using:
    Code:
    double radians = Math.Atan(slope)
    Last edited by NinjaTrader_Austin; 03-02-2010, 03:04 PM.
    AustinNinjaTrader Customer Service

    Comment


      #3
      The good news is, yes it can be done. The bad news is, if you are asking this question it is probably beyond your capabilities. (I'm not a programmer so don't look at me)

      Slope = Rise/Run

      Angle= ArcTangent of Slope

      Radians to Degrees =( 180/PI )

      Angle=((Radians to Degrees) *((Math.Atan(Rise / Run))/Ticksize)

      Rise= Value[0] – Value[X bars ago]

      Run= X bars ago

      If you wanted to calculate the Angle of the change in EMA(34) from 2 bars back;

      Angle = (((180/PI)*((Math.Atan ( (EMA(34)[0]-EMA(34)[2])/2)))/TickSize);

      Comment


        #4
        Hello

        any news about wmaria's request ?

        Comment


          #5
          ottoetre, ThatManFromTexas's reply is the exact set of steps you need to accomplish what wmaria wanted in the first post. I have nothing more to add; it is all there. Unfortunately his second sentence still stands true.
          AustinNinjaTrader Customer Service

          Comment


            #6
            Sample Code

            Originally posted by ThatManFromTexas View Post
            The good news is, yes it can be done. The bad news is, if you are asking this question it is probably beyond your capabilities. (I'm not a programmer so don't look at me)

            Slope = Rise/Run

            Angle= ArcTangent of Slope

            Radians to Degrees =( 180/PI )

            Angle=((Radians to Degrees) *((Math.Atan(Rise / Run))/Ticksize)

            Rise= Value[0] – Value[X bars ago]

            Run= X bars ago

            If you wanted to calculate the Angle of the change in EMA(34) from 2 bars back;

            Angle = (((180/PI)*((Math.Atan ( (EMA(34)[0]-EMA(34)[2])/2)))/TickSize);
            Attached is an indicator that graphs the angle of an EMA. Use this as a basis to write the indicator you want. Hope this helps.
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X