AgenaScriptAgenaTraderEnglish

Integrate an AgenaScript DLL into AgenaTrader

bildschirmfoto-2016-10-14-um-20-37-41

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 1.0.8.453
  • 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:

using System;
namespace AgenaTraderDLL
{
public static class ExternalHelper {
public static String Test() {
return "Hello World!";
}
}
}


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

signate_visual_studio

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:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe

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.
visual_studio_build_process

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /i "$(TargetPath)

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:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /l "AgenaTraderDLL

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

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /u "AgenaTraderDLL

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.

using AgenaTraderDLL;

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.

protected override void OnBarUpdate() {
String helloDLLworld = ExternalHelper.Test();
Print(helloDLLworld);
}


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

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

Share