How to Automate your Strategy just by Adding Two lines of Code in Amibroker?

Since the start of Algomojo, we are focusing on one thing “how to simplify the automated execution controls” – so that traders can easily convert their Buy or Sell trading strategy to automate their trading solutions faster. So started implementing simplified & open-source Amibroker libraries so that traders could connect their trading strategies by adding few lines of code and drastically reducing their coding time in implementing trading alerts, automation, trade connectivity dashboard & controls.

To start with Amibroker we started implementing four main execution modules. Download the Amibroker Open Source Libraries

1)Algomojo Chart Based Execution Module
2)Algomojo Smart Order Execution Module
3) Time-Based Order Execution
4)Split Order Execution to execute large orders


1)Algomojo Account
2)Amibroker (6.0 or higher recommended)

1)Download the Library and Install as per the guidelines (Same AFL codes are provided in the link)

Download the Algomojo Amibroker Library

2)API Configuration Settings in Amibroker

 Go to Amibroker->Formulas->Include->Algomojo folder and Edit using AFL Editor. Enter the APIkey and API secret obtained from Algomojo->My API section

Here is a sample code to do smart order execution

How to Send Orders using Amibroker from the Charts?

Simplified Chart Based Automation Controls can be rendered in Amibroker just by adding two lines of code.

Here are the Two Lines of Code that needs to be added
1)Including Algomojo Charts library

//include the line at the top of your trading strategy code.
#include <algomojo/>

2)Transmit Signals from Amibroker to Algomojo Connected Brokers

//Add the Code after the computation of Buy,Sell,Short,cover Signals

If your strategy contains only Buy, Sell, and not the Short, Cover Signals then add the following code


Algomojo Controls

Once the appropriate codes are added necessary strategy control parameters, dashboard controls and alert controls are automatically added and code is ready to perform automation once the AlgoMode Parameter is enabled

Sample AFL Code – Chart Based Trading

#include <algomojo/>

//Candle Plot and Axis
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

len1 = Param("Length1",20,1,100,1);
len2 = Param("Length2",50,1,100,1);

//Plot Functions
Plot(EMA(Close,len1),"EMA1",colorGreen, styleLine | styleThick);
Plot(EMA(Close,len2),"EMA2",coloryellow, styleLine | styleThick);

//Trading Rules
Buy = Cross(EMA(Close,len1), EMA(Close,len2)); //Positive EMA Crossover
Sell = Cross(EMA(Close,len2), EMA(Close,len1)); //Negative EMA Crossover

//Stop and Reverse

Short = Sell;
Cover = Buy;

//Non Repainting  - Signals happens only after the close of the current
Buy = Ref(Buy,-1);
Sell = Ref(Sell,-1);
Short = Ref(Short,-1);
Cover = Ref(Cover,-1);

/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

//Transmits Signals to Order

Start Enjoying the Controls, Reduce your code time, and start focusing on building your trading strategy.

What are the next simplified versions to be released?

We are currently working on execution modules like
1)Automated Trailing Stoploss / Trade Modification Modules
2)Fixed/Perc Stoploss and Target Modules
3)Futures to Options Execution Modules
4)Multi Legged Option Execution Modules
5)Bracket and Cover Order Stop and Reverse Intraday Modules
6)Limit Order with Time-based AutoCancellation Execution Modules
7)Limit Order Strategies with Autocancellation of orders
8)Limit Order Strategies with Combined Stops/Targets
9)Multi-Client Trade Execution
10)Multi-Broker Trade Execution

and more to come. Stay tuned!

2 thoughts on “How to Automate your Strategy just by Adding Two lines of Code in Amibroker?”

Leave a Comment

Your email address will not be published. Required fields are marked *