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 22.214.171.1243
- 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:
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:
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.
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:
If you want to manually remove the DLL from the GAC, you can do this by using the following command:
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.
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.
In the end we have to compile all scripts in AgenaTrader.