How Easy the AmiBroker AFL can be converted into C++ DLL plugin...!
There are many AFL experts who are traders as well who want to convert their AFL code business(trade) logic to host inside the DLL plugin for hiding the logic and for the distribution to their clients...
How easy is this for AFL coders?? Definitely tough and tedious job if you are directly using AmiBroker C based ADK..besides AFL coders may not know the C/C++ language.
Here is one library description that can be used for 1-1 mapping each line in the AFL code to C/C++ code..
Refer the simple example attached which shows the Pivots AFL code and its equivalent C/C++ code. Compare the line numbers between 10 to 29 high-lighted in yellow color !!!... It is virtually "Cut n Paste" i.e. "Cut as AFL & Paste as C++" operation!!...
1. AFL2DLL: Conversion of AmiBroker AFL into C/C++ DLL Plugin
(Low cost conversion of AFL to DLL)
Contents:
Background
Our Service
o AFL Plugin Development & Training
o Example Plugins
Magnetic Dynamic Levels Plugin
Magic Trend Indicator
Candle Patterns Plugin
ORB (Open Range Breakout) plugin.
o Theory
Description of the Library
Debugging of plugin using Visual Studio Platform
Example code
o Contact : AFL2DLL@GMAIL.COM
o http://bit.ly/2mQSxGw
Background:
AmiBroker is an advanced technical analysis software developed by the one-man developer genius Dr. Tomasz
Janeczko, and is widely respected financial instrument charting platform - used all over the planet earth!!, to
analyze stocks, futures, options, currencies, funds and various financial instruments. More about AmiBroker and its
features can be found at http://www.amibroker.com/features.html
AmiBroker supports C-Like and Python-Like array-based formula language called AmiBroker Formula
Language in short form AFL which is very powerful and speed/performance optimized and used for
writing simple indicators to complex trading systems. More on how AFL works is given here
http://www.amibroker.com/guide/h_understandafl.html
There are smart AFL programmers cum traders around the globe who want their AFL programs to be converted
into DLL to protect their business/trading logic from clients.
Our Service:
The working AFL code received from the clients will be converted into C DLL which can be used as the AmiBroker
plugin. The conversion process is very fast and the method involves the 99% direct 1-1 mapping of the raw
AFL code into C code. Refer the example below.
The cost of conversion is low with benefits compared to others in this field.
After conversion, the unprotected DLL, single converted C code (just for reference) of the AFL will be
provided to the clients.
The Clients if needed can protect their converted DLL using available license managers and distribute it to
their end-users/clients. We will provide guidance/training on protecting the DLL.
The DLL protection can be either time limited or PC locked or both depending on the client requirements.
Some of the interesting plugins developed using this library.
Magnetic Dynamic Levels Plugin: This plugin is used to display automatic dynamic intraday
magnetic levels on market opening. The plugin internally uses some specialized algorithms based on
tweaked/modified volatility. This plugin can be used for any heavily traded financial instrument, like index,
stocks, futures, options and commodities & forex.
The plugin exports the single API where AFL writers can call this API from their code.
//<no-of-days>, <time frame>, <algorithim_type>, <index>,<style>,<thickness><ehl_flag>
_MAGIC_LEVELS( 2, inDaily, 0, 2, styleDots, 0, 0);
_MAGIC_LEVELS( 5, inDaily, 2, 2, styleDots, 0, 0);
_MAGIC_LEVELS( 3, inHourly, 2, 2, styleDashed, 0, 0);
Here are the three output 5-minute timeframe charts for NIFTY CALL options and BANKNIFTY for
different dates. The horizontal red and green parallel lines are displayed using the above API calls.
Observe how the width of the parallel lines gets adjusted automatically on market opening and stay intact
2. till market closing. The algorithm takes care of the GapUp and GapDown opening cases. The market reacts
sharply at these levels. You can observe how these levels can acts as a magnetic support & resistance
levels.
3. Magic Trend Indicator: This plugin is used to display a indicator which is used for identify trends in
the market. The below graph shows the indicator output in 15 minutes timeframe chart.
mgiOut = MTI(0,0,0);
mgiColor = IIf(mgiOut, colorDarkGreen, colordarkRed);
Plot(mgiOut, "TI", mgiColor, ParamStyle("Style")|styleDots ,Null, Null, 0, 1, 1);
Candle Patterns Plugin: This plugin is used for getting the candle pattern of the selected candle.
The plugin internally uses the table based approach and the performance of this plugin is multiple times
better than the raw afl script. Here is the usage and the corresponding chart of the plugin.
//CPA function returns string which is candle pattern of the selected candle.
cndleptrn = CPA();
Title += "n"+cndleptrn;
//Another Use case:
//CPS function returns the individual flags depending input integer/enum parameter
which represents the single candle pattern. The return value is true or false depending on the
selected candle. These flags are used for making trade decisions.
CP_Init();
cp_0 = CPS(CP_NearDoji);
cp_2 = CPS(CP_LongBlackCandle);
cp_6 = CPS(CP_LongWhiteCandle);
cp_26 = CPS(CP_BullishEngulfing);
cp_45 = CPS(CP_StrongBullishHarami);
cp_48 = CPS(CP_TweezerBOTTOM);
cp_49 = CPS(CP_TweezerTOP);
cp_55 = CPS(CP_InvertedHammer2);
cp_13 = CPS(CP_HangingMan);
cp_14 = CPS(CP_Hammer);
cp_29 = CPS(CP_ThreeInsideUpPattern);
cp_13_14 = cp_13 OR cp_14;
4. ORB (Open Range Breakout Plugin): This plugin is used for plotting time based parallel lines as
shown in the figure below.
//15 Minutes Range lines:
Plot( C, "Price", colorDefault, styleCandle );
MGORB(in15Minute);
Theory:
Provided highly optimized C/C++library ( on the top of AmiBroker ADK ) which acts as a platform to edit/build
Amibroker AFL scripts. One can virtually “cut and paste” the raw AFL script directly into the C . Since AFL
language is typeless, the only challenging task after copying the script into the C /C++, need t o identify the array
type and number type variables and declare them inside C accordingly. Build the C code and create a DLL. Use it
as a amibroker plugin!.
Features:
No Managed code
Say Goodbye to StaticVarSet StaticVarGet (AmiBroker functions) funct ions!!...
Use structures/classes , unions, static/un-named namespace variables inside C/C++ based AFL
code. Amibroker AFL does not support these.
Use multithreaded architecture with C/C++ AFL to design trading systems and money management
rules.
Interface other high performance math libraries with C/C++ based AFL script.
Interface Artificial Intelligence (Neural network) code and other machine learning code very easily.
Interface STL library.
Performance is almost equal and in some cases greater than t hat of AFL scripts.
MOST importantly debug the AFL code inside Visual Studio! .
Bypass AmiBroker FrontEnd and route your data to your own charting software by still using
AmiBroker Builtin highly optimized functions.
I spent 9 months effort to develop this bug free library code. Do not try to re-invent the wheel. Use this library
Example: The below graph is displayed on AmiBroker by calling single AFL entry function
RTDF_AFL2C_DEMO1_PLOTOHLC(O,H,L,C) which is implemented inside the C DLL.
5. The AFL code and its equivalent C/C++ code is given below. Observe the code between _SECTION_BEGIN and _SECTION_END
blocks !! and spot the differences!
Debugging the Plugin:
The below image show how the debugging session of the plugin is done with the visual studio.
Contact:
Contact AFL2DLL@GMAIL.COM , +91-9986180746 for further details.