So, I have been playing around with QuantConnect, which provides a convenient framework to automate trading strategies using C#. It has a lot of useful indicators out of the box. However, one indicator that’s missing is Fibonacci Retracement. That is understandable since it is generally used as a static manually drawn charting feature. But I wanted some way to utilize it as an automatic indicator. That is where Donchian Channels come in. Fibonacci Retracement is a range of values drawn between a high and low. Donchian Channels provide continuously updating high and low values. Combining the two concepts yield an automatically updating Fibonacci Retracement.

Let’s dig into Fibonacci Retracements a little deeper. They are a range of values between a high and low at 61.8%, 50%, 38.2%, and 23.6%. These values are based on the famous Fibonacci Sequence, where each value is the sum of the two prior values (0, 1, 1, 2, 3, 5, 8, 13, 21, etc.). Starting at 2, a value divided by the next value begins to approximate 0.6180. As the values increase the closer the approximation. This is where the 61.8% retracement comes from. A value divided by two places higher approximates 0.382. The 50% mark technically is not related to Fibonacci, but it is often thrown in to indicate a halfway point. The basic idea is that these retracement values indicate possible support or resistance levels.

A Donchian Channel indicator is already built into QuantConnect. It is simply the highest high and the lowest low within a rolling determined period of time. This forms a top and bottom channel. When there is a new lowest low the bottom channel resets to that value. The value is held until the rolling period no longer includes that low or there is a new lowest low. The top channel works in the opposite way.

This all sounds more complicated than it really is. It's simple math that is easy to code. The following code represents the indicator.

The following extension methods register the indicator.

Next there is a trading algorithm that really just plots the indicator.

Here is a sample plot.

The following Gist has all the classes combined into one file, so it can be copied straight into a new trading algorithm on QuantConnect.

## Comments

## Post a Comment