Automated price action strategy - first test results

Discussion in 'Strategy Development' started by jcl, Mar 24, 2012.

  1. jcl

    jcl

    In the previous week I asked here if price action really works, and was informed that trading based on price patterns is indeed very profitable. So I'm trying it and these are my first results.

    The task is finding price patterns that precede profitable trades. I am not able to look through tons of price charts, and a computer can do this anyway much better, so I'm using a decision tree for identifying profitable price patterns.

    The first question is what constitutes a price pattern. A classical pattern is the result of comparing the o l h c prices of 3 bars. But a direct comparison seems not so good to me: when the prices are very close, the result is more or less random. So for the test I use their change ratio from one bar to another, like this:

    Code:
    var Change(int n) 
    { 
    	return (price(n)-price(n-1))/price(n-1);
    }
    For this first test, I didn't use high, low, open, and close, but instead the medium price of the bar, and the range of the bar. I figured that this might constitute a more significant pattern, as with intraday bars the open and close prices are just determined by the bar offset, and they are anyway almost identical between bars.

    The second question is what constitutes a profitable trade. I just look for three ascending bars with a price difference above a certain threshold:

    Code:
    bool findProfit()
    {
    	Mode |= PEEK;
    	var Rate = (price(-3)-price(0)-Spread)/price(0);
    	if(Rate < THRESHOLD) return false;
    	int i;
    	for(i = 0; i > -3; i--)
    		if(price(i-1) < price(i))
    			return false;
    	return true;
    }
    The "Mode |= PEEK;" is required here because I'm peeking in the future with negative price offsets. Without the PEEK flag, the program would complain.

    This is the simple lite-C strategy script that finds the price patterns:

    Code:
    function run()
    {
    	TimeExit = 3; // exit trade after 3 bars 
    	if(0 < adviseLong(DTREE,findProfit(),
    		PriceChange(1),PriceChange(2),PriceChange(3),
    		RangeChange(1),RangeChange(2),RangeChange(3)))
    		enterLong();
    }
    The adviseLong(DTREE,...) function generates the decision tree with a learn result given by findProfit(), and 6 input signals that constitute the price changes and the range changes of the last 3 bars. In the simulation, it returns the result of the decision tree.

    When I run the above script, it generates a decision tree that looks like this:

    Code:
    int EURUSD_L(float* sig)
    {
    if(sig[2] <= -0.317) {
      if(sig[2] <= -0.465) {
        if(sig[0] <= -0.028) {
          if(sig[2] <= -0.497) { return -1; }
          else { return 1; }
        }
        else {
          if(sig[3] <= 1.763) { return -1; }
          else { return 1; }
        }
      }
      else {
        if(sig[1] > -0.198) { return -1; }
        else {
          if(sig[1] <= -0.234) { return -1; }
          else { return 1; }
        }
      }
    .....
    This is only the first part of the tree, it's much longer. The size of the tree already suggests that the price changes and range changes of the last 3 bars have almost no predictive value for a profitable trade. The prediction accuracy is 8%.

    Of course, when I run a trade simulation with the above tree, I'm getting 2000% annual return and a Sharpe ratio of 7 - but this is just overfitting. When I use out of sample data, I get 60% loss. This is better than random trading, but that's the only good news. Pruning the tree aggressively improves the results, but I don't exceed 20% annual loss on out of sample data.

    So, these first results seem to contradict the statements by many users that price action trading is profitable.

    What could I do better here? Maybe using other input signals, really comparing olhc, using a different criterion for a profitable trade, using other assets than EUR/USD, and other time frames than 60 minutes? Has someone suggestions for better tests?
     
  2. ssrrkk

    ssrrkk

    I mentioned this in another thread, but I will repeat: bar patterns on their own are not predictive. One needs to use lower highs higher lows etc. in conjunction with S/R levels. Bar patterns on top of that may help but I have always been skeptical about that.

    The trick is to implement something like this: if you see a bounce down from a resistance line (e.g., previous day close, or high, or pivot or longer term resistance), then wait for another local high. If that second local high is lower than the first resistance bounce (LH), then go short with stop slightly above the resistance. Of course, if the LH is too far down from the resistance, then you shouldn't enter because now the risk reward is not in your favor. So one needs to figure out how far down the LH is from the first high to permit an entry. One also needs to figure out when to get out. Both of these can be determined by statistical analysis of past occurrences.

    This is just one pattern. There are other patterns. For example, if you see a big bar jump down (or up) across a major S/R line, then often it pays to go in that direction with the stop placed appropriately in relation to the S/R line.

    The difficulty is this: time series are noisy. Local peak and trough detection is often subjective. One can use various smoothing algorithms but often smoothers create lag, which then shrinks your profit margin. Also slippage is a major issue because many people are following these patterns so by the time you detect it, the price is moving.

    All of these also must be done with consideration of where you are in the day range. Are you outside the prev day range? Are you way beyond yesterday's high or low? Are you close to the close? Are you approaching the previous day high or low? Are you making new day highs on an outside day? These can be evaluated on historical data to create Bayesian probability models, in conjunction with the price patterns above.

    These are the most basic ideas. One needs to go slightly beyond these to be profitable. The key I believe is to have a model of where the other "uninformed" players are placing their entries and stops. The price patterns tell you most likely where they are doing it. Using that consideration can improve the results.
     
  3. jcl

    jcl

    Thanks, that makes sense. Support and resistance lines should be relatively easily to find by looking for price clusters. So an idea for another test could be to identify price patterns in relation to the last support or resistance line.
     
  4. programing a bar-and-price-action-based trading system is extremely difficult, because you have to consider bar relationship with previous bars. most of time, consideration of only 3 consecutive bars is not enough since price action is moving on bar context, which is way beyond 3 bars.

    it took me 2 years and a half almost full time to think about how to code my bar-based trading system.

    think about it: if you can program a chart based system, since the chart is fractal, this system can be used on all markets and all times frames, that means you will make tons of money.
    few people succeed so far.
     
  5. ssrrkk

    ssrrkk

    I would say one needs to consider conventional S/R lines at all time scales plus previous day high low close, plus today's open, plus integer multiple of 10s (clean round number lines). Other sensitive areas: year to date break-even line, weekly or quarterly ranges and break-even points.
     
  6. Is "price action" the change is historical price, or the direction of recent order flow?

    Should actual support and resistance be visible in the order book?

    Why does the backtest above always pay the spread?
     
  7. ssrrkk

    ssrrkk

    These are good questions. I have to say I am not an expert on price action although I have spent over a year back and forward testing many of these ideas, and so far, I have found algorithms that work only in high volatility high ATR regimes. In a low ATR low volatility environment, the profit per trade is too small to overcome the spread+commission incurred due to frequent triggers.

    Regarding what is the proper definition of price action, again I am no authority here, but from what I have read, it is often a combination of bar patterns + support resistance + higher lows lower highs + daily quarterly yearly ranges and pivots. Of course, paying attention to daily ranges is also actually an example of bar patterns -- you are looking at the bar pattern of the daily bars but using it for day trading in the minutes timescale. So often one must mix information from longer timescales to make decisions on shorter timescales.

    I believe the philosophical reason as to why these support resistance lines and pivots often emerge as statistically significant decision points is based on the human being's inability to assign absolute valuations to any asset -- humans can only assign relative valuation. Often I believe the seed or genesis of S/R lines originate in (1) chance occurrence, an inflection that happened from a random walk that many people later assigned significance to and acted on repeatedly, or (2) a round number level, or (3) yesterday's close, or (4) quarterly or year-to-date close. The reason for (2) is purely psychological. Items (3) and (4) are perhaps due to people adjusting their portfolios based on daily quarterly or yearly performance, e.g., if you are a fund manager and you are keeping track of your year-to-date performance then you will likely pay attention to your break-even year-to-date level. You may even want to go to cash if the market dips below the year-to-date break even.

    Regarding order flow, yes, I do think that information will likely predict similar phenomena and more importantly it is information that has an orthogonal or independent component relative to historical price data alone.

    I believe PA alone will not give you a universal algorithm unless you are adjusting it as you go (e.g., as in discretionary trading). Playing level II games to both reduce the slippage (aka paying the spread) and improve prediction rates will likely be needed to make the algorithms more consistent.
     
  8. You have only looked at a particular type of price pattern and for a particular market. How can you arrive to a general conclusion from a study of a limited scope such as this?

    Robust price patterns may last for 3 to maybe 5 years in my experience. Island formations, key reversals and inside day breakouts, for example, seem to work very well in some markets.

    More importantly you appear not aware of the fact that many price action traders use clusters of patterns to increase success rate and robustness. I understand that because you seem to be new in this area. No serious price action trader will ever trade single patterns. I think I have said enough. My son is getting angry at me now for talking about these things in forums. He is my trading assistance and system administrator.
     
  9. Interesting.

    If support and resistance exist, shouldn't they be measurable as either limit orders in the book, or a burst / lack of market orders around the particular price?

    I mean, what else is there? :D
     
  10. As I understand it, an Island Reversal is a signal to sell Apple.
     
    #10     Mar 25, 2012