Integrate an AgenaScript DLL into AgenaTrader


The integration of an AgenaScript DLL into the AgenaTrader is an extremely useful option, because you can centrally classify classes, extensions and global functions, and you do not have to duplicate this source code in scripts such as indicators or conditions (duplicate code = error!).

Our test-DLL shown in this article was created in Visual Studio and integrated into AgenaTrader with the following setup:

  • Windows 10 64bit
  • Agena Trader Andromeda
  • Visual Studio Ultimate 2013 (community edition also possible)
  • For all activities we are using .NET Framework 3.5
  • Visual Studio was launched with the Administrator account to make it possible to copy the DLL into the GAC.

For AgenaTrader in version 1.9 and above, Visual Studio 2015 is recommended and .NET Framework 4.6 is required.

Create an AgenaScript DLL in Visual Studio

Für die Erstellung unserer sehr einfache DLL nutzen wir Visual Studio und erstellen ein Projekt mit dem Typ Klassenbibliothek. Der Name unserer Projektes ist AgenaTraderDLL da dieser Name später benötigt wird. Unsere sehr einfache DLL besteht aus folgendem Code:

To create our very simple DLL, we use Visual Studio and create a project with the type classlibrary. The name of our projects is AgenaTraderDLL. This name is needed later. Our very simple DLL consists of the following code:

[pastacode lang=”java” manual=”using%20System%3B%0Anamespace%20AgenaTraderDLL%0A%7B%0Apublic%20static%20class%20ExternalHelper%20%7B%0Apublic%20static%20String%20Test()%20%7B%0Areturn%20%22Hello%20World!%22%3B%0A%7D%0A%7D%0A%7D” message=”” highlight=”” provider=”manual”/]

Before we compile the script we need to sign the project first. You will find the settings for signing within the project settings.


The DLL created by us has to be copied to the GAC (Global Assembly Cache) using gacutil.exe. An alternative is to create an MSI package. Using gacutil is the better (faster) solution during development. Since we use .Net 3.5, we have to use gacutil from the following folder:

[pastacode lang=”bash” manual=”C%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20SDKs%5CWindows%5Cv7.0A%5CBin%5Cgacutil.exe” message=”” highlight=”” provider=”manual”/]

To reduce the workload while copying to the GAC, the Visual Studio post-build process can be used, so after each build process, Visual Studio copies the newly created DLL to the GAC.

[pastacode lang=”bash” manual=”C%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20SDKs%5CWindows%5Cv7.0A%5CBin%5Cgacutil.exe%22%20%2Fi%20%22%24(TargetPath)” message=”” highlight=”” provider=”manual”/]

Now you are ready to compiled the DLL and it will be automatically copied to the GAC.

To ensure that the DLL is actually present in the GAC, the following command can be used:

[pastacode lang=”bash” manual=”C%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20SDKs%5CWindows%5Cv7.0A%5CBin%5Cgacutil.exe%22%20%2Fl%20%22AgenaTraderDLL” message=”” highlight=”” provider=”manual”/]

If you want to manually remove the DLL from the GAC, you can do this by using the following command:

[pastacode lang=”bash” manual=”C%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20SDKs%5CWindows%5Cv7.0A%5CBin%5Cgacutil.exe%22%20%2Fu%20%22AgenaTraderDLL” message=”” highlight=”” provider=”manual”/]

Caution gacutil was executed in ADMINISTRATOR mode on command line!

Using our DLL in AgenaTrader

Lets start AgenaTrader and click on: Tools => Programming => Programming References. In the “Select References” window we recognize our DLL in the GAC. Via the tap “Browse” we load our DLL into the AgenaTrader and then we will find the path to the local DLL in the bottom window.

If we add the ‘using’ statement into our AgenaScript files like indicators or conditions, we can access the encapsulated functions from our DLL.

[pastacode lang=”java” manual=”using%20AgenaTraderDLL%3B” message=”” highlight=”” provider=”manual”/]

In the OnBarUpdate() event of an AgenaScript indicator or AgenaScript condition, we access the static helper from our DLL and write the value to the output of the AgenaTrader.

[pastacode lang=”java” manual=”protected%20override%20void%20OnBarUpdate()%20%7B%0AString%20helloDLLworld%20%3D%20ExternalHelper.Test()%3B%0APrint(helloDLLworld)%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

In the end we have to compile all scripts in AgenaTrader.

The source code for this article is available on our GitHub project.