Skip to content

GetData Example - Tool Programming

By Optuma Team · Updated 2019-09-10

The GETDATA function can be used to retrieve data from a security different from the chart to which the tool is applied.

To use the GETDATA function you just pass the code you want to open, easiest way is to open it as a TDataList and you can access the data like a plot i.e.

var D1 : TDataList;
procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
var
i : Integer;
iIndex : Integer;
begin
D1 := GetData('CODE=SPX:WI'); // this means code is SPX from the World Indices Exchange (WI)
for i := ProcessStart to ProcessEnd do
begin
iIndex := D1.DateToIndex(DataIn.Row[i].Date);
if iIndex >=0 then
begin
Plot1.Row[i].Date := D1.Row[iIndex].Date;
Plot1.Row[i].Close := D1.Row[iIndex].Close;
end;
end;
end;

Now because the number of bars for the result from GETDATA might be different from the number of bars in the chart, the rows will not have the same index. So to compare bars of the same date you will need to find the correct index from the date using the DateToIndex function e.g.

D1 := GetData('CODE=SPX:WI');
//loop through the source code
for i := 0 to DataIn.Count-1 do
begin
// lookup the SPX index for each bar date
iIndex := D1.DateToIndex(DataIn.Row[i].Date);
if iIndex > 0 then
bClosesHigher := DataIn.Row[i].close) > D1.Row[iIndex].Close;
end;

Forum Discussion

Choose which categories of cookies you allow. Strictly-necessary cookies are always on. You can change this any time via the "Cookie Settings" link in the footer.

  • Functional

    Remember preferences like dismissed banners and your dark-mode choice.

  • Analytics

    Help us understand how the site is used so we can improve it.

  • Marketing

    Measure our advertising and help us reach people who may be interested in Optuma.