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
Of course additional leading signals could be calculated to give a sort of countdown to the high or low as consecutive lines cross each other. All this will have to be tested on real data, but it is gratifying to see that the theory, and my coding of it, work flawlessly on idealised data. This testing on real data will be the subject of a future posting.