Announcement

Collapse
No announcement yet.

Coding Help - Calculate the angle of a line

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

  • Coding Help - Calculate the angle of a line

    EFS Guru,
    These questions are for you.
    1. I would like to calculate the slope (angle) of an imaginary line that (for example) connect the close of two bars (not necessarily adjacent), or - another example - a line that is formed by two points on a given study (say MACD), each point representing another candle (or bar).

    I guess the appropriate trig function to use would be tangent where we divide the y component (diff in the values between the two bars) by the x value (number of bars).

    In any case - since each type of bar (this or that symbol) or line (MACD Signal would return different values than - for example - Moving Average study) - how is this normalization handled?

    Guru, do you have some coding examples please.

    Another question: I wrote a script (not using the wizard) which is supposed to display an up or down arrow (image) when it decides it should. When I re-load it, it does the job but it does not refresh after each bar.

    When I used the verb DrawTextRelative, there was no problem (now this code is commented out).

    Thanks,

  • #2
    BeyMelamed

    Let me see if I understand correclty...

    You want to take the difference between two indicator values, like MA,0 and MA, -5 and divide them by the number of bars between them, in this case 5, and then take the tangent to get a slope? Maybe you want to get the slope of the MACD, 0 and MACD, -5 also.

    To simplify matters, why don't you just use the difference in the indicator values because this is directly related to the slope... bear with me for a second, ok?

    Let's say the difference in the ma's is 5 ticks in the underlying (over the number of bars you have selected). This is directly related to the aswer you will get for the tangent - every time you put 5 into the tangent equation you will get the same result.

    So I wonder why the slope is required, why not just use the indicator differences?

    Actually the difference will give you the velocity (distance over time) of the indicator movement - kinda the same as slope, no?

    PS _ I am struggling with the same issues myself in another project and wonder what you think of my ideas, thanks.

    Comment


    • #3
      I have and continue to have issues similar to using the angle. The idea is so easy, however, the angle is related to your frame of reference. Maybe a good frame of reference is the number of bars between the previous hi and low, and the price difference between the high and low. Therefore, you have a frame of reference for that time frame.

      Here is something else you may want to consider. The most popular Gann angle is 1:1, ref Gann, which is 45 degrees.

      Given that, and the previous bar values and the prices at the major high and lows, would those values be, by default, a 45 degree angle? After all, you can make the price and the time reference in your chart anything you want, so what is the real angle?

      These are some thoughts.

      Regards,

      Steve

      Comment


      • #4
        To add something, I use the slope extensively Dave. Converting to an angle takes it out of context somewhat. Slope is very well defined, as a change in value over time. What I use is a Least squares function (Regression) to calculate slope. Here is a copy

        Regards,

        Steve

        Comment

        Working...
        X