GetData Example - Tool Programming

Author: Optuma Team Last updated: Sep 10, 2019 08:59

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

NOTE: For the scripting language version please see here.

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;

Discussion