Got frequent requirements from many traders to automate Amibroker based trading system where one single button click from charts could punch orders in multiple accounts (friends & family). Here is the readymade execution module one can plugin send multi orders and easily configure multi-client under the same broker.
This tutorial demonstrates how to send orders from Amibroker to Algomojo using Simple GUI buttons using modern amibroker tools to Multiple Clients belongs to the same broker.

Supported Amibroker Version
Amibroker 6.22 or Higher
Who can make use of this module?
Any traders who have access to Amibroker and access to Algomojo Trading Platform can trigger their buy & sell signal generation from their trading system to multiple accounts (friends & family). i.e one Amibroker to fire orders in multiple accounts.
Which brokers are supported?
Currently, module supports Aliceblue, Tradejini, Zebu and Mastertrust
How many accounts one can connect?
Currently, there is no restriction on the number of clients one can connect.
Multi-Client Account Controls – AFL Coding Block
Multi-client account control block contains the configuration of multiple clients, trading symbols, and trade multiplier. If more clients need to be added then here is the sample format. Client details need to be configured in order to send multiple client accounts.
_SECTION_BEGIN("Multi Client Button Trading Controls - Algomojo");
TotalAccounts = Param("Total Accounts",4,1,25,1);
TradingSymbol = ParamStr("TradingSymbol","SBIN-EQ");
Broker = Paramlist("Broker","tj|ab|zb|mt|en",0); //Broker Short Code ab - aliceblue, tj - tradejini, zb - zebu, mt-mastertrust, en- enrich
TradeSize = Param("TradeSize",25,1,10000,1);
//Client 1 Details
ClientId1 = ParamStr("ClientId1","TS2499");
ApiKey1 = ParamStr("ApiKey1","86cbef19e7e61ccee91e497690d5814e");
ApiSecret1 = ParamStr("ApiSecret1","f2800307bdff70f8f856f6728ea7a58b");
Quantity1 = Param("Multiplier1",1,1,100,1)*TradeSize;
//Client 2 Details
ClientId2 = ParamStr("ClientId2","TS2499");
ApiKey2= ParamStr("ApiKey2","86cbef19e7e61ccee91e497690d5814e");
ApiSecret2 = ParamStr("ApiSecret2","f2800307bdff70f8f856f6728ea7a58b");
Quantity2 = Param("Multiplier2",1,1,100,1)*TradeSize;
//Client 3 Details
ClientId3 = ParamStr("ClientId3","TS2499");
ApiKey3 = ParamStr("ApiKey3","86cbef19e7e61ccee91e497690d5814e");
ApiSecret3 = ParamStr("ApiSecret3","f2800307bdff70f8f856f6728ea7a58b");
Quantity3 = Param("Multiplier3",1,1,100,1)*TradeSize;
//Client 4 Details
ClientId4 = ParamStr("ClientId4","TS2499");
ApiKey4 = ParamStr("ApiKey4","86cbef19e7e61ccee91e497690d5814e");
ApiSecret4 = ParamStr("ApiSecret4","f2800307bdff70f8f856f6728ea7a58b");
Quantity4 = Param("Multiplier4",1,1,100,1)*TradeSize;
_SECTION_END();
Multi Client Button Trading Module – Amibroker AFL
Here is the complete code where the user has to configure the Total Accounts , Client ID, APIKey, API Secret, Trading Size, and Multiplier accordingly.
//Single Broker - Multi Client Algomojo Button Trading AFL
//Coded by Rajandran R - Co-Founder - Algomojo / Founder - Marketcalls
//Version 1.0
//Date : 15th Aug 2021
//Website : www.algomojo.com / www.marketcalls.in
_SECTION_BEGIN("Multi Client Button Trading Controls - Algomojo");
TotalAccounts = Param("Total Accounts",4,1,25,1);
TradingSymbol = ParamStr("TradingSymbol","SBIN-EQ");
Broker = Paramlist("Broker","tj|ab|zb|mt|en",0); //Broker Short Code ab - aliceblue, tj - tradejini, zb - zebu, mt-mastertrust, en- enrich
TradeSize = Param("TradeSize",25,1,10000,1);
//Client 1 Details
ClientId1 = ParamStr("ClientId1","TS2499");
ApiKey1 = ParamStr("ApiKey1","86cbef19e7e61ccee91e497690d5814e");
ApiSecret1 = ParamStr("ApiSecret1","f2800307bdff70f8f856f6728ea7a58b");
Quantity1 = Param("Multiplier1",1,1,100,1)*TradeSize;
//Client 2 Details
ClientId2 = ParamStr("ClientId2","TS2499");
ApiKey2= ParamStr("ApiKey2","86cbef19e7e61ccee91e497690d5814e");
ApiSecret2 = ParamStr("ApiSecret2","f2800307bdff70f8f856f6728ea7a58b");
Quantity2 = Param("Multiplier2",1,1,100,1)*TradeSize;
//Client 3 Details
ClientId3 = ParamStr("ClientId3","TS2499");
ApiKey3 = ParamStr("ApiKey3","86cbef19e7e61ccee91e497690d5814e");
ApiSecret3 = ParamStr("ApiSecret3","f2800307bdff70f8f856f6728ea7a58b");
Quantity3 = Param("Multiplier3",1,1,100,1)*TradeSize;
//Client 4 Details
ClientId4 = ParamStr("ClientId4","TS2499");
ApiKey4 = ParamStr("ApiKey4","86cbef19e7e61ccee91e497690d5814e");
ApiSecret4 = ParamStr("ApiSecret4","f2800307bdff70f8f856f6728ea7a58b");
Quantity4 = Param("Multiplier4",1,1,100,1)*TradeSize;
_SECTION_END();
_SECTION_BEGIN("Single Broker Multi Client Button Trading Module");
//Common Mapping
Exchange = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX",1); //Common Mapping
Retention = ParamStr("Retention","DAY");
Product = ParamList("Product Type","MKT|LMT",0); // Pricetype
OrderType = ParamList("Product code","CNC|NRML|MIS",2); // CNC - Cash and Carry, NRML - Normal, MIS - Margin Intraday Squareoff
AMO = "NO";
ver = ParamStr("API Version","1.0");
tradedelay = Param("Execution Delay",0,0,1); // 0 - Execution with No Delay after a signal, 1- Execution at the end of the candle
strg_name = ParamStr("Strategy Name","Multi Broker Execution"); // Strategy Name
EnableAlgo = ParamList("Button Trading","Enabled",0); // Button Trading Enabled By Default
//Static Variables for Order Protection
static_name_ = Name()+GetChartID()+interval(2)+strg_name;
static_name_algo = Name()+GetChartID()+interval(2)+strg_name+"algostatus";
//StaticVarSet(static_name_algo, -1);
//Algo Dashboard
GfxSelectFont( "BOOK ANTIQUA", 14, 100 );
GfxSetBkMode( 1 );
if(EnableAlgo == "Enabled")
{
AlgoStatus = "Button Trading : Enabled";
GfxSetTextColor( colorGreen );
GfxTextOut( AlgoStatus , 20, 40);
if(Nz(StaticVarGet(static_name_algo),0)!=1)
{
_TRACE("Button Trading : Enabled");
StaticVarSet(static_name_algo, 1);
}
}
if(EnableAlgo == "Disable")
{
AlgoStatus = "Button Trading : Disabled";
GfxSetTextColor( colorRed );
GfxTextOut( AlgoStatus , 20, 40);
if(Nz(StaticVarGet(static_name_algo),0)!=0)
{
_TRACE("Button Trading : Disabled");
StaticVarSet(static_name_algo, 0);
}
}
if(EnableAlgo == "LongOnly")
{
AlgoStatus = "Long Only";
GfxSetTextColor( colorYellow );
GfxTextOut( AlgoStatus , 20, 40);
if(Nz(StaticVarGet(static_name_algo),0)!=2)
{
_TRACE("Algo Status : Long Only");
StaticVarSet(static_name_algo, 2);
}
}
if(EnableAlgo == "ShortOnly")
{
AlgoStatus = "Short Only";
GfxSetTextColor( colorYellow );
GfxTextOut( AlgoStatus , 20, 40);
if(Nz(StaticVarGet(static_name_algo),0)!=3)
{
_TRACE("Algo Status : Short Only");
StaticVarSet(static_name_algo, 3);
}
}
function apidata(Accounts,Action){
head = "{\"orders\" : [";
tail = " ]}";
body = "";
for(i=1;i<=Accounts;i++)
{
qty = VarGet("Quantity"+i);
msg = "{ \"order_refno\":\""+i+"\", \"user_apikey\":\""+VarGetText("ApiKey"+i)+"\", \"api_secret\":\""+VarGetText("ApiSecret"+i)+"\", \"strg_name\": \"MultiOrder Amibroker\", \"s_prdt_ali\":\"BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML\", \"Tsym\":\""+TradingSymbol+"\", \"exch\":\""+Exchange+"\", \"Ttranstype\":\""+Action+"\", \"Ret\":\"DAY\", \"prctyp\":\"MKT\", \"qty\":\""+qty+"\", \"discqty\":\"0\", \"MktPro\":\"NA\", \"Price\":\"0\", \"TrigPrice\":\"0\", \"Pcode\":\""+OrderType+"\", \"AMO\":\"NO\" }";
if(i==1)
{
body = msg;
}
else
{
body = body + "," + msg;
}
}
api_data = head + body + tail;
return api_data;
}
//Buy and Sell Order Functions
function PlaceMultiOrder(Action)
{
algomojo=CreateObject("AMAMIBRIDGE.Main");
api = apidata(TotalAccounts,Action);
_TRACE("Broker API Data "+api);
GetPerformanceCounter(True);
resp=algomojo.AMDispatcher(ApiKey1, ApiSecret1,"PlaceMultiOrder",api,Broker,ver);
elapsed = GetPerformanceCounter()/1000;
_TRACE("Execution Time : "+elapsed);
_TRACE("Broker API Response "+resp);
_TRACE("Execution Period : "+elapsed);
}
static_name_ = Name()+GetChartID()+interval(2)+strg_name;
function CreateGui(ButtonName, x, y, width, Height )
{
//_TRACEF( "IDset before: %g", IDset );
global IDset;
if( typeof( IDset ) == "undefined" ) IDset = 0;
GuiButton( ButtonName, ++IDset, x, y, width, height, 7 );
}
function GuiButtonTrigger( ) {
/// @link http://forum.amibroker.com/t/guibuttons-for-everyone/1716/4
/// by beaver & fxshrat
/// version 1.1
global IDset;
local id, event, clickeven;
if( typeof( IDset ) == "undefined" ) IDset = 0;
//_TRACEF( "IDset after: %g", IDset );
result = 0;
id = GuiGetEvent( 0, 0 );// receiving button id
event = GuiGetEvent( 0, 1 );// receiving notifyflag
clickevent = event == 1;
BuyClicked = id == 1 && clickevent;
SellClicked = id == 2 && clickevent;
ShortClicked = id == 3 && clickevent;
CoverClicked = id == 4 && clickevent;
if( BuyClicked AND StaticVarGet(static_name_+"buyClicked")==0 )
{
Say("Buy Button Clicked");
PlaceMultiOrder("B");
StaticVarSet(static_name_+"buyClicked",1);
}
else
{
StaticVarSet(static_name_+"buyClicked",0);
}
if( SellClicked AND StaticVarGet(static_name_+"sellClicked")==0 )
{
Say("Sell Button Clicked");
PlaceMultiOrder("S");
StaticVarSet(static_name_+"sellClicked",1);
}
else
{
StaticVarSet(static_name_+"sellClicked",0);
}
if( ShortClicked AND StaticVarGet(static_name_+"shortClicked")==0 )
{
Say("Short Button Clicked");
PlaceMultiOrder("S");
StaticVarSet(static_name_+"shortClicked",1);
}
else
{
StaticVarSet(static_name_+"shortClicked",0);
}
if( coverClicked AND StaticVarGet(static_name_+"coverClicked")==0 )
{
Say("Cover Button Clicked");
PlaceMultiOrder("B");
StaticVarSet(static_name_+"coverClicked",1);
}
else
{
StaticVarSet(static_name_+"coverClicked",0);
}
return result;
}
_SECTION_END();
_SECTION_BEGIN("Button Plot and Mouse Click Detection Module");
CreateGui("Long Entry", 0, 100, 200, 30 );
CreateGui("Long Exit", 0, 100+50, 200, 30);
CreateGui("Short Entry", 200, 100, 200, 30 );
CreateGui("Short Exit", 200, 100+50, 200, 30 );
GuiSetColors( 1,1, 2, colorgreen, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow );
GuiSetColors( 2,2, 2, colororange, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow );
GuiSetColors( 3,3, 2, colorred, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow );
GuiSetColors( 4,4, 2, colorBlue, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow );
GuiButtonTrigger();
_SECTION_END();
_SECTION_BEGIN("Price");
//Persistant Static Variables
//Save the Static Variables every 15 second once
SetOption("StaticVarAutoSave",15);
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();
The post Multi-Client Button Trading Amibroker AFL appeared first on Marketcalls.