function call time out

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

function call time out

Postby blue5519 » Wed Mar 28, 2012 11:08 am

Hi Guys

I've written a strategy that has some lengthy analysis using nested looped and when I'm running it the strategy gets stopped with an error message about the function running for longer than 30 seconds. Is there any command or setting that will allow a function to run for longer than 30 seconds? BTW I've tried breaking up my loops and I still get the same error because each loop runs for more than 30 secs.

Thanks for the help

J.K.
blue5519
 
Posts: 2
Joined: Wed Mar 28, 2012 10:22 am

Re: function call time out

Postby Nikolay.Gekht » Wed Mar 28, 2012 11:15 am

No, this limitation prevents the strategy from handing Marketscope especially when a backtester or optimizer is running. There is no way to overcome this limitation. However, this is a good flag that:
a) calculation shall be optimized
b) C++ must be used for calculation
c) possible calculation must be done in parallel thread

The common rule is that indicator or strategy must return the control back to Martketscope ASAP.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: function call time out

Postby boss_hogg » Tue Feb 26, 2013 2:56 pm

I'm having the same issue , here is how: I'm implementing more than one different strategies on the same instrument; this means that when a strategy closes one or more positions, it must close its own positions, not the other strategy's positions.

One of the strategies is the Donchian Strategy I found in fxcodebase, but since I need to close only its own positions, I changed the closing function like this: instead of using
Code: Select all
valuemap.NetQtyFlag = "Y";
I call a findTrade function which returns the first trade of the same AccountID, OfferID, QTXT, Instrument and BS , close this trade, and keep calling findTrade until it returns nil.

The problem is that I get the 30 sec error msg even when less than 10 trades are running on TSII. It is hard to believe that going ten times (max) through a ten-row table takes more than 30 seconds!!!

I would also really appreciate some help on this, because the error pauses the strategy and this has already costed me some money...

Here is the code:

Code: Select all
function findTrade(BuySell)
    local enum, row;
    local foundRow = false;

    enum = core.host:findTable("Trades"):enumerator();
    row = enum:next();

    while not(foundRow) and row~=nil do
        if row.AccountID == Account and
           row.OfferID == Offer and
           row.QTXT=="DONCHIAN" and
           row.Instrument == instance.bid:instrument() and
           row.BS == BuySell then
             foundRow = row;
        end
        row = enum:next();
    end

    return foundRow;
end


function exit(BuySell)
    if not(AllowTrade) then
        return true;
    end

    local enum, row, valuemap, success, message;

    row = findTrade(BuySell);
    if row then
        valuemap = core.valuemap();
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "CM";  -- Close Market
        valuemap.OfferID = Offer;
        valuemap.AcctID = Account;
        valuemap.Quantity = row.Lot;
        valuemap.TradeID = row.TradeID;
        if row.BS == "B" then
            valuemap.BuySell = "S";
        else
            valuemap.BuySell = "B";
        end

        success, message = terminal:execute(101, valuemap);
        if not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "Close trade failed: " .. message, instance.bid:date(NOW));
        end

        exit(BuySell);  -- executed only if row~=nil
    end
end
boss_hogg
FXCodeBase: Confirmed User
 
Posts: 48
Joined: Fri Oct 26, 2012 3:03 am

Re: function call time out

Postby boss_hogg » Wed Mar 13, 2013 6:11 pm

Hi again....I still haven't solved this, is there any way this way of exiting can be done :?: :?: :?:
boss_hogg
FXCodeBase: Confirmed User
 
Posts: 48
Joined: Fri Oct 26, 2012 3:03 am

Re: function call time out

Postby Victor.Tereschenko » Fri Mar 15, 2013 5:58 am

boss_hogg wrote:I'm having the same issue , here is how: I'm implementing more than one different strategies on the same instrument; this means that when a strategy closes one or more positions, it must close its own positions, not the other strategy's positions.

One of the strategies is the Donchian Strategy I found in fxcodebase, but since I need to close only its own positions, I changed the closing function like this: instead of using
Code: Select all
valuemap.NetQtyFlag = "Y";
I call a findTrade function which returns the first trade of the same AccountID, OfferID, QTXT, Instrument and BS , close this trade, and keep calling findTrade until it returns nil.

The problem is that I get the 30 sec error msg even when less than 10 trades are running on TSII. It is hard to believe that going ten times (max) through a ten-row table takes more than 30 seconds!!!

I would also really appreciate some help on this, because the error pauses the strategy and this has already costed me some money...

Here is the code:

Code: Select all
function findTrade(BuySell)
    local enum, row;
    local foundRow = false;

    enum = core.host:findTable("Trades"):enumerator();
    row = enum:next();

    while not(foundRow) and row~=nil do
        if row.AccountID == Account and
           row.OfferID == Offer and
           row.QTXT=="DONCHIAN" and
           row.Instrument == instance.bid:instrument() and
           row.BS == BuySell then
             foundRow = row;
        end
        row = enum:next();
    end

    return foundRow;
end


function exit(BuySell)
    if not(AllowTrade) then
        return true;
    end

    local enum, row, valuemap, success, message;

    row = findTrade(BuySell);
    if row then
        valuemap = core.valuemap();
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "CM";  -- Close Market
        valuemap.OfferID = Offer;
        valuemap.AcctID = Account;
        valuemap.Quantity = row.Lot;
        valuemap.TradeID = row.TradeID;
        if row.BS == "B" then
            valuemap.BuySell = "S";
        else
            valuemap.BuySell = "B";
        end

        success, message = terminal:execute(101, valuemap);
        if not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "Close trade failed: " .. message, instance.bid:date(NOW));
        end

        exit(BuySell);  -- executed only if row~=nil
    end
end

terminal:execute is an async command. It will not remove the trade from the trades table until your strategy will return the execution from the update function.
Try sligtly different algorith: enumerate all rows (like in findTrade) but instead of returning the row call exit for it:
Code: Select all
function exitAll(BuySell)
    if not(AllowTrade) then
        return;
    end

    local enum, row;
    local foundRow = false;

    enum = core.host:findTable("Trades"):enumerator();
    row = enum:next();

    while row~=nil do
        if row.AccountID == Account and
           row.OfferID == Offer and
           row.QTXT=="DONCHIAN" and
           row.Instrument == instance.bid:instrument() and
           row.BS == BuySell then
             exit(row);
        end
        row = enum:next();
    end
end

function exit(row)
    local enum, valuemap, success, message;

    if row then
        valuemap = core.valuemap();
        valuemap.Command = "CreateOrder";
        valuemap.OrderType = "CM";  -- Close Market
        valuemap.OfferID = Offer;
        valuemap.AcctID = Account;
        valuemap.Quantity = row.Lot;
        valuemap.TradeID = row.TradeID;
        if row.BS == "B" then
            valuemap.BuySell = "S";
        else
            valuemap.BuySell = "B";
        end

        success, message = terminal:execute(101, valuemap);
        if not success then
            terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], "Close trade failed: " .. message, instance.bid:date(NOW));
        end
    end
end
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 144
Joined: Fri Nov 19, 2010 8:55 am

Re: function call time out

Postby boss_hogg » Fri Apr 19, 2013 4:01 am

It works, no issues so far!

Thank you Victor :D
boss_hogg
FXCodeBase: Confirmed User
 
Posts: 48
Joined: Fri Oct 26, 2012 3:03 am

Re: function call time out

Postby shayanjameel08 » Wed Oct 23, 2013 1:36 am

Call a function with parameters applied:
Use an anonymous function as a wrapper:

searchTimer = setTimeout(function () {
doSearch('parameter');
}, 250);
shayanjameel08
 
Posts: 1
Joined: Sat Oct 19, 2013 5:50 am


Return to Discussions

Who is online

Users browsing this forum: No registered users and 24 guests