Tables and Arrays

Moderator: admin

Tables and Arrays

Postby Lua_Student » Sat Nov 19, 2011 4:17 pm

Hi:

I was reading in the Indicore SDK manual in "The structure of an Indicator: Update (period, mode)" section that:

"Please note that the period index for the same date and time can be changed, when data appears or disappears at the beginning of the source stream. Therefore, you must not use arrays and tables to keep intermediate data for the periods. Use the internal streams instead."

I do see where this could really mess up tables and arrays when the price index (ie. firstperiod()) changes, but does this mean I shouldn't use tables or arrays at all when creating indicators? As an example: How could I store some price values within a set of periods and count the ones within a specific price range as intermediate data using internal streams?

The internal stream instruction quoted above left me confused because the SDK manual has some sections showing table and array-related commands.

Any clarity would be very helpful. Thanks!
Lua_Student
 
Posts: 5
Joined: Sun Nov 06, 2011 10:28 pm

Re: Tables and Arrays

Postby Victor.Tereschenko » Mon Nov 21, 2011 5:47 am

You can use tables/arrays if a number of items in these tables/arrays doesn't depend from the number of rates in the source (some constant number of items).
You can look for examples of internal streams usage in standard indicators: ATR, ADX, CMO, DMI...
Code: Select all
function Prepare()
...
    tr = instance:addInternalStream(source:first() + 1, 0);
...
end

function getTrueRange(period)
    local hl = tAbs(source.high[period] - source.low[period]);
    local hc = tAbs(source.high[period] - source.close[period - 1]);
    local lc = tAbs(source.low[period] - source.close[period - 1]);

    local tr = hl;
    if (tr < hc) then
        tr = hc;
    end
    if (tr < lc) then
        tr = lc;
    end
    return tr;
end

-- Indicator calculation routine
function Update(period)
    if period >= trFirst then
        tr[period] = getTrueRange(period);
    end
    if period >= first then
        ATR[period] = mathex.avg(tr, period - n + 1, period);
    end
end

Or you can post your code with tables/arrays and I'll write a version of your code with internal streams.
“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: Tables and Arrays

Postby Lua_Student » Mon Nov 21, 2011 6:53 pm

Hi Victor:

You answered my tables question very clearly and it seems I will have to use internal streams. I also looked at the code you posted along with ADX & DMI that I had already downloaded (as per your suggestion).

I now see a lot more clearly how to place the variables I need, so no worries on having to post fresh code. Thank you for your generous assistance! :)
Lua_Student
 
Posts: 5
Joined: Sun Nov 06, 2011 10:28 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 71 guests