Plugins help extend the functionalities of Amibroker beyond all the good things it can do out of the box. You can build your custom code in C++ or C# programming environment, package it as DLL, and then integrate it with Amibroker using Amibroker Development Kit (ADK). In this article, we’ll learn how to create an Amibroker AFL DLL plugin in a step-by-step fashion.
second part of this article, you’ll learn how to convert any AFL into a DLL.
Before going to the tutorial, let’s understand what is DLL?
Quoting Techopedia, “A dynamic link library (DLL) is a shared program module with ordered code, methods, functions, enums, and structures that may be dynamically called by an executing program during run time. A DLL usually has a file extension ending in .dll “
In simple words, A DLL contains a set of programs with some underlying logic that is packaged as a single executable file. This file can be invoked or integrated with external applications like Amibroker. If you are from the Java world, a JAR file is more or less equivalent to DLL
Also Read: Amibroker Custom Backtester: Step by Step Tutorial
Introducing Dot Net for Amibroker
For this tutorial, and any subsequent tutorials on this topic we’ll be using an SDK called Dot Net for Amibroker.
It is a wrapper on top of the standard Amibroker development kit (ADK) to simplify your development experience. With this tool, you can choose your favorite .NET language! All programmable AmiBroker features can be used from .NET code using C#, VB.NET, VC.NET, F#, or any .NET language. No need to hassle with native C/C++.
The intent is not to stop you from using ADK, but rather to keep your development easier by using a lot of reusable interfaces.
Dot Net for Amibroker saves a lot of development efforts and time, and hence it comes with a price tag. Starts from $59 for a standard license at the time of writing this article. But there is an option to use their free and trial plans as well.
Let’s dig into the prerequisites and detailed steps for creating your first Amibroker AFL DLL plugin.
Prerequisites
- Download and Install the latest version of Amibroker. Refer to this link.
- Download and Install the Visual studio community edition here
- Download and Install .Net for Amibroker from this link. Remember to choose the correct installation package compatible with your Amibroker version
You can refer to the below video to install .Net for Amibroker, it references the old version of Amibroker but its still valid
https://www.youtube.com/watch?v=UtMNLGqWbsU
Apart from the above, you’ll need to have an elementary knowledge of Amibroker AFL as well as visual C# to successfully complete this tutorial
Steps to create an Amibroker AFL DLL Plugin
Please make sure that you finish the prerequisites above before moving on. Otherwise, you won’t be able to proceed.
Follow the below steps to create a fresh Amibroker AFL DLL plugin:
Step 1: Verify if you are able to see a folder named “.Net for Amibroker” inside your Amibroker installation directory.
This is a simple function that plots a candlestick chart along with a 20 period exponential moving average. PriceWithEMA is a member function attributed by [ABMethod]. AFAvg, AFGraph, Plot, etc are inbuilt classes present in the Amibroker namespace. They are C# equivalents of similar functions in AFL. You can find documentation of all these functions inside the Help file in the .Net for Amibroker folder. Step 6: Build the solution. From the top-level menu bar click on Build → Build Solution, or use Ctrl+Shift+B shortcut key. In the output window, you’ll see a “Build Successful” message, or error messages if any. So for this particular sample project, post build, you’ll see a file named AmiBroker.Samples.SamplePlugInCS.dll in the Amibroker.NET for AmiBrokerAssemblies folder.
[ABMethod]
public void PriceWithEMA()
{
ATArray myFastEma = AFAvg.Ema(Close, 20);
AFGraph.Plot(myFastEma, "Ema5", Color.DarkBlue, Style.Line);
AFGraph.PlotOHLC(Open, High, Low, Close, "Close", Color.Red, Style.Candle);
}
It copies the compiled assembly of the project to .NET for AmiBroker’s Assemblies folder (Amibroker.NET for AmiBrokerAssemblies).
_SECTION_BEGIN("Price with EMA DLL");
PriceWithEMA();
_SECTION_END();