Thursday 14 November 2013

Andrews Median Lines

Alan Andrews is famous for teaching traders about median lines. The most popular configuration available on modern charting packages is the Andrews Pitchfork, an attempt to project price and time forward from known price turning points (pivots). In most implementations, one selects 3 alternating high/low pivot points (either low/high/low or high/low/high), and the charting package draws the pitchfork as follows:

1. Draw a line (the median line) from the first point through the midpoint of 
the second two points.
2. Draw a line parallel to the median line that passes through the second 
point.
3. Draw a line parallel to the median line that passes through the third 
point.



Andrews stated there is a high probability that:
Price will return to the median line 80% of the time after the third pivot is made.
Price will either reverse on meeting the median line or gap through it (he used daily stock charts, so a common modern interpretation is if the price moves quickly though the median line rather than gap across it).
When price passes through the median line, price will pull back to it (i.e. the median line acts as a price attractor).
If the price fails to reach the median line, it will move in the opposite direction for a greater distance than that which it missed the median line by.
Price reverses at any median line or extension of a prior median line. 

Inside lines

Price can be expected to stay within the confines of a pitchfork. Sometimes the pitchfork drawn can be large, and price projection is more easily found when additional lines are drawn within the median parallels.




Warning lines

When price falls outside the pitchfork, the pitchfork is considered to have "failed". Price may, however, return to the pitchfork at a later time. Price may respect lines drawn outside of, but parallel to the original median line, at spacing equal to the distance between the median line and one of the median line parallels drawn from point 2 or point 3.



Schiff

Andrews encouraged his students to contribute towards the technique. One of these was a trader named Jerome Schiff. He proposed that, when price does not follow the traditional pitchfork implementation, it may follow a modified arrangement where the start point of the median line is taken to be half way between the first and second pivots.

50% Pitchfork

Another variant, attributed to the Austin Financial Group [1] alters the first price to be the same as the third price.



Trigger (Hagopian) lines

Another student, Hagopian, suggested that, if price crossed either a line drawn from point 1 to point 2, or crossed a line drawn from point 1 to point 3, that this indicated a price failure and that a trade may be taken in the direction of the failure.



Mini Pitchfork

Andrews often drew pitchforks using alternate daily closing prices. These are referred to as "Mini Pitchforks". In this case, prices are aligned to the closing prices and not high/low prices.



Implementation

The FPS Pitchfork tool for MetaTrader4 supports:

1. The original Andrews pitchfork.
2. The Schiff pitchfork.
3. The 50% pitchfork.
4. The Mini pitchfork.
5. All of the pitchfork variants may have hagopian (trigger) lines, inside lines and trigger lines added by manually modifying the object description.

The tool is implemented as a script, which I have linked to a hotkey, so that it is called each time I press CTRL-F. Some other pitchfork tools are implemented as indicators. The indicator has 2 drawbacks. Firstly, you cant use it easily on a weekend, since redrawing is only done when quotes arrive. Secondly, they consume CPU on every quote, even if they decide they don't have any useful processing to do. Since I run 153 bots at the same time, this ends up being a significant factor.

The user draws a pitchfork using the Metatrader tool, then optionally modifies the object description to contain pitchfork type and lines required. The script then uses the object description information to both align the pitchfork and to draw the necessary ancillary lines.

Recommended reading (and recommended order)

1. Fisher, Greg - Using Median Lines as a Trading Tool.
2. Mikula, Patrick - The Best Trendline Methods of Alan Andrews.
3. Morge, Timothy - Trading With Median Lines.

Sunday 25 August 2013

Multiple Renko Charts in one Metatrader with no extra "Ticking" software

One of the issues encountered when using Renko inside of Metatrader is the fact that the refresh signal sent (PostMessage) by the generator is consumed by the first chart receiving it. In order to overcome this problem, the generator needs to be modified to recreate the offline chart (.HST) in a continuous loop. In the following example, a proprietary generator is used to produce BOTH a EURUSD and a GBPUSD chart within the same instance. Any EA attached to the charts needs to employ techniques to detect "Aged Quotes". These occur as the generator causes them to be ticked on each throttled cycle, but also occur in real-life after weekend server switch-offs.


Saturday 6 July 2013

Are Fibonacci numbers important?

I have 68 bots running currently, none of which use Fibonacci numbers. Now that's not to say that they are not possible future inflection points ...

Which they are. Its easy to attribute cause to Fibonacci ratios, merely because they are a self-fulfilling argument, i.e. if a Brazilian people (the number of people it would take to fill Brazil) traded a currency pair using Fibonacci numbers, then their actions would mean that they would influence the price with their supply and demand. same goes for round numbers (e.g. cable support at 1.5000) which are psychological support/resistance numbers.

Consider the action of major banks. No desk head says "sell at 1.49372", rather they say sell at one and a half (1.5000). Junior traders responsible for bulk execution will set their limit/stop orders to exactly 1.5000, hence these become important numbers.

If you watch a gold tick chart, you will clearly see the "magic" numbers.

Monday 1 July 2013

10 Reasons why back-testing is pointless

I am always interested in why my endeavours fail, but i usually try to do something about it. Often the knowledge so gained sets me upon a different, hopefully profitable path.

Recently, one of my bots had some issues which made me decide to use "better data" for my backtesting and optimisation. The following is a bullet-point list of the results.

1. You are not using your own broker's live server data:
- It comes from a different broker than the one on which you will forward test, and so
will almost certainly have (even slightly) different prices from that which you would have experienced had you been connected to your broker's platform. Prices differ also between demo and live, and between historic timeframe data (*see footnote*)

2. You are using your own broker's (tick) data, but the copy that you have is not complete and/or accurate:
- This would probably be the most accurate way to test a bot, but relies on you receiving/recording every tick in a timely fashion. This may not be possible due to net latency.

3. You have filtered out duplicate ticks
- Duplicate ticks may have an effect on your bot.

4. You are using a constant spread:
- Spreads are usually only constant when the market is closed.

5. You are using a constant tick value:
- Tick values are sometimes not constant, e.g. when trading a cross pair.

6. Your bot behaves differently in live than in optimisation/testing mode:
- Some platforms provide a way of the software determining if it is "test" mode, e.g. the IsOptimisation() and IsTesting() Metatrader functions. These allow you to legitimately bypass unwanted code (e.g. some console output) but may also cause other side effects.

7. You assume market memory where there is none.
- If the random-walk theory is correct (not my opinion), then technical analysis of any kind is useless.

8. Your bot is over-tuned (curve-fitted) to the price data:
- Some analysts insist a bot must have been back-tested using many years of data, and is only "useful" if it would have been consistently profitable over that period.

9. Your bot is under-tuned (not curve-fitted) to the price data:
- Some analysts believe that regular tuning is necessary to allow the bot to "keep in step" with the changing data distribution.

10. You can't keep your fingers off the finished product:
- OK, so you got 1 to 9 under control, and then put your "holy grail" onto a live account. The bot enters a trade, and it is making money so you just HAVE to close it at a profit, thus ignoring a sound tenet "Let your winners run", and losing 50% of the profit you would have otherwise made (opportunity cost). The bot then enters a trade, and it is losing money, so you "Cut your losing trades short". The second you close your trade, the price action reverses and you lose what would have been a healthy profit. YOU MUPPET!

Saturday 12 January 2013


A Happy New Year to all clients and friends. I haven't made any updates for a while (I hope 2013 is as busy as 2012!), so to make up I will try to detail some of the behavior that I think every trader (and financial services developer) should consider.




Frame dependence

Frame Dependence is the tendency to evaluate current decisions within the framework in which they have been presented. Look at the screenshot of recent activity of EURUSD on one of my robots. See the long rally which halts, then continues upwards. This presents a frame-dependent choice. One can either decide, "Yes, that's a significant enough rally, I will take profit here", or decide "Nope, let the profits run, I can always exit if it doesn't work out". What is really going on here is how one perceives the trade profit. The thought "Its not mine until it's booked" may lead to "It's only winnings so it's not a problem if I lose it". Account equity becomes account balance only if you have no open winning or losing trades. Frame dependence includes loss aversion ("I don't want to lose my winnings so I'll book them at this level") and hedonic editing ("Wow! If I book now I've made $$$!").

Money illusion (a 2% payrise with 4% inflation is better than a 2% pay cut) also comes into play when trading costs (swap,commission,spread and slippage) are not considered. This further leads one to believe more profit is being captured than actually is. In the screenshot, notice the robot takes the profit, then enters again. As it wins both times, "happy days!", but staying in the trade would have halved the trading costs, plus also of course gaining the difference between the exit of the first trade and the entry of the second.


The final statement of the last paragraph can be considered to be made as a result of hindsight. We knew the trades had already been made, we knew the outcome, so we can bemoan the losses incurred, or celebrate the successes. In a manual trading situation, having observed this outcome, if we weigh on the side of "cup half full", we would do the same thing as the robot has done here, and book profit in a similar fashion. If we come down on the "cup half empty" side, we may let the trade run, in the hope of gaining the lost costs. So hindsight may give us a bias for what we do in the future.


In scientific experiments, one posits a theory, describes the event or existence of something that would prove the hypothesis, then actively looks for that event or object. If found, the hypothesis is proven, if not, it is not proven.

Confirmation bias is the tendency of people to favor information that confirms their hypotheses. Having observed the events described above, one could look backwards for similar events where 2 such trade events occurred. Seeing the event again could lead one to believe either that the cup was half empty or full.