Donchian Channel Error

Created at 22 Aug 2013, 04:38
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DR

DrPeter

Joined 22.08.2013

Donchian Channel Error
22 Aug 2013, 04:38


Sorry if this has been raised already. I have noticed an error in the Donchian Channel indicator.

It paints one bar too late. The line output needs to paint to screen one bar earlier.


@DrPeter
Replies

DrPeter
22 Aug 2013, 07:35

Spelling

By the way, it is a Donchian Channel, not a Dochian Channel as you have it labeled in cTrader.

And what's with the middle line? It should not have a middle line.


@DrPeter

virtuesoft
22 Aug 2013, 12:07

Hi,

I coded my own version. Hopefully this helps you out...

 

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class BreakoutLines : Indicator
    {
        [Parameter(DefaultValue = 55)]
        public int Period { get; set; }

        [Output("High", Color = Colors.Yellow, Thickness = 2)]
        public IndicatorDataSeries High { get; set; }

        [Output("Low", Color = Colors.DodgerBlue, Thickness = 2)]
        public IndicatorDataSeries Low { get; set; }

        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {
            Low[index] = double.MaxValue;
            High[index] = double.MinValue;
 
            for (int i = 0; i < Period; i++)
            {
                if (MarketSeries.High[index - i] > High[index])
                {
                    High[index] = MarketSeries.High[index - i];
                }
            
                if (MarketSeries.Low[index - i] < Low[index])
                {
                    Low[index] = MarketSeries.Low[index - i];
                }
            }   
            
        }
    }
}

 


@virtuesoft

DrPeter
22 Aug 2013, 12:33

That's the real deal

Yes indeed, that's how it should be done. Many thanks Virtuesoft,
 


@DrPeter

gorin
29 Aug 2013, 15:24

Actually, 

The selected period does not include the day on which the band is plotted (otherwise the band would never be crossed). For example, the 20-Day Donchian Channels for today are the highest high and lowest low for the preceding 20 trading days.

[http://www.incrediblecharts.com/indicators/donchian_channels.php


@gorin

DrPeter
29 Aug 2013, 15:36

RE:

gorin said:

Actually, 

The selected period does not include the day on which the band is plotted (otherwise the band would never be crossed). For example, the 20-Day Donchian Channels for today are the highest high and lowest low for the preceding 20 trading days.

[http://www.incrediblecharts.com/indicators/donchian_channels.php

Perhaps you have misinterpreted the IncredibleCharts information Gorin. I suggest you compile the code kindly provided above by Virtuesoft and observe what happens on a chart. You will see that the channel correctly contains the price action, which it must do by definition. However, as time moves forward if price "breaks" a channel line then the channel moves to show the new support or resistance levels created by the price movement. It is these breaks that are of interest to the trader. All price action however, will always be contained within the channel.


@DrPeter