Guest User | Sign In

Knowledge Base

GetData Example - Tool Programming

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); 
   i : Integer; 
   iIndex : Integer; 
   D1 := GetData('CODE=SPX:WI'); // this means code is SPX from the World Indices Exchange (WI) 
   for i := ProcessStart to ProcessEnd do 
      iIndex := D1.DateToIndex(DataIn.Row[i].Date); 
      if iIndex >=0 then 
         Plot1.Row[i].Date := D1.Row[iIndex].Date; 
         Plot1.Row[i].Close := D1.Row[iIndex].Close; 

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
    // 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;

Please Wait!

Please wait... it will take a second!