Guest User | Sign In

Knowledge Base

Calling DLL Example

This is the C source code to build the dll for Market Analyst to process the data list. The dll is called matool.dll.

#include <stdio.h>
#include <math.h>
// datain and dataout are two dimensional arrays with the following columns
#define DBDATE 0
#define DBCLOSE 1
#define DBHIDDEN 2
#define DBHIGH 3
#define DBLOW 4
#define DBOPEN 5
#define DBVOLUME 6
#define DBOI 7
#define DBBARTYPE 8
#define DBHIGHTIME 9
#define DBLOWTIME 10
#define DBFACTOR 11
#define DBCOLOUR 12
#define UnixStartDate 25569.0
// Converts MA DateTime to Unix seconds
// dtDate = the Date and Time that you want to convert
// returns the number of seconds since UTC 1 January 1970
long DateTimeToUnix(double dtDate)
    return lround((dtDate - UnixStartDate) * 86400);
extern "C"
    // datain and dataout are two dimensional arrays of double - both are the same size
    // this example simply adds 10 to the close of the data in.
    __declspec(dllexport) void processdata(double **datain, double **dataout, int count)
        int i;
        for (i = 0; i<count; i++) {
           dataout[i][dbclose]=datain[i][DBCLOSE] += 10; // in this case the other columns are left as zero 

This is the custom code source code in Market Analyst Custom tool to load and use the dll to process the data list.

// Sample script for Market Analyst tool programming using a C dll to process the data list.
// This section is where variable are defined that need to be used in both the Init and Process procedures
    Plot1 : TPlot;
// declare the procedure from the dll used to process the data list.
procedure processdata(datain, dataout: pointer; count: Integer); stdcall; external 'matool.dll' name 'processdata';
// DefineTool is where the settings for the Tool are defined
// This procedure is called once when the tool is loaded
// Normally this procedure does not need to be changed
procedure DefineTool(Tool : TTool);
    Tool.Name := 'dllprocess';
    Tool.MouseClicks := 1;
    Tool.Hint := '';
    Tool.ToolType := ttDataList;
// Init is called to initialise the tool
// This procedure is called once when the tool is added to a chart
procedure Init(Tool : TTool);
    Plot1 := Tool.AddPlot();
    Plot1.Color := clBlue;
    Plot1.PlotStyle := Line; // possible values are (Line, Dot, Histogram, Stepped, Shaded)
    Plot1.FillColor := clBlue;
    Plot1.LineStyle := Dash;
// Process is called to calculate and drawn the tool on screen
// This procedure is called when new data is received or loaded and
// when a selection point is moved by the user
procedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);
    Plot1.Data.SetSize(datain.Count); // set the output plot the same size as the input data
    processdata(DataIn.DataArray, Plot1.Data.DataArray, Plot1.Count); // pass the data to the c dll

Please Wait!

Please wait... it will take a second!