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 cmoran13, 04-16-2026, 01:02 PM
            0 responses
            43 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            25 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            162 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            98 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            157 views
            2 likes
            Last Post CaptainJack  
            Working...
            X