Go Back   DailyFX Forum > FXCM Products and Services > FXProgrammers > Discussion / Support Forum > Indicator SDK Support

Reply
 
Thread Tools Rate Thread
  #1 (permalink)  
Old 10-12-2009, 02:18 PM
Member
 
Join Date: Oct 2008
Posts: 474
Nikolay.Gekht is on a distinguished road
Example: Demarker

Here is a source code for the DeMarker oscillator as it is described at DeMarker — Technical Indicators, Technical Analysis.

1) Create the file dem.lua
2) Copy the code below into this file
3) Save the file
or
1,2,3) Just right-click on this link and choose "Save As..." from the menu.

4) Go to "Charts/Chart/Manage Custom Indicators" menu of the Trading Station
5) Click "Load"
6) Choose the dem.lua file created at the previous steps

Code:
-- initializes the indicator
function Init()
    indicator:name("DeMarker");
    indicator:description("")
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);

    indicator.parameters:addInteger("N", "Number of periods for smoothing", "", 14);
    indicator.parameters:addColor("C", "Color of the oscillator", "", core.rgb(0, 127, 127));
end

local source;
local first;
local out;
local max;
local min;
local smax;
local smin;
local n;

-- process parameters and prepare for calculations
function Prepare()
    n = instance.parameters.N;
    source = instance.source;

    max = instance:addInternalStream(source:first() + 1);
    min = instance:addInternalStream(source:first() + 1);
    smax = core.indicators:create("MVA", max, n, core.rgb(0, 0, 0));
    smin = core.indicators:create("MVA", min, n, core.rgb(0, 0, 0));
    first = smax.DATA:first();
    name = profile:id() .. "(" .. n .. ")";
    instance:name(name);
    out = instance:addStream("DeM", core.Line, name .. ".DeM", "DeM", instance.parameters.C, first);
    out:addLevel(0);
    out:addLevel(0.3);
    out:addLevel(0.5);
    out:addLevel(0.7);
    out:addLevel(1);
end

-- Indicator calculation routine
function Update(period, mode)
    if (period > source:first() + 1) then
        if (source.high[period] > source.high[period - 1]) then
            max[period] = source.high[period] - source.high[period - 1]
        else
            max[period] = 0;
        end
        if (source.low[period] < source.low[period - 1]) then
            min[period] = source.low[period - 1] - source.low[period];
        else
            min[period] = 0;
        end
    end
    smax:update(mode);
    smin:update(mode);
    if (period >= first) then
        local vmax;
        local vmin;
        vmax = smax.DATA[period];
        vmin = smin.DATA[period];
        if (vmax == 0 and vmin == 0) then
            out[period] = nil;
        else
            out[period] = vmax / (vmax + vmin);
        end
    end
end
Attached Thumbnails
example-demarker-snapshot.jpg  

Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.

All times are GMT -5. The time now is 09:46 PM.
Copyright ©2009 Daily FX. All Rights Reserved.