Good Slope Equation?

Discussion in 'App Development' started by Canoe007, May 26, 2013.

  1. Canoe007

    Canoe007

    What are the options for calculating the Slope of an indicator?

    How many periods do you like to have it look at?
     
  2. (Not sure if serious)

    OK I'll bite. You take 2 adjacent samples of the indicator. If the first value is 2 and the next value is 3 then the slope between these points is 3-2=1 (assuming that 1 tick on the x axis is weighted with 1).

    If both values are 2 then the slope is 2-2=0

    If I were Jack Hershey I'd suggest taking the derivative of the indicator at that point.
     
  3. vicirek

    vicirek

    for line formula y=mx+b slope is m=y2-y1/x2-x1 between points (x1,y1) and (x2,y2) where x would be either index or time (probably transformed to integer or some other value that is more math friendly) and y is price or indicator value (if x2-x1 = 0 then you get overflow error because of division by 0 - so do some error checking) .

    Now, since this is noisy set of inputs slope (or derivative if you would choose to use it) would have quite a fluctuation in values and could be as randomly distributed as underlying data regardless of period you would use.

    By the way this is not the only formula for slope but easy to start with.
     
  4. Andy

    Andy

    I think you're using a filter to generate an indicator, then looking at the indicator to make an up/down determination; but you're thinking that your up/down determination needs to be smarter than just comparing one value with the next. However, you're contemplating adding more filtering - which belongs in the filter, not the up/down determination.

    I heard a quote on the radio once which is appropriate here: "Investing would be easy, you invest when the market is going up, and cash out when it's going down. The trouble is, no one has yet been able to give me a workable definition of whether the market is going up or down".
     
  5. Canoe007

    Canoe007

    The possibilities I got off the top of my head include:
    • rise/run (y/x), the delta between current and previous bar,
    • lookback rise/run: delta of current bar and the bar n periods back,
    • multiple lookbacks, n periods, weighted average of slopes (short n, or too much lag...),
    • fit a curve for n periods, take the slope of the curve for the last n/2 length (end-start points; tangent to mid-point; ...)
    But that's all speculating. I was wondering what others have found works.

    I also figure, as you don't code for absolute zero, that I'll have a tolerance for determining a slope of zero. As there will still be noise even in smoothed indicators, perhaps the logic for the slope should more realistically be:
    • positive
    • indeterminate (zero +/- tolerance)
    • negative
    Thoughts?
     
  6. Canoe007

    Canoe007

    Ideally yes, but..

    Coding simple rise/run of current period to previous period didn't work due to noise. Adding enough filtering or extending the period destroyed the usefulness due to introduced lag (tried a little, it needed a lot).

    When charted, I can visually clearly see where an indicator changes direction, be it tops, bottoms, and changes in between. I want a robust slope method. Code against that slope over time lets me determine direction changes of the indicator. A short period weighted MA of slope may be smoother or faster than that code. The lag of either is miniscule compared to the lag I got from further filtering the underlying indicators.

    Hence, looking at different slope equations for suitability.
     
  7. Craig66

    Craig66

    Linear Regression is the first thing that springs to mind, however, remember that slopes calculated off charts are not scale invariant.
     
  8. aqtrader

    aqtrader

    I use least square regression to calculate slopes for a given period. That given period is any number of points of your interest.
     
  9. I do have one but it is proprietary.

    The best solution is Linear Regression.

    Let me describe the qualifications of the person I paid to write what you're asking then you can see if you have it:

    BSc Math University of Michigan
    MS Math University of London
    PhD Math Stanford University

    At a minimum, this is about what qualifications it'll take to get the equation logical enough to analyze, but as far as the manipulations it's funny to me just to say that I only asked for a linear regression equation....
     
  10. vicirek

    vicirek

    Any issues with performance of linear regression in real time?
     
    #10     May 28, 2013