Math Question - Peak Detection Algorithm

Discussion in 'Technical Analysis' started by ET151, Dec 11, 2010.

  1. ET151

    ET151

    I have an indicator that oscillates between 0 and 1. It looks like a stochastic oscillator and the signal has a variable frequency. It's smooth most of the time, and the peaks are usually curved or sharp / pointed. I want to identify the locations of the peaks. One way to do this is by keeping track of the min / max points and then calling the peak the highest point once the signal deviates away from that point by some margin. Then after the highest point is called, reset the min/max points to the value of the current point. However, does anyone know of a simpler or more robust way? I could code this up myself, but I figure there's a better / more computationally efficient way to do it than what I have just described. I figure this must come up a lot in technical analysis / automated trading.
     
  2. jesus just learn to trade
     
  3. Then the min is 0+ and the max is 1-.
     
  4. rosy2

    rosy2

    for inflection points you can check for zero slope or do diffs to get sign changes.

    <code>
    public static List<double> ixt(List<double> ii){
    double[] iii = new double[ii.Count - 1];
    List<double> iiii = new List<double>();

    for (int i = 1; i < ii.Count; i++){
    iii[i - 1] = ii - ii[i - 1];
    }
    for (int i = 0; i < iii.Length - 1; i++){
    double x = iii * iii[i + 1];

    if (i>0 && x<0)
    iiii.Add(ii[i + 1]);
    }
    return iiii;
    }
    </code>
     
  5. ET151

    ET151

    Yes, checking for change in slope is one way to do it and maybe the best if there's not much noise. I've also considered taking the difference of two moving averages, longer and shorter. There's always going to be a tradeoff between lag and accuracy with any approach. But I think something more statistically-based would provide a better solution (minimum lag with high accuracy).
     
  6. ET151

    ET151


  7. if you are trying to detect the curve or sharp; why don't you look for whenever f'(x) = 0 or f'(x)=does not exist. change of signs is good too but it would lag a little considering you would have to wait for the current interval to end.
     
  8. =====================

    Yes, there is a simply way, its battle tested also;
    200 day moving average, with some shorter- ''sharp pointed'' moving averages[hint =less comissions/slippage with longer moving averages]
    Speaking of yearly patterns-Merry Christmas/hanukkah/ thanksgiving:cool: Cool
     
  9. bone

    bone

    Nobody wants to mention the most applicable and profitable variable: the timeframe (s) you choose to sample.

    This has been done ad nauseum - look at timeframes for real traction.
     

  10. The no-lag solution is to use a filter. You could either try low-pass, band-pass, high-pass filters and see what works best. Or do a spectral analysis and see what frequency/frequencies the peaks occur at... watch those frequencies for any value above a certain threshold.
     
    #10     Dec 13, 2010