FXCM Forex Trading

DMI VTTrader Version (Upd: Jun 18 10)

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

DMI VTTrader Version (Upd: Jun 18 10)

Postby Nikolay.Gekht » Tue May 04, 2010 1:28 pm

Upd Jun 18 2010. The first version of the indicator was always calculated as DMI(14), regardless the parameter. The problem is fixed now.

The MT4 and FXCM Trading Station DMI (Directional Movement Index) implementation uses EMA smoothing instead of Wilder's smoothing.

This is the implementation of the DMI indicator on the base of Wilders smoothing.

See ADX VTTrader version topic for more details about the algorithms.

vtdmi.png


Download the indicator:

VTDMI.lua
(4.09 KiB) Downloaded 489 times


This indicator uses WMA indicator. Please, do not forget to download and install it. Find the WMA indicator here: WMA (Wilder's moving average).

Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
-- TODO: Add minimal and maximal value of numeric parameters and default color of the streams
function Init()
    indicator:name("Directional Movement Index (VTTrader version)");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);

    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addInteger("N", "Number of periods", "", 14, 1, 1000);
    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clrDIP", "Color of DI+", "", core.rgb(0, 183, 183));
    indicator.parameters:addColor("clrDIM", "Color of DI-", "", core.rgb(219, 64, 0));

end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- TODO: Refine the first period calculation for each of the output streams.
-- TODO: Calculate all constants, create instances all subsequent indicators and load all required libraries
-- Parameters block
local N;

local first;
local firstTR;
local source = nil;

-- Streams block
local TR = nil;
local TR_W = nil;
local PlusDM = nil;
local PlusDM_W = nil;
local PlusDI = nil;
local MinusDM = nil;
local MinusDM_W = nil;
local MinusDI = nil;
local H, L, C;
local DIP = nil;
local DIM = nil;

-- Routine
function Prepare()
    N = instance.parameters.N;
    source = instance.source;
    firstTR = source:first() + 1;
    H = source.high;
    L = source.low;
    C = source.close;

    TR = instance:addInternalStream(firstTR, 0);
    PlusDM = instance:addInternalStream(firstTR, 0);
    MinusDM = instance:addInternalStream(firstTR, 0);

    TR_W = core.indicators:create("WMA", TR, N);
    PlusDM_W = core.indicators:create("WMA", PlusDM, N);
    MinusDM_W = core.indicators:create("WMA", MinusDM, N);

    first = TR_W.DATA:first();

    local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ")";
    instance:name(name);
    DIP = instance:addStream("DIP", core.Line, name .. ".DIP", "DI+", instance.parameters.clrDIP, first)
    DIM = instance:addStream("DIM", core.Line, name .. ".DIM", "DI-", instance.parameters.clrDIM, first)
end

-- Indicator calculation routine
function Update(p, mode)
    if p >= firstTR then
        local th, tl;

        if C[p - 1] > H[p] then
            th = C[p - 1];
        else
            th = H[p];
        end

        if C[p - 1] < L[p] then
            tl = C[p - 1];
        else
            tl = L[p];
        end

        TR[p] = th - tl;

        if H[p] > H[p - 1] and L[p] >= L[p - 1] then
            PlusDM[p] = H[p] - H[p - 1];
        elseif  H[p] > H[p - 1] and L[p] < L[p - 1] and ((H[p] - H[p - 1]) > (L[p - 1] - L[p])) then
            PlusDM[p] = H[p] - H[p - 1];
        else
            PlusDM[p] = 0;
        end
        if L[p] < L[p - 1] and H[p] <= H[p - 1] then
            MinusDM[p] = L[p - 1] - L[p];
        elseif  L[p] < L[p - 1] and H[p] > H[p - 1] and ((H[p] - H[p - 1]) < (L[p - 1] - L[p])) then
            MinusDM[p] = L[p - 1] - L[p];
        else
            MinusDM[p] = 0;
        end
    end

    TR_W:update(mode);
    PlusDM_W:update(mode);
    MinusDM_W:update(mode);

    if p >= first then
        DIP[p] = 100 * PlusDM_W.DATA[p] / TR_W.DATA[p]
        DIM[p] = 100 * MinusDM_W.DATA[p] / TR_W.DATA[p]
    end
end
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1224
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: DMI VTTrader Version

Postby Blackcat2 » Thu Jun 17, 2010 11:25 pm

I'm currently testing this indicator but for some reason the lines don't change if I change the number of period, I changed it to 1,7,14,18 but doesn't change anything..

Am I missing something?

Cheers..
BC
Blackcat2
FXCodeBase: Initiate
 
Posts: 118
Joined: Wed May 19, 2010 12:42 am

Re: DMI VTTrader Version

Postby Nikolay.Gekht » Fri Jun 18, 2010 11:10 am

Blackcat2 wrote:Am I missing something?

It's me who was missing something. The first version was always calculated N=14. I apologize for the inconvenience. The indicator is fixed. Thank you very much for reporting the problem.
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1224
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: DMI VTTrader Version (Upd: Jun 18 10)

Postby Apprentice » Sat Jan 08, 2011 9:02 am

Style Option Added.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 14500
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: DMI VTTrader Version (Upd: Jun 18 10)

Postby DS0167 » Sun Mar 06, 2011 6:24 am

Hello gentlemen :)

Could you please improve the DMI TTrader so that it colored like on the image below ?

Image

Also, want to know if you can create the signal for DMI Vttrader cross (with level option) ?

Many kind thank you in advance,

:)
Danielle
DS0167
 
Posts: 86
Joined: Mon Aug 09, 2010 2:22 pm

Re: DMI VTTrader Version (Upd: Jun 18 10)

Postby Apprentice » Sun Mar 06, 2011 9:43 am

VTDMI.png

Danielle,
Here you can find an indicator.
I hope that i will finish signal today as well.
VTDMI.lua
(4.71 KiB) Downloaded 666 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 14500
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: DMI VTTrader Version (Upd: Jun 18 10)

Postby DS0167 » Sun Mar 06, 2011 10:54 am

Wonderful !!!

You are the best team ever :D

Thank you again :o)
DS0167
 
Posts: 86
Joined: Mon Aug 09, 2010 2:22 pm

Re: DMI VTTrader Version (Upd: Jun 18 10)

Postby Apprentice » Fri Feb 17, 2017 10:50 am

Indicator was revised and updated.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 14500
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Custom Indicators

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests