Automating Divergence signals

Discussion in 'Automated Trading' started by stevenpaul, Dec 4, 2009.

  1. I am new to automating systems and was wondering if anyone could share any tips on integrating "divergence" into an automated trading methodology. The appearance of divergence may not be sufficient to warrant a trade for me, but it is one of the factors I like to take into consideration. Everything else I use is easy enough to program, but I'm stumped on how to go about getting a computer to notice what leaps off the screen as divergence between price and an indicator, or between two given indicators, etc.

    Any food for thought would be much appreciated.


  2. Corey


    I typically use a short term simple moving average to identify highs and lows of a time-series.

    For example, use a 5-period simple moving average, and anytime the time-series is above the average, keep track of the highest point. When it is below, keep track of the lowest points. This will allow you to identify short-term highs and lows and be 'time' agnostic (aka, doesn't have to be higher that last 5 and higher than next 5 to be considered a 'high').

    Note that by changing the period frame of the moving average, you can change your sensitivity to what you call highs and lows.

    Do this for both price and your indicator. If the last high prices are increasing, but the last indicator highs are decreasing, you have a divergence. If the last high prices are decreasing, but your indicator highs are increasing, you have a divergence.

    If you want to make it more rigorous, you can ensure that the highs of the price series and highs of the indicator series are happening 'near' the same time.
  3. We'll assume we're talking about price, but this applies to indicator values as well.
    Mark your starting price at time T0.
    Now keep track of the maximum/minimum value it achieves.
    At some point you will hit an extreme value (EXTREME1) and price will then retrace from that value. When it retraces by at least some amount (RETRACE1) and starts to make new extremes again, track those extremes. Now look for a retracement again (RETRACE2) and you can now identify the extreme of the second cycle (EXTREME2).
    The relationship between EXTREME1 and EXTREME2 identifies the trend.
    Do the same on an indicator and compare the results and you should be able to determine your divergence.
    I would use a larger value for RETRACE1 than for RETRACE2, since this would allow you to identify the divergence in a timely matter.

    Clear as mud, probably, but hopefully this helps.
  4. Thanks guys,

    Those are brilliant ideas. Should be interesting programming that stuff in Excel.

  5. Are you looking to automate the entire process or just the generation of divergence signals?

    If you're looking to auto generate and execute orders, I'd probably use something other than Excel unless you plan on hovering in the background to monitor trades as they occur.
  6. Hi Goonior,

    Yes, I'm interested in automating the whole trading process. I use Sierra Chart right now, and they have us code our entire systems with Excel. It's a real pain, and I don't care for it much, but I'm accustomed to the platform and like it for charting and for the numerous indicators it has ready to go. I'm trying to weigh the pros and cons of using other software that I don't know. I'd be grateful for any input you might care to offer on which platforms are best and whether Excel coding is in fact unsatisfactory.


  7. I'm not that familiar with Sierra Charts, but according to their website, they offer an API which is based off of C++.
    It doesn't appear like you need to be a C++ master to create a system as you will only be implementing your system logic and interfacing with Sierra Charts system functions. They have a whole tutorial on there, so that's worth checking out.

    Personally I would go that approach since I find Excel cumbersome to use (great for spreadsheets, but a pain for more complicate stuff like a trading system state machine).

    Are you looking to develop a fully unattended system (i.e: it'll be churning away night and day while you're on vacation, etc) or just a system that generates and manages orders while you read a book or do some household chores, etc?
    The latter is not so bad to implement.
    A robust version of the former is quite formidable.

    There are vendors out there that host your system, but I've never explored that avenue since I don't want to pay for it.
  8. Thanks so much for the input, Goonior.
  9. I agree on The Excel step - Trading is not really well matching into the spreadsheet model.

    Regarding having a 24/7 trading system, though, dont overlook error factors. I would not really want a possibly failing computer trading without attention (i.e. someone there who can say "stop" and close all orders manually if the need arrives).