Indicore SDK for 2010, III release

Moderator: admin

Indicore SDK for 2010, III release

Postby Nikolay.Gekht » Fri Jul 09, 2010 1:59 pm

Ok. I'm back with a good news.

The 2010, III release is almost ready for the beta testing. What's new (from point of view of the indicator core)? Well. Many things.

Indicator-related changes:

1) Now you can specify line width and style for the indicator lines, indicator level lines and free-form lines.

See output_stream:setStyle, output_stream:setWidth, output_stream:addLevel methods.

2) You can also specify tooltip for the indicator free-form lines.

3) You can specify precision for the individual output stream of the indicator (output_stream:setPrecision).

4) You can create a volume output for the candles group (instance:createCandleGroup (label, id, open, high, low, close, volume?)).

5) Both, indicators and signals now can access to the trading information (orders, trades and so on). See host:findTable method.

Signal-related things:

1) Signal now can send emails. See terminal:alertEmail() method.

2) Signal now can trade. See terminal:execute() method.

Strategy debugger (luadbg1) changes.

1) The tick stream now can be simulated on the base of High-Low-Close or Low-High-Close patterns, i.e. it creates three ticks instead of one for each candle of the chosen price history.

2) The debugger simulates all trading table, so you can monitor simulated trades during the step-by-step strategy execution.

Both debuggers. Now the standard indicators are moved into indicators/standard folder. So, your startegy and indicators can use any of the standard indicator, but these indicators does not appear in the "Open Indicator" command.

The beta SDK can be downloaded here: http://www.gehtsoftusa.com/bin/IndicoreSDK.exe

The beta Trading Station is expected in a week. The official release is expected in the beginning of august.

Note about volumes. The trading station is completely ready to support volume. Unfortunately, we aren't sure whether the server side components will be ready to provide tick volume before the official release, so, probably, tick volume for the instruments will be available a bit later than the Trading Station release.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Indicore SDK for 2010, III release

Postby Nikolay.Gekht » Fri Jul 09, 2010 2:03 pm

An example of the simple Moving Average cross strategy. Work in all trading modes: FIFO, non-FIFO-hedging and non-FIFO-non-hedging.

Code: Select all
function Init()
    strategy:name("MA test trading");
    strategy:description("DO NOT USE IT ON A REAL ACCOUNT!!!");

    strategy.parameters:addInteger("FN", "Fast MVA", "", 5, 1, 300);
    strategy.parameters:addInteger("SN", "Slow MVA", "", 20, 1, 300);

    strategy.parameters:addString("Period", "Timing period", "", "t1");
    strategy.parameters:setFlag("Period", core.FLAG_PERIODS);
    strategy.parameters:addInteger("TS", "Trade Size (in lots)", "", 1, 1, 100);
end

local FN;
local SN;
local TS;
local FMA;
local SMA;
local source;
local instr_id;
local acct_id;
local hedging;

function Prepare()
    FN = instance.parameters.FN;
    SN = instance.parameters.SN;
    TS = instance.parameters.TS;

    assert(FN < SN, "Fast MVA must be faster than slow MVA");

    gSource = ExtSubscribe(1, nil, instance.parameters.Period, true, "close");

    FMA = core.indicators:create("MVA", gSource, FN);
    SMA = core.indicators:create("MVA", gSource, SN);

    local name = profile:id() .. "(" .. instance.bid:instrument()  .. "(" .. instance.parameters.Period  .. ")" .. "," .. FN  .. "," .. SN .. ")";
    instance:name(name);

    -- find offer
    instr_id = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;
    -- get the first existing account
    local acct = core.host:findTable("accounts"):enumerator():next();
    hedging = acct.Hedging ~= "N";
    acct_id = acct.AccountID;

    -- size for the trade
    TS = TS * core.host:execute("getTradingProperty", "baseUnitSize", instance.bid:instrument(), acct_id);
end

function ExtUpdate(id, source, period)
    FMA:update(core.UpdateLast);
    SMA:update(core.UpdateLast);

    if not(SMA.DATA:hasData(period - 1)) then
        return ;
    end

    local enum, row, i;
    local success, msg;

    if core.crossesOver(FMA.DATA, SMA.DATA, period) then
        -- buy
        if hedging then
            if closeAll("S") == 0 then
                success, msg = buy();
            else
                success = true;
            end
        else
            success, msg = buy();
        end
        assert(success, msg);
   
    elseif core.crossesOver(SMA.DATA, FMA.DATA, period) then
        -- sell
        if hedging then
            if closeAll("B") == 0 then
                success, msg = sell();
            else
                success = true;
            end
        else
            success, msg = sell();
        end
        assert(success, msg);
    end
end

function sell()
    local valuemap = core.valuemap();
    valuemap.OrderType = "OM";
    valuemap.OfferID = instr_id;
    valuemap.AcctID = acct_id;
    valuemap.BuySell = "S";
    valuemap.Quantity = TS;
    local success, msg;
    success, msg = terminal:execute(100, valuemap);
    return success, msg;
end

function buy()
    local valuemap = core.valuemap();
    valuemap.OrderType = "OM";
    valuemap.OfferID = instr_id;
    valuemap.AcctID = acct_id;
    valuemap.BuySell = "B";
    valuemap.Quantity = TS;
    local success, msg;
    success, msg = terminal:execute(100, valuemap);
    return success, msg;
end

function closeAll(side)
    local enum, row, count, success, msg;

    count = 0;
    -- if hedging is on - check whether short
    -- position exists - and close them instead of
    -- opening a new long
    enum = core.host:findTable("trades"):enumerator();
    while true do
        row = enum:next();
        if row == nil then
            break;
        end
        if row.AccountID == acct_id and row.OfferID == instr_id and
            row.BS == side then
            success, msg = close(row);
            assert(success, msg);
            count = count + 1;
        end
    end
    return count;
end

function close(trade)
    local valuemap = core.valuemap();
    valuemap.OrderType = "CM";
    valuemap.OfferID = instr_id;
    valuemap.AcctID = acct_id;
    valuemap.Quantity = trade.Lot;
    valuemap.TradeID = trade.TradeID;
    if trade.BS == "B" then
        valuemap.BuySell = "S";
    else
        valuemap.BuySell = "B";
    end
    local success, msg;
    success, msg = terminal:execute(100, valuemap);
    return success, msg;
end

function ExtAsyncOperationFinished(cookie, success, message)
    assert(success, message);
end

dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 18 guests