core.host:execute("isTableFilled", "trades") core.host:execu

Moderator: admin

core.host:execute("isTableFilled", "trades") core.host:execu

Postby 215607364@qq.com » Tue Dec 21, 2010 4:14 am

core.host:execute("isTableFilled", "trades")
core.host:execute("isReadyForTrade")
I find this two functions in a strategy code below:
why I did not find this two functions in Indicore SDK help document?
Can I have the Complete Indicore SDK help document?
Code: Select all
function Init()
    strategy:name("Set stop by order's life time");
    strategy:description("Strategy changes stop followiung to the order's life time");

    strategy.parameters:addGroup("Stop Parameters");
    strategy.parameters:addInteger("TimeInterval", "Time interval for trailing, in minutes", "", 60, 1, 100000);
    strategy.parameters:addInteger("StepTrailing", "Step for trailing", "", 10, 1, 1000);

    strategy.parameters:addString("Type", "Price type", "", "Bid");
    strategy.parameters:addStringAlternative("Type", "Bid", "", "Bid");
    strategy.parameters:addStringAlternative("Type", "Ask", "", "Ask");

    strategy.parameters:addGroup("Trade");
    strategy.parameters:addString("Trade", "Choose Trade", "", "");
    strategy.parameters:setFlag("Trade", core.FLAG_TRADE);
end

local tradeExist = true;
local first = true;
local stopOrder = nil;      -- the identifier of the stop order
local tsource = nil;
local timer;
local minChange;
local executing = false;
local LastTime;

function Prepare(onlyName)
    local name;
    name = profile:id() .. "(" .. instance.bid:instrument()  ..
                           "," .. instance.parameters.TimeInterval .. "," ..
                           "," .. instance.parameters.StepTrailing .. "," ..
                           instance.parameters.Trade .. ")";
    instance:name(name);
    if onlyName then
        return ;
    end

    minChange = math.pow(10, -instance.bid:getPrecision());

    ExtSetupSignal(name .. ":", true);
    tsource = ExtSubscribe(1, nil, "t", instance.parameters.Type == "Bid", "close");
    LastTime=core.now();
end

function ExtUpdate(id, source, period)
    if id == 1 and tradeExist then
        if period > tsource:first() then
            -- check whether trade exists
            local trade, order;

            if not(core.host:execute("isTableFilled", "trades")) then
                core.host:trace("not filled");
                -- relogin??
                return ;
            end

            if not(core.host:execute("isReadyForTrade")) then
                -- relogin??
                core.host:trace("not ready");
                return ;
            end

            trade = core.host:findTable("trades"):find("TradeID", instance.parameters.Trade);

            if trade == nil then
                tradeExist = false;
                terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "Trade " .. instance.parameters.Trade .. " disappear", instance.bid:date(NOW));
                core.host:execute("stop");
                return ;
            end

            local stopValue, valuemap, success, msg;
            local stopSide;
            local FlTrail=false;
           
            if math.floor((core.now()-LastTime)*1440)>=instance.parameters.TimeInterval then
             FlTrail=true;
             LastTime=core.now();
            end
           
            if FlTrail==false then
             return ;
            end
           
            if trade.StopOrderID == "" or trade.StopOrderID == nil then
             return ;
            end
           
            if trade.BS == "B" then
                stopValue=trade.Stop+instance.parameters.StepTrailing*instance.bid:pipSize();
               stopSide = "S";
               if stopValue >= instance.bid[NOW] then
                   --core.host:trace(string.format("not passed %f >= %f", stopValue, instance.bid[NOW]));
                   return ;
               end
            else
                stopValue=trade.Stop-instance.parameters.StepTrailing*instance.bid:pipSize();
               stopSide = "B";
               if stopValue <= instance.ask[NOW] then
                   --core.host:trace(string.format("not passed %f <= %f", stopValue, instance.ask[NOW]));
                   return ;
               end
            end


                if math.abs(stopValue - trade.Stop) > minChange then
                    -- stop exists
                    valuemap = core.valuemap();
                    valuemap.Command = "EditOrder";
                    valuemap.AcctID = trade.AccountID;
                    valuemap.OrderID = trade.StopOrderID;
                    valuemap.Rate = stopValue;
                    executing = true;
                    success, msg = terminal:execute(200, valuemap);
                    if not(success) then
                        executing = false;
                        terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "Failed change stop " .. msg, instance.bid:date(NOW));
                    end
            end
        end

    end
end
function ExtAsyncOperationFinished(id, success, message)
    if id == 200 then
        executing = false;
        if not(success) then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "Failed create/change stop " .. message, instance.bid:date(NOW));
        end
    end
end
dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");
215607364@qq.com
 
Posts: 13
Joined: Mon Oct 11, 2010 9:56 pm

Re: core.host:execute("isTableFilled", "trades") core.host:execu

Postby Nikolay.Gekht » Wed Dec 22, 2010 10:27 am

These functions are documented in beta SDK (viewtopic.php?f=28&t=2178). This SDK will be released with new TS (Jan, 07)

In short, the first function returns true in case the table specified is completely filled (it can be not filled right after the login or if the user call "Refresh" command in TS).

The second function returns true is all the tables are filled and TS can trade with no limitations (the same logic as used to enable/disable BUY/SELL buttons of the trading station).
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 53 guests