Open Position for Instrument Type

Moderator: admin

Open Position for Instrument Type

Postby pesh123 » Wed Mar 08, 2017 12:49 am

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
pesh123
 
Posts: 5
Joined: Mon Mar 06, 2017 6:08 am

Re: Open Position for Instrument Type

Postby Apprentice » Sun Mar 12, 2017 4:35 pm

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
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19000
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 5 guests

cron