Catalog · How the catalog works
TALib4D
TA-Lib 4 Delphi.
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
TALib4D
Delphi wrapper for TA-Lib - a widely used technical analysis library for financial market data.
Features
- Wraps the native TA-Lib C dynamic library for use in Delphi applications
- Supports both 32-bit and 64-bit Windows
- Provides access to over 500 TA-Lib technical indicators and functions
- Dynamic DLL loading with error handling (planned/future)
- Easy to extend and integrate with your Delphi projects
- Includes unit tests demonstrating usage and correctness
Requirements
- Delphi (tested with Delphi 10.x and above)
- TA-Lib DLL (
ta-lib.dll) for Windows x86 and x64 - Compatible with Windows 32-bit and 64-bit platforms
Installation
- Clone or download this repository.
- Place the appropriate TA-Lib DLL in the
static/windows-x86_32/orstatic/windows-x86_64/folder. - Add the
srcfolder to your Delphi project search path. - Use the wrapper unit (
MWQ.TALibWrapper.pas) in your Delphi project.
Usage Example: Testing SMA (Simple Moving Average)
This example shows how to initialize TA-Lib, calculate the SMA on a sample input array, verify results, and then properly shutdown TA-Lib.
procedure TestTALibWrapper.TestSMA_CalculatesCorrectly;
var
Input: TArray<TA_Real>;
Output: array[0..9] of TA_Real;
I, BegIdx, NbElem: Integer;
Status: TA_RetCode;
TempString: string;
begin
Input := [44.34, 44.09, 44.15, 43.61, 44.33, 44.83, 45.10, 45.42, 45.84, 46.08];
Status := TA_Initialize;
Assert.AreEqual(TA_RetCode.TA_SUCCESS, Status, 'TA_Initialize failed');
Status := TA_SMA(
0, High(Input), @Input[0], 5,
@BegIdx, @NbElem, @Output[0]);
Assert.AreEqual(TA_RetCode.TA_SUCCESS, Status, 'TA_SMA failed');
Assert.AreEqual(6, NbElem, 'Unexpected number of SMA output values');
Assert.AreEqual(4, BegIdx, 'Unexpected beginning index');
// Verify the first SMA value (with tolerance)
Assert.AreEqual(44.104, Output[0], 0.001, 'Unexpected SMA[0]');
// Print the SMA results
for I := 0 to NbElem - 1 do
begin
TempString := Format('SMA[%d] = %.3f', [I + BegIdx, Output[I]]);
Writeln(TempString);
end;
SetLength(Input, 0);
TA_Shutdown;
end;About the Wrapper Generation
The main wrapper unit, MWQ.TALibWrapper.pas, is automatically generated using Chet, a C header to Delphi translator developed by Neslib.
Currently, the generated wrapper uses static external declarations to link directly to the TA-Lib DLL functions by name. This approach requires the TA-Lib DLL (ta-lib.dll) to be available at runtime but does not perform explicit dynamic loading or function pointer retrieval.
Future Improvements
A dynamic DLL loading mechanism (using LoadLibrary and GetProcAddress) could be implemented to:
- Load the DLL at runtime explicitly
- Handle missing DLLs more gracefully
- Support runtime switching between 32-bit and 64-bit DLLs depending on the application
For more information about Chet, visit the Chet GitHub repository.
Thank you for using TALib4D!

