Amibroker Last updated: 2021-07-03

Presenting a functional python wrapper for algomojo trading api. Algomojo is a multi broker python library for the Algomojo Free API + Free Algo Trading Platform . It allows rapid trading algo development easily, with support for both REST-API interfaces.

Basic Features of Amibroker Trading Module

Algo Chart Based Module
Smart Order Module
Time Based Order Module
Split Order Module

For more details of each API behavior, Please see the Algomojo API documentation.

Bridge Installation

How to Install Algomojo Amibroker Bridge?

Step 1: Download bridge from the Algomojo application -> Tools Section -> Amibroker, Metatrader, C# Bridge

Multibroker Execution Module

Step 2: Run AMBRIDGE-Setup.msi file in the system

Amibroker Module Install


Step 3: Click NEXT -> NEXT while installation

Amibroker Module Install


Step 4: Then press the Close button to finish the installation

Amibroker Module Install


Step 5: Download, Right Click and Run As Administrator the batch file 32-bit or 64-bit based on your Amibroker Version

32 Bit Batch File

64 Bit Batch File

Amibroker Module Install

Library Installation

How to Install Algomojo Amibroker Library?

Step 1: Download zip file from below link

Algomojo

Amibroker Module Install


Step 2: Unzip the file and move Algomojo folder inside the Amibroker->Formulas->Include

Amibroker Module Install


API Configuration

How to configure API in Algomojo AFL?

Step 1: Go to Amibroker->Formulas->Include->Algomojo and Edit API.afl

Amibroker Module Install


Step 2: Edit your API Key, Secret Key and Client ID from Algomojo application in My API section.

Amibroker Module Install


Algo Chart Based Module

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 codes.

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/algomojocharts.afl>
2)Transmit Signals from Amibroker to Algomojo Connected Brokers

//Add the Code after the computation of Buy,Sell,Short,cover Signals
Algomojo(Buy,Sell,Short,cover);
If your strategy contains only Buy, Sell and not the Short, Cover Signals then add the following code

Algomojo(Buy,Sell,0,0);
Sample AFL Code - Chart Based Trading


_SECTION_BEGIN("EMA Crossover Chart Order");

#include <algomojo/Algomojocharts.afl>


//Candle Plot and Axis
SetChartOptions(0,chartShowArrows|chartShowDates);
_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() ); 

//Controls
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
Algomojo(Buy,Sell,Short,Cover);

_SECTION_END();

Smart Order

How to Send Smart Order using Algomojo?

Simplified Smart Order Based Automation Controls can be rendered in Amibroker just by adding two lines of codes.

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


//include the line at the top of your trading strategy code.
#include <algomojo/smartalgomojo.afl>
2)Transmit Signals from Amibroker to Algomojo Connected Brokers

//Add the Code after the computation of Buy,Sell,Short,cover Signals
SmartAlgomojo(Buy,Sell,Short,Cover);
Sample AFL Code - Smart Order Trading


_SECTION_BEGIN("EMA Crossover Smart Order");

#include <algomojo/smartalgomojo.afl>

//Candle Plot and Axis
SetChartOptions(0,chartShowArrows|chartShowDates);
_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() ); 

//Controls
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
SmartAlgomojo(Buy,Sell,Short,Cover);

_SECTION_END();

Time Based

How to send Time Based Orders?

Simplified Time Based Order Automation Controls can be rendered in Amibroker just by adding two lines of codes.

Here are the Two Lines of Code that needs to be added
1)Including Time Based Order library


//include the line at the top of your trading strategy code.
#include <algomojo/TimeBased.afl>
2)Entry and Exit time to Order Execution from Amibroker to Algomojo Connected Brokers

//Transmits Entry and Exit time to Order Execution
TimeBaseExecution(Entrytime,Entrytype);
TimeBaseExecution(Exittime,Exittype); 
Sample AFL Code - Times Based Order Trading


#include <algomojo/TimeBased.afl>  //Main Module


_SECTION_BEGIN("Time Based Algo Execution");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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", colorDefault, styleNoTitle | styleCandle | GetPriceStyle() ); 

Entrytime = ParamTime("Entry Time", "09:20:00", 0);  
Entrytype = ParamList("Entry Type", "BUY|SELL",0);

Exittime = ParamTime("Exit Time", "15:15:00", 0);  
Exittype = ParamList("Exit Type", "BUY|SELL",1);

//Transmits Entry and Exit time to Order Execution
TimeBaseExecution(Entrytime,Entrytype);
TimeBaseExecution(Exittime,Exittype); 

_SECTION_END();

Split Order Module

How to send Split Orders using Algomojo?

Simplified Split Orders Order Automation Controls can be rendered in Amibroker just by adding two lines of codes.

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


//include the line at the top of your trading strategy code.
#include <algomojo/OrderSplit.afl>
2)Transmits Signals to Order Execution from Amibroker to Algomojo Connected Brokers

//Transmits Signals to Order
AlgomojoOrderSpit(Buy,Sell,Short,Cover); 
Sample AFL Code - Split Orders Trading



#include <algomojo/OrderSplit.afl>


_SECTION_BEGIN("EMA Crossover Order Split");


//Candle Plot and Axis
SetChartOptions(0,chartShowArrows|chartShowDates);
_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() ); 

//Controls
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
AlgomojoOrderSpit(Buy,Sell,Short,Cover);

_SECTION_END();

Straddle Module

How to send Time Based Straddle Orders?

Simplified Time Based Straddle Automation Controls can be rendered in Amibroker just by adding two lines of codes.

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


//Index Straddle Automation	
#include <algomojo\straddle.afl>
2)Time based straddle Orders Execution from Amibroker to Algomojo Connected Brokers

//Transmits time based straddle Orders
algostraddle("entry1",entrytime1,exittime1,Stops1); 
Sample AFL Code - Time Based Straddle Automation


// NIFTY/BANKNIFTY MultiLeged Straddle Automation
#include <algomojo\straddle.afl>

Entry1 = ParamToggle("Entry1","Enable|Disable",1);
Stops1 = Param("Stoploss 1",30,0,500,1);  //If zero value is sent then no stops should be placed
entrytime1 = ParamTime( "Start Time 1", "09:30" );
exittime1 = ParamTime( "End Time 1", "11:30" );

Entry2 = ParamToggle("Entry2","Enable|Disable",1);
Stops2 = Param("Stoploss 2",20,0,500,1);  //If zero value is sent then no stops should be placed
entrytime2 = ParamTime( "Start Time 2", "12:30" );
exittime2 = ParamTime( "End Time 2", "2:00" );

Entry3 = ParamToggle("Entry3","Enable|Disable",1);
Stops3 = Param("Stoploss 3",10,0,500,1);  //If zero value is sent then no stops should be placed
entrytime3 = ParamTime( "Start Time 3", "14:30" );
exittime3 = ParamTime( "End Time 3", "15:23" );

if(Entry1)
{
algostraddle("entry1",entrytime1,exittime1,Stops1);
}
if(Entry2)
{
algostraddle("entry2",entrytime2,exittime2,Stops2);
}
if(Entry3)
{
algostraddle("entry3",entrytime3,exittime3,Stops3);
}

SetChartOptions(0, chartShowArrows | chartShowDates); //x-Axis will be plottted
//plot the candles
Plot(Close,"Close",colorDefault,styleCandle | styleNoTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Auto Rollover Module

How to send Auto Rollover Orders?

Simplified Auto Rollover Automation Controls can be rendered in Amibroker just by adding two lines of codes.

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


//Index Straddle Automation	
#include <algomojo/API.afl>
#include <algomojo/AlgoControls.afl>
#include <algomojo/OrderControls.afl>
#include <algomojo/AlgoDashboard.afl>
#include <algomojo/Algostatus.afl>
2)Time based auto rollover orders execution from Amibroker to Algomojo Connected Brokers

//Transmits time based auto rollover Orders
Rollover(currsym,rolloversym,RolloverDate,RolloverTime);
Sample AFL Code - Time based auto rollover


#include <algomojo/API.afl>
#include <algomojo/AlgoControls.afl>
#include <algomojo/OrderControls.afl>
#include <algomojo/AlgoDashboard.afl>
#include <algomojo/Algostatus.afl>

_SECTION_BEGIN("Auto Rollover");

currsym = ParamStr("Current Symbol","NIFTY29JUL21FUT");
rolloversym = ParamStr("Rollover Symbol","NIFTY26AUG21FUT");

RolloverDate = ParamDate("Rollover Date","2021-07-06 14:30:09");
RolloverTime = ParamTime( "Rollover Time", "14:30:09" );


Rollover(currsym,rolloversym,RolloverDate,RolloverTime);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_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() ); 
_SECTION_END();

Realtime Options Implied Volatility Charts

Sample AFL Code - Realtime Options Implied Volatility


#include <algomojo/OptionGreeks.afl>


_SECTION_BEGIN("Implied Volatility");
Plot( OptionGreeks("IV"), _DEFAULT_NAME(), ParamColor("Color", colorGreen ), ParamStyle( "Style", styleLine | styleOwnScale | styleThick  ) );
_SECTION_END();

Realtime Options Greeks-Delta Charts

Sample AFL Code - Realtime Options Greeks-Delta


#include <algomojo/OptionGreeks.afl>

_SECTION_BEGIN("Option Greeks - Delta");
Plot( OptionGreeks("delta"), _DEFAULT_NAME(), ParamColor("Color", colorAqua ), ParamStyle( "Style", styleLine | styleOwnScale | styleThick  ) );
_SECTION_END();

Realtime Options Greeks-Gamma Charts

Sample AFL Code - Realtime Options Greeks-Gamma


#include <algomojo/OptionGreeks.afl>

_SECTION_BEGIN("Option Greeks - Gamma");
Plot( OptionGreeks("gamma"), _DEFAULT_NAME(), ParamColor("Color", colorGold ), ParamStyle( "Style", styleLine | styleOwnScale | styleThick  ) );
_SECTION_END();

Realtime Options Greeks-Theta Charts

Sample AFL Code - Realtime Options Greeks-Theta


#include <algomojo/OptionGreeks.afl>

_SECTION_BEGIN("Option Greeks - Theta");
Plot( OptionGreeks("theta"), _DEFAULT_NAME(), ParamColor("Color", colorOrange ), ParamStyle( "Style", styleLine | styleOwnScale | styleThick  ) );
_SECTION_END();

Realtime Options Greeks-Vega Charts

Sample AFL Code - Realtime Options Greeks-Vega


#include <algomojo/OptionGreeks.afl>

_SECTION_BEGIN("Option Greeks - Vega");
Plot( OptionGreeks("vega"), _DEFAULT_NAME(), ParamColor("Color", colorBlue ), ParamStyle( "Style", styleLine | styleOwnScale | styleThick  ) );
_SECTION_END();