Local and global variable relationship

Section for all discussions related to development using Indicore API/SDK.

Moderator: admin

Local and global variable relationship

Postby sllouw » Sat Apr 02, 2016 2:47 am

The code below contains selected ordered fragments of the script TRADESESSIONS()
This is for the purpose of clarifying the relationship between the local variable local_source and the instance global variable.

The variable local_source is defined in the function Prepare().
It is then initialised at the beginning of the same function:

Code: Select all
local_source = instance.source;


local_source is then referenced in multiple other functions as shown in the code fragment below.

My question:
Is it necessary to make this assignment and then reference the variable as it has been done in this script?
Or can reference be made instead to instance.source where necessary?

Put another way, if I did a find “local_source” and replace with “instance.source” throughout the script would it work?

Many thanks for any reply
####
Code: Select all
-- 007            Replace source with local_source
function Init()
end
--
local local_source = nil;
function Prepare()
    local_source = instance.source;
    local_pipsize = local_source:pipSize();
    local_first = local_source:first();
    s, e = core.getcandle(local_source:barSize(), 0, 0, 0);
end
--
function Update(period)
    if period >= local_first then
        if local_ref == nil then
            local_ref = registerStream(0, "H1", 24);  -- open 1-hour stream which returns 24 bars BEFORE the start of the source collection.
        end
    end

    Process(new_york, period);
    Process(london, period);
    Process(tokyo, period);
    Process(sydney, period);
end
--
function Process(session, period)
    local date = local_source:date(period);       -- bar date;
                local open = local_source.open[t];
                local open = local_source.open[t];
                local close = local_source.close[period];
                local date_from = local_source:date(t);
                if period ~= local_source:size() - 1 then
                    date_to = local_source:date(period + 1);
                    date_to = local_source:date(period) + barsize;
                    if hi ~= local_source.high[prior_hi] then
                        price, pos = core.max(local_source.high, range);
                    if pos ~= local_source:size() - 1 then
                        prior_hi = local_source:date(pos + 1);
                        prior_hi = local_source:date(pos) + barsize;
                    if lo ~= local_source.low[prior_lo] then
                        price, pos = core.min(local_source.low, range);
                    if pos ~= local_source:size() - 1 then
                        prior_lo = local_source:date(pos + 1);
                        prior_lo = local_source:date(pos) + barsize;
end
--
function CreateSession(from, len, color, name, iname, labels)
end
--
function registerStream(id, barSize, extent)
    if (local_source:isAlive()) then
        t, to = core.getcandle(barSize, local_source:date(local_source:size() - 1), local_day_offset, local_week_offset);
    stream.data = local_host:execute("getHistory", id, local_source:instrument(), barSize, from, to, local_source:isBid());
end
--
function getDate(id, candle, precise, period)
    if (not(local_source:isAlive()) and candle > stream.data:date(stream.data:size() - 1)) then
end
--
function setBookmark(period)
end
--
function getFrom(barSize, length, extent)
    from = core.getcandle(barSize, local_source:date(local_source:first()), local_day_offset, local_week_offset);
end
--
function AsyncOperationFinished(cookie)
end
--
function findDateFast(stream, date, precise)
end
--
sllouw
 
Posts: 23
Joined: Tue Mar 08, 2016 8:28 am
Location: Queensland Australia

Re: Local and global variable relationship

Postby Julia CJ » Tue Apr 05, 2016 5:31 am

Hi Sllouw,

Or can reference be made instead to instance.source where necessary?


I'm sure that it is possible.
Julia CJ
 


Return to Discussions

Who is online

Users browsing this forum: No registered users and 1 guest