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

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 Radano, 06-10-2021, 01:40 AM
            20 responses
            616 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by Mizzouman1, Today, 07:35 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by i019945nj, 12-14-2023, 06:41 AM
            6 responses
            67 views
            0 likes
            Last Post i019945nj  
            Started by aa731, Today, 02:54 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by BarzTrading, Today, 07:25 AM
            0 responses
            3 views
            0 likes
            Last Post BarzTrading  
            Working...
            X