Page 1 of 10

Dochian Channel Indicator

PostPosted: Tue Oct 20, 2009 3:45 pm
by admin
DESCRIPTION:
This indicator displays a simple marker of the Highest High in the last few periods, and the Lowest Low in the last few periods. Usually this indicator is configured to use 20 periods. Center line displays average between highest high and lowest low. Dochian Channel Indicator is useful because previous highs and lows usually show significant resistance to further currency price movement.

CALCULATION:
UP(N) = MAX(HIGH, N)
DOWN(N) = MIN(LOW, N)
DNC(N) = (UP(N) + DOWN(N)) / 2


Dochian.jpg
Screenshot of Dochian Channel Indicator



DNC.lua
Download Dochian Channel Indicator
(2.57 KiB) Downloaded 19208 times


Donchian Channel with Alert.lua
(12.99 KiB) Downloaded 5519 times

This Version will give Audio / Email Alerts on Price/Line Cross.

Dec 14, 2015: Compatibility issue Fixed. _Alert helper is not longer needed.

Tick DNC.lua
(6.73 KiB) Downloaded 3535 times


MT4/MQ4 version
viewtopic.php?f=38&t=20206

Indicator-based strategy.
viewtopic.php?f=31&t=68575

MT4/MQ4 version.
viewtopic.php?f=38&t=68979

Re: Dochian Channel Indicator

PostPosted: Sat May 08, 2010 11:40 am
by gerrysta
Could someone tell me what program I use to open a '.lua file for the Donchian Channel? Thanks

Re: Dochian Channel Indicator

PostPosted: Sun May 09, 2010 9:24 am
by Nikolay.Gekht
It is the FXCM Trading Station (dbFX Trading Station is the same).
Please read the instruction:
viewtopic.php?f=17&t=17

Re: Dochian Channel Indicator

PostPosted: Fri May 28, 2010 1:21 pm
by Apprentice
Close.png
Dochian Channel Indicator


This version has the option to choose between High / Low and Close values as a basis for drawing Dochian Channel.

DNC_V2.lua
Dochian Channel Indicator
(2.82 KiB) Downloaded 10751 times

Re: Dochian Channel Indicator

PostPosted: Tue Oct 19, 2010 7:07 am
by abcdefg
Can I please request a bigger timeframe of this indicator for my tick chart.
Placing a 1440 or 2180 donchian channel on tick charts are very limiting and also inaccurate, due to the repaints.
(Please do not remove the mid line as it is a very effective alternative compared to pivots.)

It would be great for all trend-followers (scalping the ticks) and in honor to Mr.Donchian :D

Thank you guys in advance. :D no rush :)

Re: Dochian Channel Indicator

PostPosted: Tue Oct 19, 2010 8:38 am
by Apprentice
Added to developmental cue.

Re: Dochian Channel Indicator

PostPosted: Thu Oct 21, 2010 4:35 am
by Alexander.Gettinger
Bigger timeframe DNC.

BF_DNC.png


Code: Select all
function Init()
    indicator:name("Bigger timeframe DNC");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addString("BS", "Time frame to calculate DNC", "", "D1");
    indicator.parameters:setFlag("BS", core.FLAG_PERIODS);
    indicator.parameters:addInteger("N", "Number of periods", "", 20, 2, 10000);
    indicator.parameters:addString("AC", "Analyze the current period", "", "yes");
    indicator.parameters:addStringAlternative("AC", "no", "", "no");
    indicator.parameters:addStringAlternative("AC", "yes", "", "yes");
    indicator.parameters:addString("SM", "Show middle line", "", "no");
    indicator.parameters:addStringAlternative("SM", "no", "", "no");
    indicator.parameters:addStringAlternative("SM", "yes", "", "yes");

    indicator.parameters:addGroup("Display");
    indicator.parameters:addColor("clrDU", "Color of the Up line", "", core.rgb(255, 255, 0));
    indicator.parameters:addColor("clrDN", "Color of the Down line", "", core.rgb(255, 255, 0));
    indicator.parameters:addColor("clrDM", "Color of the middle line", "", core.rgb(255, 255, 0));

end

local source;                   -- the source
local bf_data = nil;          -- the high/low data
local N;
local BS;
local bf_length;                 -- length of the bigger frame in seconds
local dates;                    -- candle dates
local host;
local day_offset;
local week_offset;
local extent;
local dn=nil;
local du=nil;
local dm=nil;

function Prepare()
    source = instance.source;
    host = core.host;

    day_offset = host:execute("getTradingDayOffset");
    week_offset = host:execute("getTradingWeekOffset");

    BS = instance.parameters.BS;
    N = instance.parameters.N;
    extent = N*2;

    local s, e, s1, e1;

    s, e = core.getcandle(source:barSize(), core.now(), 0, 0);
    s1, e1 = core.getcandle(BS, core.now(), 0, 0);
    assert ((e - s) <= (e1 - s1), "The chosen time frame must be bigger than the chart time frame!");
    bf_length = math.floor((e1 - s1) * 86400 + 0.5);

    local name = profile:id() .. "(" .. source:name() .. "," .. BS .. "," .. N .. ")";
    instance:name(name);
    dn = instance:addStream("DU", core.Line, name .. ".DU", "DU", instance.parameters.clrDU,  0);
    du = instance:addStream("DN", core.Line, name .. ".DN", "DN", instance.parameters.clrDN,  0);
    if (instance.parameters.SM=="yes") then
        dm = instance:addStream("DM", core.Line, name .. ".DM", "DM", instance.parameters.clrDM,  0);
    end


end


local loading = false;
local loadingFrom, loadingTo;
local pday = nil;

-- the function which is called to calculate the period
function Update(period, mode)
    -- get date and time of the hi/lo candle in the reference data
    local bf_candle;
    bf_candle = core.getcandle(BS, source:date(period), day_offset, week_offset);

    -- if data for the specific candle are still loading
    -- then do nothing
    if loading and bf_candle >= loadingFrom and (loadingTo == 0 or bf_candle <= loadingTo) then
        return ;
    end

    -- if the period is before the source start
    -- the do nothing
    if period < source:first() then
        return ;
    end

    -- if data is not loaded yet at all
    -- load the data
    if bf_data == nil then
        -- there is no data at all, load initial data
        local to, t;
        local from;

        if (source:isAlive()) then
            -- if the source is subscribed for updates
            -- then subscribe the current collection as well
            to = 0;
        else
            -- else load up to the last currently available date
            t, to = core.getcandle(BS, source:date(period), day_offset, week_offset);
        end

        from = core.getcandle(BS, source:date(source:first()), day_offset, week_offset);
        dn:setBookmark(1, period);
        -- shift so the bigger frame data is able to provide us with the stoch data at the first period
        from = math.floor(from * 86400 - (bf_length * extent) + 0.5) / 86400;
        local nontrading, nontradingend;
        nontrading, nontradingend = core.isnontrading(from, day_offset);
        if nontrading then
            -- if it is non-trading, shift for two days to skip the non-trading periods
            from = math.floor((from - 2) * 86400 - (bf_length * extent) + 0.5) / 86400;
        end
        loading = true;
        loadingFrom = from;
        loadingTo = to;
        bf_data = host:execute("getHistory", 1, source:instrument(), BS, loadingFrom, to, source:isBid());
        DNC = core.indicators:create("DNC", bf_data, instance.parameters.N,instance.parameters.AC,instance.parameters.clrDU,instance.parameters.clrDU,instance.parameters.clrDU,instance.parameters.SM);
        return ;
    end

    -- check whether the requested candle is before
    -- the reference collection start
    if (bf_candle < bf_data:date(0)) then
        dn:setBookmark(1, period);
        if loading then
            return ;
        end
        -- shift so the bigger frame data is able to provide us with the stoch data at the first period
        from = math.floor(bf_candle * 86400 - (bf_length * extent) + 0.5) / 86400;
        local nontrading, nontradingend;
        nontrading, nontradingend = core.isnontrading(from, day_offset);
        if nontrading then
            -- if it is non-trading, shift for two days to skip the non-trading periods
            from = math.floor((from - 2) * 86400 - (bf_length * extent) + 0.5) / 86400;
        end
        loading = true;
        loadingFrom = from;
        loadingTo = bf_data:date(0);
        host:execute("extendHistory", 1, bf_data, loadingFrom, loadingTo);
        return ;
    end

    -- check whether the requested candle is after
    -- the reference collection end
    if (not(source:isAlive()) and bf_candle > bf_data:date(bf_data:size() - 1)) then
        dn:setBookmark(1, period);
        if loading then
            return ;
        end
        loading = true;
        loadingFrom = bf_data:date(bf_data:size() - 1);
        loadingTo = bf_candle;
        host:execute("extendHistory", 1, bf_data, loadingFrom, loadingTo);
        return ;
    end

    DNC:update(mode);
    local p;
    p = findDateFast(bf_data, bf_candle, true);
    if p == -1 then
        return ;
    end
    if DNC:getStream(0):hasData(p) then
        dn[period] = DNC:getStream(0)[p];
    end
    if DNC:getStream(1):hasData(p) then
        du[period] = DNC:getStream(1)[p];
    end
    if (instance.parameters.SM=="yes") then
     if DNC:getStream(2):hasData(p) then
         dm[period] = DNC:getStream(2)[p];
     end
    end
   
end

-- the function is called when the async operation is finished
function AsyncOperationFinished(cookie)
    local period;

    pday = nil;
    period = dn:getBookmark(1);

    if (period < 0) then
        period = 0;
    end
    loading = false;
    instance:updateFrom(period);
end

function findDateFast(stream, date, precise)
    local datesec = nil;
    local periodsec = nil;
    local min, max, mid;

    datesec = math.floor(date * 86400 + 0.5)

    min = 0;
    max = stream:size() - 1;

    while true do
        mid = math.floor((min + max) / 2);
        periodsec = math.floor(stream:date(mid) * 86400 + 0.5);
        if datesec == periodsec then
            return mid;
        elseif datesec > periodsec then
            min = mid + 1;
        else
            max = mid - 1;
        end
        if min > max then
            if precise then
                return -1;
            else
                return min - 1;
            end
        end
    end
end


For this indicator must be installed DNC indicator.

Re: Dochian Channel Indicator

PostPosted: Mon Dec 06, 2010 8:56 am
by Apprentice
DNC.png


DNC-Bandwidth
The difference between the highest and lowest prices within the period.
You used to determine the width of the channel,
measure of volatility.

DNC-Percentage
Shows the percentage position of the closing price within the DNC canal.
Can be used as simple indicators for overbought / oversold conditions.
Filter for possible Entry, Exit orders.

DNC-Bandwidth.lua
(1.36 KiB) Downloaded 5555 times

DNC-Percentage.lua
(1.4 KiB) Downloaded 5331 times

Re: Dochian Channel Indicator

PostPosted: Fri Jan 21, 2011 10:47 am
by pippelin
Apprentice wrote:
Close.png


This version has the option to choose between High / Low and Close values as a basis for drawing Dochian Channel.

DNC_V2.lua



Hi apprentice
even when i use your version 2 of your donchian channel i cant change the data source to close and its always history
can you help me to get the chance to just use the close price as the data source with this indicator

Thank you very much

Re: Dochian Channel Indicator

PostPosted: Fri Jan 21, 2011 1:14 pm
by Apprentice
Data source for this indicator Is always Bar. (All four data points)

You have the choice to select, whether the channel lines are to be drawn on High / Low or Close values.