Page 1 of 1

Open Position for Instrument Type

PostPosted: Wed Mar 08, 2017 12:49 am
by pesh123
Hi,
I'm building a strategy and I need to check if the are any open positions for the particular instrument type on which the strategy is being run.
Could someone kindly provide some sample linkson how to do that.
Thanks

Re: Open Position for Instrument Type

PostPosted: Sun Mar 12, 2017 4:35 pm
by Apprentice
Code: Select all
strategy.parameters:addString("Account", "Account to trade on", "", "");
strategy.parameters:setFlag("Account", core.FLAG_ACCOUNT);
Account = instance.parameters.Account;
Offer = core.host:findTable("offers"):find("Instrument", instance.bid:instrument()).OfferID;

function haveTrades()
    local enum, row;
    local found = false;
    enum = core.host:findTable("trades"):enumerator();
    row = enum:next();
    while (row ~= nil) do
        if row.AccountID == Account
      and row.OfferID == Offer
      then
            found = true;
            break;
        end
 
        row = enum:next();
    end

    return found;
end