Skip to main content

For seasoned Amibroker developers, being able to Convert an AFL to DLL is essential to distribute proprietary indicators or trading systems while keeping the core logic confidential. This article unfolds the process of converting an AFL to a DLL, harnessing the capabilities of the Dot Net for Amibroker SDK.

For an in-depth understanding of DLLs and Dot net for Amibroker, don’t miss Part 1 of this series, where we covered these topics extensively.

Essential Preparations

  • Get the latest Amibroker version. Visit here for download.
  • Install the Visual Studio community edition from this link.
  • Acquire .Net for Amibroker. Ensure compatibility with your Amibroker version from here.

Watch this video for a visual guide on installing .Net for Amibroker:

Basic knowledge of Amibroker AFL and Visual C# is necessary for this tutorial.

Recommended Reading: Develop and Backtest Options Trading System in Amibroker

Converting AFL to DLL: The Process

Make sure you’ve completed the prerequisites before proceeding.

Here are the steps to transform your AFL into a DLL:

Step 1: Confirm the presence of a folder named “.Net for Amibroker” in your Amibroker installation directory.

AFL-to-DLL-1

If it’s missing, reinstall .Net for Amibroker.

Step 2: Open Microsoft Visual Studio and select ‘Open a Project or Solution’ from the Get Started Menu.

AFL-to-DLL-2

Navigate to “AmiBroker.NET for AmiBrokerSamplesSourcesAFL Plug-insSamplePlugInCS” and open the project file SamplePlugInCS_VS2010.csproj.

AFL-to-DLL-3

Step 3: The sample project will appear in the solution explorer.

AFL-to-DLL-4

Step 4: Go to “AmiBroker.NET for AmiBrokerTools” and start “AflXCompilerx64.exe.”

Note: A licensed .Net for Amibroker is needed for effective use.

Step 5: Launch the application, choose File → Open AFL File, and select the AFL you wish to convert.

AFL-to-DLL-5

Here’s a simple AFL for illustration:

				
					console.log( 'Code is Poetry' );_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();
				
			
Step 6: Compile the AFL to C# in AFLXComplier and review the generated code. AFL-to-DLL-6 Step 7: Copy the C# code into BasicSamples.cs in the SamplePlugInCS_VS2010 project.
				
					[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();

        }
				
			
Step 8: Build the solution in Visual Studio. AFL-to-DLL-7 Post-build, the file AmiBroker.Samples.SamplePlugInCS.dll will appear in the Assemblies folder. AFL-to-DLL-8 Step 9: In Amibroker, create a new AFL and call the PricewithSMA function.
				
					_SECTION_BEGIN("Price with SMA DLL");

PricewithSMA();

_SECTION_END();
				
			

AFL-to-DLL-9

Save this AFL code and load it on a chart to view the Price with SMA chart.

AFL-to-DLL-10

With C# encapsulating multiple lines of code into one function, the underlying logic in AFL remains concealed.

To distribute your AFL code broadly without revealing the logic, this process is the key.

After Converting AFL to DLL

After converting AFL to DLL, protect and license your plugin using tools like IntelliLock, CliSecure Licensing, or .NET Licensing Pro. These tools allow you to make your plugins public while ensuring only licensed customers can use them.

We plan to provide a detailed tutorial on protecting and licensing your DLL plugins in the future. Additionally, we’ll explore more complex examples of AFL to DLL conversion.

In the meantime, if you have any questions or need assistance, please don’t hesitate to ask in the comments section.

Leave a Reply