For advanced Amibroker developers, it’s a common need to convert their AFL to DLL, so that they can distribute their proprietary indicators or trading systems without exposing the underlying logic. In this article, we’ll learn how to convert an AFL to DLL using Dot Net for Amibroker SDK.
Please refer to Part 1 of this article where we have explained in detail about DLL (dynamic link libraries), Dot net for Amibroker, and some of the benefits of converting your AFL into DLL code.
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
Also Read: Develop and Backtest Options Trading system in Amibroker
Steps to convert an AFL to DLL
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 convert AFL to DLL:
Step 1: Verify if you are able to see a folder named “.Net for Amibroker” inside your Amibroker installation directory.
Step 6: Once the AFL code is loaded in the AFLXComplier application, click on File → Compile AFL to C#, you will see the generated C# code in the right-hand pane. Errors (if any) will appear in the bottom pane. Step 8: 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. As you can see, we are calling the C# function from AFL code, and since the function call is colored in blue, AFL recognizes it all fine. Save this AFL code and load it on a chart. You’ll see a Price with SMA chart as below. Once you have converted your AFL code into a DLL plugin, it can be protected and licensed by commercial protection tools like IntelliLock, CliSecure Licensing, .NET Licensing Pro, etc. The protected plugins can be made public and only customers who were given licenses for their machines can use the protected .NET Plug-Ins. We’ll come up with a tutorial in the future detailing all the steps to protect and license your DLL plugins. Also, we’ll look at more complex examples of AFL to DLL conversion. Until then, if you have any questions please feel free to put them in the comments section
_SECTION_BEGIN("Price with Simple Moving Average");
Plot( Close, "Price", colorWhite, styleCandle );
SimpleMovAvg = MA(C,20);
Plot (SimpleMovAvg, "Simple Moving Average", colorRed, styleLine);
_SECTION_END();
[ABMethod]
public void PricewithSMA()
{
ATArray simpleMovAvg;
AFMisc.SectionBegin("Price with Simple Moving Average");
AFGraph.Plot(Close, "Price", (float)Color.White, (float)Style.Candle);
simpleMovAvg = AFAvg.Ma(Close, 20f);
AFGraph.Plot(simpleMovAvg, "Simple Moving Average",(float)Color.Red, (float) Style.Line) ;
AFMisc.SectionEnd();
}
It copies the compiled assembly of the project to .NET for AmiBroker’s Assemblies folder (Amibroker.NET for AmiBrokerAssemblies).
_SECTION_BEGIN("Price with SMA DLL");
PricewithSMA();
_SECTION_END();
What’s next after Converting AFL to DLL?