Support and Resistance Algorithm

Discussion in 'Automated Trading' started by Hoplite, Mar 29, 2009.

  1. Hoplite

    Hoplite

    Can anyone provide info/link to a sample SR detection algorithm? I understand many people define support and resistance differently, so I'd prefer code (or algorithm description) that determines SR levels based on previous price peaks and troughs ... but anything close to that would be great. I'm just looking for something to use as a starting point.

    Thanks in advance for your help.
     
  2. If pricevalue > HighLimitOfPriceRangeOfPrior10Intervals then buy;

    If pricevalue < LowLimitOfPriceRangeOfPrior20Intervals then sell;
     
  3. FaceOff

    FaceOff

    I did a bit of analysis on this a month or so back. You can take the prev day high, low, close as S/R. Also, today's open seemed valid. Use a zigzag indicator to get the other peaks. Unfortunately the in backtesting, using SR was not as profitable as other systems - too many times the price breaks SR and then has a strong reversal.
     
  4. Hoplite

    Hoplite

    Thanks for the replies.

    After thinking ... I guess I'm looking for a algorithm to find trend lines ... Something that examines the peaks and troughs of price movement and attempts to assign trend lines. So it would "detect" a channel, or a flag, or whatever. (I'm more intersted horizontal in channels, but they're all interesting.)

    I understand this is a complex problem ... any help in that direction is appreciated. Thanks in advance.
     
  5. Hoplite

    Hoplite

  6. eagle

    eagle

    You may have a look into this. Remember, in the normal environment, it gives a pretty assured result. It will NOT apply in the exceptional circumstances. The problem is that, how you know the next day will be a normal or exceptional environment? And also, how you know the next day the direction will be up or down?

    Despite the two uncertainties, it's quite interesting...
     
  7. Auto-trendline calculation isn't that simple. Theoretically you can pick some period, say 50 days. Then go through the lows in the price data and find the 50 day long line that just contains all the lows. Do the same for the highs.

    Do you want to anchor the one end of the line on today's date? Or place all the trendlines found all over the chart?

    You could also try finding the longest upsloping trendline that contains all the lows, or the longest downsloping trendline that contains all the highs.

    The core of any algorithm is a manual method. How do you find trendlines by hand? This tells you what output would make sense to you.

    Finviz does have an auto-trendline finder but they seem to use a percentile method. i.e. finding trendlines that contain say, 90% of the price action.

    There are different schools of thought about what constitutes a "properly" drawn trendline.
     
  8. rosy2

    rosy2

    if you use python and numpy i found this...

    def extrema_sampling(x, withend=False):
    """
    return the indices into the local maxima or minima of x
    if withend, include the 0 and end points in the sampling
    """
    d = np.diff(x)
    d2 = d[:-1]*d[1:]
    ind = []
    if withend:
    ind.append(0)
    ind.extend(np.nonzero(d2<0)[0]+1)
    if withend and ind[-1]!=len(x)-1:
    ind.append(len(x)-1)
    return np.array(ind)