Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Angel Broking Multi-Client Amibroker Trading Module

6 min read

Got frequent requirements from Angel Broking Customers to automate Amibroker based trading system where one single generation from charts could punch orders in multiple accounts (friends & family). Here is the readymade execution module one can plugin with their trading system to send multi orders and easily configure multi-client under the same broker.

Angel Broking Multi-Client Amibroker Trading Module

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?

Current module supports Angel Broking only

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 control to configure a number of trading accounts. 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 Account Controls - Algomojo");

TotalAccounts = Param("Total Accounts",4,1,25,1);
TradingSymbol = ParamStr("TradingSymbol","RELIANCE-EQ");
Token = ParamStr("Token","2885"); //token is a mandatory parameter can be obtained from Symbol Details from Algomojo Watchlist 
Broker = Paramlist("Broker","an",0);  //Broker Short Code ab - aliceblue, tj - tradejini, zb - zebu, mt-mastertrust, en- enrich


//Client 1 Details
ClientId1 = ParamStr("ClientId1","K190553");
ApiKey1 =  ParamStr("ApiKey1","b48e4db30e47326722a388c03eb4ee26");
ApiSecret1 =  ParamStr("ApiSecret1","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity1 = ParamStr("Quantity1","5");


//Client 2 Details
ClientId2 = ParamStr("ClientId2","K190553");
ApiKey2 =  ParamStr("ApiKey2","b48e4db30e47326722a388c03eb4ee26");
ApiSecret2 =  ParamStr("ApiSecret2","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity2 = ParamStr("Quantity2","10");


//Client 3 Details
ClientId3 = ParamStr("ClientId3","K190553");
ApiKey3 =  ParamStr("ApiKey3","b48e4db30e47326722a388c03eb4ee26");
ApiSecret3 =  ParamStr("ApiSecret3","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity3 = ParamStr("Quantity3","15");


//Client 4 Details
ClientId4 = ParamStr("ClientId4","K190553");
ApiKey4 =  ParamStr("ApiKey4","b48e4db30e47326722a388c03eb4ee26");
ApiSecret4 =  ParamStr("ApiSecret4","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity4 = ParamStr("Quantity4","25");



_SECTION_END();

Chart Based Multi Client Trading Module

This module is a ready made module which can be connected along with Amibroker based trading system already configured for Buy,Sell, Short , Cover Conditions.


//Single Broker - Multi Client Algomojo Trading AFL
//Coded by Rajandran R - Co-Founder - Algomojo / Founder - Marketcalls
//Version 1.0
//Date : 02nd May 2021
//Website : www.algomojo.com / www.marketcalls.in

_SECTION_BEGIN("Multi Client Account Controls - Algomojo");

TotalAccounts = Param("Total Accounts",4,1,25,1);
TradingSymbol = ParamStr("TradingSymbol","RELIANCE-EQ");
Token = ParamStr("Token","2885"); //token is a mandatory parameter can be obtained from Symbol Details from Algomojo Watchlist 
Broker = Paramlist("Broker","an",0);  //Broker Short Code ab - aliceblue, tj - tradejini, zb - zebu, mt-mastertrust, en- enrich


//Client 1 Details
ClientId1 = ParamStr("ClientId1","K190553");
ApiKey1 =  ParamStr("ApiKey1","b48e4db30e47326722a388c03eb4ee26");
ApiSecret1 =  ParamStr("ApiSecret1","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity1 = ParamStr("Quantity1","5");


//Client 2 Details
ClientId2 = ParamStr("ClientId2","K190553");
ApiKey2 =  ParamStr("ApiKey2","b48e4db30e47326722a388c03eb4ee26");
ApiSecret2 =  ParamStr("ApiSecret2","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity2 = ParamStr("Quantity2","10");


//Client 3 Details
ClientId3 = ParamStr("ClientId3","K190553");
ApiKey3 =  ParamStr("ApiKey3","b48e4db30e47326722a388c03eb4ee26");
ApiSecret3 =  ParamStr("ApiSecret3","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity3 = ParamStr("Quantity3","15");


//Client 4 Details
ClientId4 = ParamStr("ClientId4","K190553");
ApiKey4 =  ParamStr("ApiKey4","b48e4db30e47326722a388c03eb4ee26");
ApiSecret4 =  ParamStr("ApiSecret4","fc3ed44d0914b0e6466f9ff2e3ae003a");
Quantity4 = ParamStr("Quantity4","25");



_SECTION_END();

_SECTION_BEGIN("Single Broker Multi Client Charting Module");


//Common Mapping
Exchange = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX",1);  //Common Mapping
ordertype = ParamList("Order Type","MARKET|LIMIT|STOPLOSS_LIMIT|STOPLOSS_MARKET",0);
producttype = ParamList("Product Type","DELIVERY|CARRYFORWARD|MARGIN|INTRADAY|AMO_MARGIN|AMO_DELIVERY|AMO_CARRYFORWARD",0);
variety = ParamList("variety","NORMAL|STOPLOSS|AMO",0); 
price = Param("Price",0,0,100000);
triggerprice = Param("triggerprice",0,0,100000);
squareoff = ParamStr("SqrOffvalue","0"); 
stoploss = ParamStr("SLvalue","0");
trailingStopLoss = ParamStr("trailingSL","0"); 
disclosedquantity = 0;
duration = ParamStr("Duration","DAY");

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
stgy_name = ParamStr("Strategy Name","Multi Broker Execution"); // Strategy Name
EnableAlgo = ParamList("Algo Mode","Disable|Enable|LongOnly|ShortOnly",0); // Algo Mode



//Initialization
resp = "";


//Configure Trade Execution Delay


AlgoBuy = lastvalue(Ref(Buy,-tradedelay));
AlgoSell = lastvalue(Ref(Sell,-tradedelay));
AlgoShort = lastvalue(Ref(Short,-tradedelay));
AlgoCover = lastvalue(Ref(Cover,-tradedelay));






//Static Varibales for Order Protection

static_name_ = Name()+GetChartID()+interval(2)+stgy_name;
static_name_algo = Name()+GetChartID()+interval(2)+stgy_name+"algostatus";
//StaticVarSet(static_name_algo, -1); 


//Algo Dashboard

GfxSelectFont( "BOOK ANTIQUA", 14, 100 );
GfxSetBkMode( 1 );
if(EnableAlgo == "Enable")
{
AlgoStatus = "Algo Enabled";
GfxSetTextColor( colorGreen ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=1)
{
_TRACE("Algo Status : Enabled");
StaticVarSet(static_name_algo, 1);
}
}
if(EnableAlgo == "Disable")
{
AlgoStatus = "Algo Disabled";
GfxSetTextColor( colorRed ); 
GfxTextOut( "Algostatus : "+AlgoStatus , 20, 40); 
if(Nz(StaticVarGet(static_name_algo),0)!=0)
{
_TRACE("Algo Status : Disabled");
StaticVarSet(static_name_algo, 0);
}
}
if(EnableAlgo == "LongOnly")
{
AlgoStatus = "Long Only";
GfxSetTextColor( colorYellow ); 
GfxTextOut( "Algostatus : "+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 : "+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,multiplier){


	head = "{\"orders\" : [";
	tail = "  ]}";
	body = "";
	
	
	for(i=1;i<=Accounts;i++)
	{
	qty = int(StrToNum(VarGetText("Quantity"+i))*multiplier);
	msg = "{   \"order_refno\":\""+i+"\",   \"user_apikey\":\""+VarGetText("ApiKey"+i)+"\", \"api_secret\":\""+VarGetText("ApiSecret"+i)+"\", \"stgy_name\": \""+stgy_name+"\", \"variety\":\""+variety+"\", \"tradingsymbol\":\""+TradingSymbol+"\", \"symboltoken\":\""+Token+"\", \"transactiontype\":\""+Action+"\", \"exchange\":\""+Exchange+"\", \"ordertype\":\""+ordertype+"\", \"producttype\":\""+producttype+"\", \"duration\":\""+duration+"\", \"price\":\""+price+"\", \"squareoff\":\""+squareoff+"\", \"stoploss\":\""+stoploss+"\", \"quantity\":\""+VarGetText("Quantity"+i)+"\", \"triggerprice\":\""+triggerprice+"\", \"trailingStopLoss\":\""+trailingStopLoss+"\", \"disclosedquantity\":\""+disclosedquantity+"\" }";
                
		if(i==1)
		{
		body = msg; 
		}    
		else
		{
		body = body + "," + msg;
		}   
		}
    api_data = head + body + tail;
	return api_data;
	
}

//Buy and Sell Order Functions

function Buyorder(multiplier)
{
	
    algomojo=CreateObject("AMAMIBRIDGE.Main");
	api = apidata(TotalAccounts,"BUY",multiplier);     
    _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);
}



function sellorder(multiplier)
{
    algomojo=CreateObject("AMAMIBRIDGE.Main");
	api = apidata(TotalAccounts,"SELL",multiplier);  
    _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);
}


//Execution Module

if(EnableAlgo != "Disable")
    {
        lasttime = StrFormat("%0.f",LastValue(BarIndex()));
        
        SetChartBkColor(colorDarkGrey);
        if(EnableAlgo == "Enable")
        {   
            if (AlgoBuy==True AND AlgoCover == True AND StaticVarGet(static_name_+"buyCoverAlgo")==0 AND StaticVarGetText(static_name_+"buyCoverAlgo_barvalue") != lasttime )
            {
            // reverse Long Entry 
                buyorder(2);
                StaticVarSetText(static_name_+"buyCoverAlgo_barvalue",lasttime);  
                StaticVarSet(static_name_+"buyCoverAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Buy AND Cover");
        
            }
            else if ((AlgoBuy != True OR AlgoCover != True))
            {   
                StaticVarSet(static_name_+"buyCoverAlgo",0);
            }
            
            if (AlgoBuy==True AND AlgoCover != True AND StaticVarGet(static_name_+"buyAlgo")==0 AND StaticVarGetText(static_name_+"buyAlgo_barvalue") != lasttime)
            {
            // Long Entry 
                buyorder(1);
                StaticVarSetText(static_name_+"buyAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"buyAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Buy");
            }
            else if (AlgoBuy != True)
            {   
                StaticVarSet(static_name_+"buyAlgo",0);
                
            }
            if (AlgoSell==true AND AlgoShort != True AND StaticVarGet(static_name_+"sellAlgo")==0 AND StaticVarGetText(static_name_+"sellAlgo_barvalue") != lasttime)
            {     
            // Long Exit 
                sellorder(1);
                StaticVarSetText(static_name_+"sellAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"sellAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Sell");
            }
            else if (AlgoSell != True )
            {   
                StaticVarSet(static_name_+"sellAlgo",0);
            }
            if (AlgoShort==True AND AlgoSell==True AND  StaticVarGet(static_name_+"ShortSellAlgo")==0 AND StaticVarGetText(static_name_+"ShortSellAlgo_barvalue") != lasttime)
            {
            // reverse Short Entry 
                sellorder(2);
                StaticVarSetText(static_name_+"ShortsellAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"ShortSellAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Short and Sell");
            }
            else if ((AlgoShort != True OR AlgoSell != True))
            {   
                StaticVarSet(static_name_+"ShortSellAlgo",0);
            }
                
            if (AlgoShort==True  AND  AlgoSell != True AND StaticVarGet(static_name_+"ShortAlgo")==0 AND  StaticVarGetText(static_name_+"ShortAlgo_barvalue") != lasttime)
            {
            // Short Entry
                sellorder(1);
                StaticVarSetText(static_name_+"ShortAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"ShortAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Short");
            }
            else if (AlgoShort != True )
            {   
                StaticVarSet(static_name_+"ShortAlgo",0);
            }
            if (AlgoCover==true AND AlgoBuy != True AND StaticVarGet(static_name_+"CoverAlgo")==0 AND StaticVarGetText(static_name_+"CoverAlgo_barvalue") != lasttime)
            {
            // Short Exit
                buyorder(1);
                StaticVarSetText(static_name_+"CoverAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"CoverAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Cover");
            }
            else if (AlgoCover != True )
            {   
                StaticVarSet(static_name_+"CoverAlgo",0);
            }
        }
        
        
        
        else if(EnableAlgo == "LongOnly")
        {
            
            if (AlgoBuy==True AND StaticVarGet(static_name_+"buyAlgo")==0 AND StaticVarGetText(static_name_+"buyAlgo_barvalue") != lasttime)
            {  
            //  Long Entry
                buyorder(1);
                StaticVarSetText(static_name_+"buyAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"buyAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Buy");
            }
            else if (AlgoBuy != True)
            {   
                StaticVarSet(static_name_+"buyAlgo",0);
            }
            if (AlgoSell==true AND StaticVarGet(static_name_+"sellAlgo")==0 AND StaticVarGetText(static_name_+"sellAlgo_barvalue") != lasttime)
            {  
            // Long Exit
                sellorder(1);
                StaticVarSetText(static_name_+"sellAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"sellAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Sell");
            }
            else if (AlgoSell != True )
            {   
                StaticVarSet(static_name_+"sellAlgo",0);
            }
        }
        else if(EnableAlgo == "ShortOnly")
        {
            if (AlgoShort==True AND StaticVarGet(static_name_+"ShortAlgo")==0 AND StaticVarGetText(static_name_+"ShortAlgo_barvalue") != lasttime)
            {
            // Short Entry
                sellorder(1);
                StaticVarSetText(static_name_+"ShortAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"ShortAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Short");
            }
            else if (AlgoShort != True )
            {   
                StaticVarSet(static_name_+"ShortAlgo",0);
            }
            if (AlgoCover==true AND StaticVarGet(static_name_+"CoverAlgo")==0 AND StaticVarGetText(static_name_+"CoverAlgo_barvalue") != lasttime)
            {
            // Short Exit
                buyorder(1);
                StaticVarSetText(static_name_+"CoverAlgo_barvalue",lasttime); 
                StaticVarSet(static_name_+"CoverAlgo",1); //Algo Order was triggered, no more order on this bar
                _TRACE("Strategy : "+ stgy_name +"AlgoStatus : "+ EnableAlgo +"Chart Symbol : "+ Name()+ "Signal = Cover");
            }
            else if (AlgoCover != True)
            {   
                StaticVarSet(static_name_+"CoverAlgo",0);
            }
        }
        
    }//end main if

    
_SECTION_END();

Feel Free to use the modify the code according to your requirements. Use this module responsibly!
Test your system properly with the module before using the module in live automation trading environment.

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

How to Install Amibroker and Ninjatrader on MacBook Air

This is a routine question we get from Mac users and in this tutorial, we will be learning how to install Windows 11 inside...
Rajandran R
49 sec read

Automated Trading Landscape of Indian Markets

Automated trading or rule-based trading is something not new for Indian retail users. And all thanks to those modern technology-driven brokers who brought API-based...
Rajandran R
5 min read

What is Algomojo – Smart Order Execution Module for…

Smart Order Module brings a 100% end-to-end automated trading solution for Amibroker users to automate their trading ideas with a simple plug-and-play module. Traders...
Rajandran R
26 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More