I recently came across a blog post here that talks about an Autoregressive Finite Impulse Response MA, with a link to Metatrader 4 code here. Whilst the blogger in question dismisses the AFIRMA as being "completely useless" I think that in fact this could be quite useful for me. I can guess that s/he dismisses it due to the fact that the windowing function "peeks into the future" (10 days in the case of the default setting of 21).
However, using the leading functions I have talked about in my recent posts, I believe it might be possible to use the values of these leading functions as a proxy for this "peek into the future." Essentially the idea is to take the current bar's 1 bar leading function value of the Cybercycle as a proxy for the next bar's actual Cybercycle value, and then add this to the current bar's Instantaneous trend line value plus its 1 bar momentum to arrive at a "best guess" for the next bar's estimated value. Then all calculations for the indicators are re-run using this estimated value, a new 1 bar leading function calculated, added etc. and wash, rinse and repeat as required.
I can envisage that the coding of this will be difficult and time consuming, so before attempting to do so I will conduct some basic tests of the AFIRMA as is, with the luxury of this perfect "peek into the future" on historical data. I will have to be satisfied that the AFIRMA is possibly worth using before I put time and effort in to this coding task.
"Trading is statistics and time series analysis." This blog details my progress in developing a systematic trading system for use on the futures and forex markets, with discussion of the various indicators and other inputs used in the creation of the system. Also discussed are some of the issues/problems encountered during this development process. Within the blog posts there are links to other web pages that are/have been useful to me.
Thursday, 31 March 2011
Thursday, 10 March 2011
Leading signal for oscillators #3
Following on from the previous two posts about creating a leading indicator for oscillators, I have decided not to use the high pass filter I was using. The reason for this is that in the presence of a trend the high pass filter tends to drift upwards in an uptrend or downwards in a down trend with the result that the filter ends up being centred around a non zero mean. The high pass filter has now been replaced by Ehler's "Cybercycle" which does not suffer from this problem.
Below there is a video showing the leading indicators in action on real life data, the data being continuous, back adjusted futures for the Live Cattle contract, covering approximately a year's worth of data up to and including the 8th March 2011.
The upper graph is obviously a candlestick chart of the data with colour coded bars, but also plotted is Ehler's "Instantaneous trend line" in blue and the Cybercycle Tukey control chart upper control lines and lower control lines, in dotted yellow, mapped on to the price chart. The first sub graph is the actual Cybercycle indicator with its leading functions and its Tukey control chart upper control line and lower control line. The one bar, two bar, three bar and four bar leading functions of the Cybercycle are coloured yellow, green, cyan and white respectively. The second and third sub graphs are a band pass filter applied to the Cybercycle and Ehler's "Sine wave Indicator" applied to the Cybercycle, and both follow the colour scheme as above.
It can be seen that in the sub graphs the lines are either solid or dotted lines, as is the trend line in the price chart. When the Cybercycle is "in control" according to the logic of the Tukey control chart the lines in the sub graphs are solid and the trend line is dotted. When the Cybercycle is "out of control" according to the logic of the Tukey control chart the lines in the sub graphs are dotted and the trend line is solid. This is a simple, visual way to determine whether prices are deemed to be trending or possibly cyclic in nature.
In the price chart the bars are coloured green if the Cybercycle is "in control" AND the leading functions of the Cybercycle are "in order" i.e. the four bar lead is leading the three bar lead, which in turn is leading the two bar lead etc. and indicating upwards cyclic action; similarly the bars are coloured cyan if downwards cyclic action is indicated.
Finally, in the price chart, there are little, coloured triangles above the bars pointing downwards or below the bars pointing upwards. These indicate when the Cybercycle leading functions actually cross each other; when the triangle is cyan the cyan four bar leading function has crossed the green three bar leading function; when the triangle is green the green three bar leading function has crossed the yellow two bar leading function, and so on. It should be noted here that there is an order of preference given to the plotting of these triangles. If there are simultaneous crossovers the "most recent" crossover is displayed, i.e. if the four bar crosses the three bar, and the three bar crosses the two bar, the triangle is green only for the three bar crossing the two bar. The "perfect" set up sequence is cyan, green, yellow and finally blue, signalling three days to the turn, two days to the turn, the turn is tomorrow, and this is the turn bar respectively.
In summary, when the trend line is solid and the leading functions are dotted the market is trending, when the trend line is dotted and the leading functions are solid the market is possibly cycling. When the market is possibly cycling green bars mean be long and cyan bars mean be short. When the market is possibly cycling the triangles give advance warning of market turns.
I leave it up to the viewers to make their own minds up about the efficacy of these signals, but personally I am quite pleased with them.
n.b. for geeks
1) all calculations were done in Octave
2) all plotting was done in Gnuplot, animated by using the reread command
3) the desktop was recorded using recordMyDesktop
4) the video was edited using the Linux video editor LiVES
5) the .ogv output of recordMyDesktop was converted to .avi for upload to Youtube using mencoder
How I love FOSS!
Below there is a video showing the leading indicators in action on real life data, the data being continuous, back adjusted futures for the Live Cattle contract, covering approximately a year's worth of data up to and including the 8th March 2011.
The upper graph is obviously a candlestick chart of the data with colour coded bars, but also plotted is Ehler's "Instantaneous trend line" in blue and the Cybercycle Tukey control chart upper control lines and lower control lines, in dotted yellow, mapped on to the price chart. The first sub graph is the actual Cybercycle indicator with its leading functions and its Tukey control chart upper control line and lower control line. The one bar, two bar, three bar and four bar leading functions of the Cybercycle are coloured yellow, green, cyan and white respectively. The second and third sub graphs are a band pass filter applied to the Cybercycle and Ehler's "Sine wave Indicator" applied to the Cybercycle, and both follow the colour scheme as above.
It can be seen that in the sub graphs the lines are either solid or dotted lines, as is the trend line in the price chart. When the Cybercycle is "in control" according to the logic of the Tukey control chart the lines in the sub graphs are solid and the trend line is dotted. When the Cybercycle is "out of control" according to the logic of the Tukey control chart the lines in the sub graphs are dotted and the trend line is solid. This is a simple, visual way to determine whether prices are deemed to be trending or possibly cyclic in nature.
In the price chart the bars are coloured green if the Cybercycle is "in control" AND the leading functions of the Cybercycle are "in order" i.e. the four bar lead is leading the three bar lead, which in turn is leading the two bar lead etc. and indicating upwards cyclic action; similarly the bars are coloured cyan if downwards cyclic action is indicated.
Finally, in the price chart, there are little, coloured triangles above the bars pointing downwards or below the bars pointing upwards. These indicate when the Cybercycle leading functions actually cross each other; when the triangle is cyan the cyan four bar leading function has crossed the green three bar leading function; when the triangle is green the green three bar leading function has crossed the yellow two bar leading function, and so on. It should be noted here that there is an order of preference given to the plotting of these triangles. If there are simultaneous crossovers the "most recent" crossover is displayed, i.e. if the four bar crosses the three bar, and the three bar crosses the two bar, the triangle is green only for the three bar crossing the two bar. The "perfect" set up sequence is cyan, green, yellow and finally blue, signalling three days to the turn, two days to the turn, the turn is tomorrow, and this is the turn bar respectively.
In summary, when the trend line is solid and the leading functions are dotted the market is trending, when the trend line is dotted and the leading functions are solid the market is possibly cycling. When the market is possibly cycling green bars mean be long and cyan bars mean be short. When the market is possibly cycling the triangles give advance warning of market turns.
I leave it up to the viewers to make their own minds up about the efficacy of these signals, but personally I am quite pleased with them.
n.b. for geeks
1) all calculations were done in Octave
2) all plotting was done in Gnuplot, animated by using the reread command
3) the desktop was recorded using recordMyDesktop
4) the video was edited using the Linux video editor LiVES
5) the .ogv output of recordMyDesktop was converted to .avi for upload to Youtube using mencoder
How I love FOSS!
Saturday, 19 February 2011
A leading signal for oscillators #2


I have now completed coding of the leading oscillator signal (c++ .oct file) and shown above are the results.The topmost chart shows idealised prices as a combination of trend and sine wave with the highpass filter below. Lead 1 and lead 2 are the 1 and 2 period leading signals of the original "price" in blue and the highpass filter in black (see legend in the plot).
The second chart shows the same, but with no trend component added to the "price." Plotting this way makes it easier to see that the indicator lines are exactly in phase with "price" and its leads.
The last chart is a check of my algorithm coding. Applying the highpass filter, and then smoothing it, results in various degrees of phase lag or lead in the basic indicator, dependent upon the period of the underlying signal. Using Monte Carlo techniques to determine the lag/lead at periods of interest I have adjusted the phase of the final indicator outputs such that the indicator adapts to the amount of lag/lead by applying a phase correction. This final chart is just a check of this phase correcting algorithm. As can be seen, once the algorithm calculations settle down, the algorithm correctly calculates the lag/lead to apply as evidenced by the hp_sine values completely overwriting the original "price" values. This algorithm is used in the .oct function used to create the top two charts of the highpass filter.
Monday, 14 February 2011
A leading signal for oscillator indicators

It has been some time since my last post, the reason being the Christmas period and being busy working on non trading stuff. However, I am now back to work on the system and have been looking at creating a leading signal to avoid the pitfalls of indicator lag. Above is a snapshot of what I have come up with shown on a sine wave function (this leading indicator is for application to oscillator indicators).
The sinewave (in dark blue) is first smoothed by a FIR filter, sinewave smooth (in cyan), with filter coefficients such that this sinewave smooth has a constant lag at all frequencies. Knowing what this lag is, along with the frequency, the lag can be compensated for using mathematical and DSP theory to produce the lag adjusted sinewave smooth (in red). It can be seen that although the amplitude of the lag adjusted sinewave smooth is slightly attenuated, it is exactly in phase with the original signal. The lead signal 1 (in magenta) and lead signal 2 (in green) lines are leading signals 1 and 2 "points" (days, bars, candlesticks etc.) in advance of the original signal.
These signals are to be interpreted as follows
- lead 2 crosses lead 1 exactly one "day" before the high or low, giving advance warning of the high or low
- lead 1 crosses the lag adjusted sinewave smooth exactly on the high or low, acting as confirmation of the advance warning
Thursday, 16 December 2010
Bayesian Analysis Update
Having spent the last 6-8 weeks researching and trying out various coding attempts, I've come to the conclusion that, for the moment at least, my time will be spent more usefully doing some of the other things on my to do list. Bayesian analysis is on the back burner for the nearest future.
Wednesday, 13 October 2010
Bayesian Analysis
The thing I'm working on at the moment is applying Bayesian analysis techniques to the trading system, and I'm currently in the research phase consisting of lots of reading and occasional queries to on-line statistical forums. The idea behind this is to develop a methodology to switch between different sets of trading rules, each rule set being applicable to defined market types. More on this as and when I have something relevant to report.
Friday, 8 October 2010
Posting to another forum
Readers of this blog might be interested in a recent forum posting of mine here, under babelproofreader.
Subscribe to:
Comments (Atom)