Beta version of the new SDK (release 2010-II)

Moderator: admin

Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Wed Mar 17, 2010 6:07 pm

Today the new release of the Marketscope finally moved to the QA and is expected to be released in a couple of weeks. The offical release of new SDK is expected the same time, but you can download and play with it right now.

SDK: http://fxcodebase.com/documents/indicor ... oreSDK.exe

The online version of the documentation: http://fxcodebase.com/documents/indicor ... ntent.html

Key new features:

1) An ability to create label output in the indicator. Label output shows the text labels instead of lines, dots and bars. See instance:createTextOutput

2) An ability to create a channel (highlight area on the chart between two lines) or candles (using four streams: open, high, low and close) in the indicator. See instance:createChannelGroup and instance:createCandleGroup

3) An new interface host which can be used to executed extended operations. Currently, the following operations are available:
1) draw a line or put a label on the associated chart.
2) load and/or subscribe for updates for prices of the the specified instrument in the specified time frame.

There is also a couple of useful functions:
core.getcandle, which returns the start date of the candle of the specified size and
core.isnontrading, which check whether the specified date and time belongs to the non-trading period (Friday 17:00-Sunday 17:00).

4) Signals! Signal is a small pieces of the lua code, similar to the indicators, which listens offers and can alert text and sound messages. Sorry, signal documentation is very-very raw for now, I have to work on it hard in a next few days.

How to try?

You can try the indicators and signals using the debuggers or can request for the beta-version of the Marketscope application (write me a personal message).

If you have requested beta-version of the Marketscope application, please note that this version is beta so can contain errors and bugs. Therefore you must NOT use it to trade. Any trading operation executed using beta version is on your risk and nobody is responsible for any damages and losts arisen from using of the beta version of the Marketscope or Trading Station application. Also, the offical technical support will NOT support the beta version. So, please, use it to develop and test new indicators ONLY.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Wed Mar 17, 2010 6:17 pm

An image demostrating new features:

1) Fractal indicators uses text output to draw arrow.
2) Pivot indicator uses new host interfaces to get daily data on 1-hour chart and to draw today's support/resistance lines.
3) TPO indicator uses host interface to draw a kind of histogram at the right side of the chart.
4) Heikin Aishi uses an ability to group outputs into candle
5) Ichimoku uses an ability to join lines into a channel to highligh the cloud area

(click image to enlarge)
newms.png


All these indicators except TPO are in the standard indicators list now.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Beta version of the new SDK (release 2010-II)

Postby Apprentice » Thu Mar 18, 2010 7:12 am

SDK Link do not work.
Horizontal histogram, nice.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Thu Mar 18, 2010 8:29 am

Link fixed.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Mon Mar 22, 2010 11:46 am

An additional example of new indicators: TPO.

Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
    indicator:name("Time Price Opportunity Profile");
    indicator:description("The indicator calculates how often the price appears in the historical data");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addInteger("BoxSize", "Size of price box in pips", "", 5);
    indicator.parameters:addInteger("Per", "Points to display the historgram", "", 50);
    indicator.parameters:addColor("S1", "Color", "", core.rgb(127, 127, 127));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local BoxSize;
local Per;
local TPO = {};
local source = nil;
local S1;
local first;

-- Routine
function Prepare()
    BoxSize = instance.parameters.BoxSize;
    Per = instance.parameters.Per;
    S1 = instance.parameters.S1;
    source = instance.source;
    first = source:first();
    source = instance.source;
    local name = profile:id() .. "(" .. source:name() .. ", " .. BoxSize .. ")";
    instance:name(name);
    instance:addStream("H", core.Line, name .. ".H", "H", S1, 0, 20);
end

local prevDate = -1;
local max = 0;

-- Indicator calculation routine
function Update(period)
    if period >= first then
        local date = source:date(period)
        if date < prevDate then
            TPO = {};
            max = 0;
        elseif date == prevDate then
            return ;
        end

        prevDate = date;

        local median;
        median = (source.high[period] + source.low[period] + source.close[period]) / 3;
        -- express in pips
        median = median / source:pipSize();
        median = median - median % BoxSize;
        local v = rawget(TPO, median);
        if v == nil then
            v = 0;
        end
        v = v + 1;
        if v > max then
            max = v;
        end
        local v = rawset(TPO, median, v);

        core.host:execute("removeAll");
        for k, v in pairs(TPO) do
            local length = v / max * Per;
            core.host:execute("drawLine", k, -2, k * source:pipSize(), length, k * source:pipSize(), S1);
        end
    end

end
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Mon Mar 22, 2010 11:48 am

Daily High/Low on smaller timeframe chart
Code: Select all
function Init()
    indicator:name("High/Low Bands");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addString("BS", "Bar Size to display High/Low", "", "D1");
    indicator.parameters:setFlag("BS", core.FLAG_PERIODS);
    indicator.parameters:addGroup("Display");
    indicator.parameters:addColor("clrB", "High/Low Band Color", "", core.rgb(192, 192, 192));
    indicator.parameters:addInteger("A", "High/Low Band Filling Alpha Factor", "", 10, 0, 100);
end

local source;                   -- the source
local hilo_data = nil;          -- the high/low data
local H;                        -- high stream
local L;                        -- low stream
local BS;
local dates;                    -- candle dates
local host;
local candles;                  -- stream of the candle's dates

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

    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    H = instance:addStream("H", core.Line, name .. ".H", "H", instance.parameters.clrB, 0);
    L = instance:addStream("L", core.Line, name .. ".L", "L", instance.parameters.clrB, 0);
    instance:createChannelGroup("HL", "HL", H, L, instance.parameters.clrB, instance.parameters.A);
    candles = instance:addInternalStream(0, 0);
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 hilo_candle;
    hilo_candle = core.getcandle(BS, source:date(period), -7);

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

    if not(source:isAlive() and period == source:size() - 1) then
        -- replicate the previous date in case it is the same upscale candle
        if (period > source:first() and candles:hasData(period - 1) and candles[period - 1] == hilo_candle) then
            H[period] = H[period - 1];
            L[period] = L[period - 1];
            candles[period] = hilo_candle;
        end
    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 hilo_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), -7);
        end

        from = core.getcandle(BS, source:date(source:first()), -7);
        loading = true;
        H:setBookmark(1, period);
        loadingFrom = from;
        loadingTo = to;
        hilo_data = host:execute("getHistory", 1, source:instrument(), BS, from, to, source:isBid());
        return ;
    end

    -- check whether the requested candle is before
    -- the reference collection start
    if (hilo_candle < hilo_data:date(0)) then
        H:setBookmark(1, period);
        if loading then
            return ;
        end
        loading = true;
        loadingFrom = hilo_candle;
        loadingTo = hilo_data:date(0);
        host:execute("extendHistory", 1, hilo_data, loadingFrom, loadingTo);
        return ;
    end

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

    -- find the hilo candle in the reference history
    local hilo_i = nil;
    local start;

    if (pday == nil) then
        start = 0;
    elseif hilo_data:date(pday) > hilo_candle then
        start = 0;
    else
        start = pday;
    end

    for i = start, hilo_data:size() - 1, 1 do
        if (hilo_data:date(i) == hilo_candle) then
            hilo_i = i;
            break;
        end
        if (hilo_data:date(i) > hilo_candle) then
            break;
        end
    end

    -- candle is not found
    if (hilo_i == nil) then
        return ;
    end

    pday = hilo_i;

    H[period] = hilo_data.high[hilo_i];
    L[period] = hilo_data.low[hilo_i];
    candles[period] = hilo_candle;

    if source:isAlive() and period > source:first() and period == source:size() - 1 then
        -- update all today's data in case today's high low is changed
        if candles:hasData(period - 1) and candles[period - 1] == hilo_candle and
           ((H[period - 1] ~= H[period]) or (L[period - 1] ~= L[period]))  then
            local i = period - 1;
            while i > 0 and candles:hasData(i) and candles[i] == hilo_candle do
                H[i] = hilo_data.high[hilo_i];
                L[i] = hilo_data.low[hilo_i];
                i = i - 1
            end
        end
    end
end

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

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

    if (period < 0) then
        period = 0;
    end
    loading = false;
    instance:updateFrom(period);
end
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Tue Mar 30, 2010 2:08 pm

The SDK link above is updates for the release candidate version of the SDK.

The lastest changes
1) Text output tooltips are supported
2) The indicator and signal debuggers has a function Restart, which starts the same indicator, keeps parameters, sources, breakpoints and watches.
3) The "save alerts" function is added to the signal debugger. The saved alerts can be shown on the chart in Marketscope using the indicator below. Just enter the file name which contains saved alerts into the first parameter of the indicator.

Code: Select all
function Init()
    indicator:name("Show Signal Debug Info");
    indicator:description("The indicator shows the saved alert info from the signal debugger");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addString("file", "Alert file", "", "");
    indicator.parameters:addColor("clr", "Color of labels", "", core.COLOR_LABEL);
end

local alerts = nil;
local pline = "([^|]*)|([^|]*)|([^|]*)|([^|]*)";

local up, down, center;
local source;
local barsize;

function Prepare()

    core.host:trace("file " .. instance.parameters.file);

    source = instance.source;

    local s, e;
    s, e = core.getcandle(source:barSize(), core.now(), 0);
    barsize = e - s;

    local name = profile:id() .. "(" .. instance.parameters.file .. ")";
    instance:name(name);

    up = instance:createTextOutput ("U", "U", "Wingdings", 10, core.H_Center, core.V_Top, instance.parameters.clr, 0);
    down = instance:createTextOutput ("D", "D", "Wingdings", 10, core.H_Center, core.V_Bottom, instance.parameters.clr, 0);
    center = instance:createTextOutput ("C", "C", "Wingdings", 10, core.H_Center, core.V_Center, instance.parameters.clr, 0);
end

function Update(period, mode)
    if alerts == nil then
        alerts = {};
        alerts.count = 0;
        local file;
        file = io.open(instance.parameters.file, "r");
        for line in file:lines() do
            local time, price, instrument, message;
            time, price, instrument, message = string.match(line, pline);
            if time ~= nil then
                time = tonumber(time);
                price = tonumber(price);
                local alert = {};
                alert.time = time;
                alert.price = price;
                alert.instrument = instrument;
                alert.message = message;
                alerts.count = alerts.count + 1;
                alerts[alerts.count] = alert;
            end
        end
    end

    local from, to, i, alert;
    from = source:date(period);
    to = from + barsize;
    for i = 1, alerts.count, 1 do
        alert = alerts[i];
        if alert.time >= from and
           alert.time < to then
            if alert.price >= source.high[period] then
                up:set(period, alert.price, "\226", alert.instrument .. " " .. alert.message);
            elseif alert.price <= source.low[period] then
                down:set(period, alert.price, "\225", alert.instrument .. " " .. alert.message);
            else
                center:set(period, alert.price, "\164", alert.instrument .. " " .. alert.message);
            end
        end
    end
end


For those, who requested the beta version of the TS, the release candidate build has updated by the same URL as well.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Beta version of the new SDK (release 2010-II)

Postby Nikolay.Gekht » Wed Apr 07, 2010 1:15 pm

The final version of the SDK released. Please see the release announce for details.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Beta version of the new SDK release 2010 II

Postby KazyFreenna » Wed Aug 11, 2010 8:40 pm

I am just curious. If things remain as they now stand are you planning to maintain your themes in version 4 or not?
KazyFreenna
 
Posts: 6
Joined: Sat Jul 17, 2010 5:31 am
Location: Denmark


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 7 guests