{"id":62,"date":"2020-11-18T03:50:27","date_gmt":"2020-11-18T03:50:27","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=62"},"modified":"2023-09-13T04:42:07","modified_gmt":"2023-09-13T04:42:07","slug":"placeorder-multi-broker-code-snippets-for-amibroker","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/placeorder-multi-broker-code-snippets-for-amibroker\/","title":{"rendered":"PlaceOrder \u2013 Multi-Broker Execution Code Snippets for Amibroker"},"content":{"rendered":"\n<p>This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders simultaneously to 4 brokers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1280\" height=\"720\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/11\/placeorder-multi-broker.png\" alt=\"\" class=\"wp-image-63\"\/><\/figure>\n\n\n\n<p>This tutorial explores the requirements for building a multi-broker execution module using Amibroker. Algomojo Multi-Broker Bridge is required to send orders to multiple brokers simultaneously.<\/p>\n\n\n\n<div class=\"wp-block-buttons\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/algomojo.com\/blog\/installation-guidelines-for-multi-platform-multi-broker-execution-modules\/\">Installation Guidelines for Algomojo Multi Broker Bridge<\/a><\/div>\n<\/div>\n\n\n\n<p>Here are the Building Blocks of Multi Broker Execution Module<\/p>\n\n\n\n<p id=\"block-97f6e9e0-8d1e-425a-8359-1849fb9d5856\"><strong>1)RequestTimedRefresh<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">RequestTimedRefresh(1, False); \/\/ Send orders even if Amibroker is minimized or Chart is not active<\/code><\/pre>\n\n\n\n<p id=\"block-4bc3e426-7219-4e13-b5f5-5e9bdae43ccd\"><strong>2)Get API Key and API Secret Key of Multiple Brokers with Short Code<\/strong><\/p>\n\n\n\n<p id=\"block-c4a0beb7-0bee-4675-9dfe-632b15ff3bfa\">. use the ParamStr function to receive the inputs of User API Key, User API secret key, Broker Short code. Broker Short code is used to identify which broker you are sending the order.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><strong>ab<\/strong> &#8211; Aliceblue , <strong>tj <\/strong>&#8211; Tradejini , <strong>zb <\/strong>&#8211; Zebu, <strong>en <\/strong>&#8211; enrich<\/p><\/blockquote>\n\n\n\n<p id=\"block-3a4a3fb0-2ce4-498e-b507-bd5ba29ae6d3\">Pass the Version of the API used. Currently, version 1.0 is used as the default version. In the future if Algomojo is getting upgraded to a higher version then this parameter will be helpful to migrate to newer versions without much of a coding change.<\/p>\n\n\n\n<p id=\"block-2ed510c6-d246-4f3f-8a79-0f5221516efe\"><strong>Algomojo API and Trading Bridges are designed with backward compatibility<\/strong>. This means even if the future if newer Algomojo API versions are released still the traders can make use of the older versions.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">\/\/Broker Authentication Parameters\nuser_apikey1 = ParamStr(&quot;user_apikey1&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey1 = ParamStr(&quot;api_secretkey1&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\nuser_apikey2 = ParamStr(&quot;user_apikey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey2 = ParamStr(&quot;api_secretkey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\nuser_apikey3 = ParamStr(&quot;user_apikey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey3 = ParamStr(&quot;api_secretkey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\nuser_apikey4 = ParamStr(&quot;user_apikey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey4 = ParamStr(&quot;api_secretkey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\n\nbroker1 = ParamStr(&quot;Broker Code1&quot;,&quot;tj&quot;); \/\/Broker Short code for Tradejini - tj\nbroker2 = ParamStr(&quot;Broker Code2&quot;,&quot;ab&quot;); \/\/Broker Short code for Aliceblue - ab\nbroker3 = ParamStr(&quot;Broker Code3&quot;,&quot;zb&quot;); \/\/Broker Short code for Zebu - zb\nbroker4 = ParamStr(&quot;Broker Code4&quot;,&quot;en&quot;); \/\/Broker Short code for Enrich - en\nver = ParamStr(&quot;version&quot;,&quot;1.0&quot;); \/\/Enter your API secret key here\n<\/code><\/pre>\n\n\n\n<p id=\"block-2aaf8bbb-f158-4679-9949-545e703a4389\"><strong>3)Trading Parameters<\/strong><\/p>\n\n\n\n<p id=\"block-ed2e31c9-038e-4462-b435-1b6b6d8640b7\">The trading parameter section explains the list of parameters users have to send to their broker for example Exchange Type(NSE, NFO, BSE, MCX), Trading Symbol, order type(MKT, LMT,SL-MKT, SL-LMT), Order Retention Type, Product Code(NRML,MIS,BO,CO), Order Quantity, Order Disclosed Quantity, AMO Orders..etc<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">\/\/Trading Parameters\ns_prdt_ali = ParamList(&quot;product alias&quot;,&quot;BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML&quot;,3); \/\/Product Alias\nTsym = ParamStr(&quot;Trading Symbol&quot;,&quot;RELIANCE-EQ&quot;); \/\/Symbol Name\nexch = ParamList(&quot;Exchange&quot;,&quot;NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX&quot;,1); \/\/Exchange\nRet = ParamList(&quot;Ret&quot;,&quot;DAY|IOC&quot;,0); \/\/Retention\nprctyp = ParamList(&quot;prctyp&quot;,&quot;MKT|L|SL|SL-M&quot;,0); \/\/ Pricetype\nPcode = ParamList(&quot;Product code&quot;,&quot;NRML|BO|CNC|CO|MIS&quot;,4); \/\/ Product Code\nqty = Param(&quot;Quantity&quot;,40,0,100000,1); \/\/ Quantity\nAMO = ParamList(&quot;AMO Order&quot;,&quot;NO|YES&quot;,0); \/\/AMO Order\nplaceordertype = ParamList(&quot;Place Order On&quot;,&quot;Realtime|CandleCompletion&quot;,0); \/\/ Place Order Type\nEnableAlgo = ParamList(&quot;Algo Mode&quot;,&quot;Disable|Enable|LongOnly|ShortOnly&quot;,0); \/\/ Algo Mode\nstgy_name = ParamStr(&quot;Strategy Name&quot;,&quot;Test Strategy Chart&quot;); \/\/ Strategy Name\n<\/code><\/pre>\n\n\n\n<p id=\"block-7f10f20f-6b69-4f83-98c6-6818ff543434\"><strong>4)Log Section and Static Variables declaration<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">static_name_ = Name()+GetChartID()+interval(2)+stgy_name;\nstatic_name_algo = Name()+GetChartID()+interval(2)+stgy_name+&quot;algostatus&quot;;\n\/\/StaticVarSet(static_name_algo, -1); \nGfxSelectFont( &quot;BOOK ANTIQUA&quot;, 14, 100 );\nGfxSetBkMode( 1 );\nif(EnableAlgo == &quot;Enable&quot;)\n{\nAlgoStatus = &quot;Algo Enabled&quot;;\nGfxSetTextColor( colorGreen ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=1)\n{\n_TRACE(&quot;Algo Status : Enabled&quot;+&quot; ChartID = &quot;+GetChartID());\nStaticVarSet(static_name_algo, 1);\n}\n}\nif(EnableAlgo == &quot;Disable&quot;)\n{\nAlgoStatus = &quot;Algo Disabled&quot;+&quot; ChartID = &quot;+GetChartID();\nGfxSetTextColor( colorRed ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=0)\n{\n_TRACE(&quot;Algo Status : Disabled&quot;+&quot; ChartID = &quot;+GetChartID());\nStaticVarSet(static_name_algo, 0);\n}\n}\nif(EnableAlgo == &quot;LongOnly&quot;)\n{\nAlgoStatus = &quot;Long Only&quot;;\nGfxSetTextColor( colorYellow ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=2)\n{\n_TRACE(&quot;Algo Status : Long Only&quot;);\nStaticVarSet(static_name_algo, 2);\n}\n}\nif(EnableAlgo == &quot;ShortOnly&quot;)\n{\nAlgoStatus = &quot;Short Only&quot;;\nGfxSetTextColor( colorYellow ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=3)\n{\n_TRACE(&quot;Algo Status : Short Only&quot;);\nStaticVarSet(static_name_algo, 3);\n}\n}\n\n\n\nresp1 = &quot;&quot;;\nresp2 = &quot;&quot;;\nresp3 = &quot;&quot;;\nresp4 = &quot;&quot;;\n<\/code><\/pre>\n\n\n\n<p id=\"block-90457e44-72e0-4b60-baa0-543275ea5db4\"><strong>5)Creating a Function for Buy Order<\/strong> <strong>with Voice Alert<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">function Buyorder()\n{\n\t\n    algomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\n    api_data =&quot;{\\&quot;stgy_name\\&quot;:\\&quot;&quot;+stgy_name+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;,\\&quot;Tsym\\&quot;:\\&quot;&quot;+Tsym+&quot;\\&quot;,\\&quot;exch\\&quot;:\\&quot;&quot;+exch+&quot;\\&quot;,\\&quot;Ttranstype\\&quot;:\\&quot;&quot;+&quot;B&quot;+&quot;\\&quot;,\\&quot;Ret\\&quot;:\\&quot;&quot;+Ret+&quot;\\&quot;,\\&quot;prctyp\\&quot;:\\&quot;&quot;+prctyp+&quot;\\&quot;,\\&quot;qty\\&quot;:\\&quot;&quot;+qty+&quot;\\&quot;,\\&quot;discqty\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;MktPro\\&quot;:\\&quot;&quot;+&quot;NA&quot;+&quot;\\&quot;,\\&quot;Price\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;TrigPrice\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;Pcode\\&quot;:\\&quot;&quot;+Pcode+&quot;\\&quot;,\\&quot;AMO\\&quot;:\\&quot;&quot;+AMO+&quot;\\&quot;}&quot;;\n    resp1=algomojo.AMDispatcher(user_apikey1, api_secretkey1,&quot;PlaceOrder&quot;,api_data,broker1,ver);\n    resp2=algomojo.AMDispatcher(user_apikey2, api_secretkey2,&quot;PlaceOrder&quot;,api_data,broker2,ver);\n    resp3=algomojo.AMDispatcher(user_apikey3, api_secretkey3,&quot;PlaceOrder&quot;,api_data,broker3,ver);\n    resp4=algomojo.AMDispatcher(user_apikey4, api_secretkey4,&quot;PlaceOrder&quot;,api_data,broker4,ver);\n    StaticVarSet(static_name_+&quot;buyCoverAlgo&quot;,1); \/\/Algo Order was triggered, no more order on this bar\n    _TRACE(&quot;Broker 1 : Tradejini , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Buy Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp1 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n    _TRACE(&quot;Broker 2 : Aliceblue , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Buy Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp2 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n\tSay( &quot;Order Placed&quot; ); \n}<\/code><\/pre>\n\n\n\n<p id=\"block-f5ccede5-d382-40b3-8896-9665b866e923\"><strong>6)Creating a Function for Sell Order<\/strong> <strong>with Voice Alert<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">function Sellorder()\n{\n    algomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\n    api_data =&quot;{\\&quot;stgy_name\\&quot;:\\&quot;&quot;+stgy_name+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;,\\&quot;Tsym\\&quot;:\\&quot;&quot;+Tsym+&quot;\\&quot;,\\&quot;exch\\&quot;:\\&quot;&quot;+exch+&quot;\\&quot;,\\&quot;Ttranstype\\&quot;:\\&quot;&quot;+&quot;S&quot;+&quot;\\&quot;,\\&quot;Ret\\&quot;:\\&quot;&quot;+Ret+&quot;\\&quot;,\\&quot;prctyp\\&quot;:\\&quot;&quot;+prctyp+&quot;\\&quot;,\\&quot;qty\\&quot;:\\&quot;&quot;+qty+&quot;\\&quot;,\\&quot;discqty\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;MktPro\\&quot;:\\&quot;&quot;+&quot;NA&quot;+&quot;\\&quot;,\\&quot;Price\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;TrigPrice\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;Pcode\\&quot;:\\&quot;&quot;+Pcode+&quot;\\&quot;,\\&quot;AMO\\&quot;:\\&quot;&quot;+AMO+&quot;\\&quot;}&quot;;\n    resp1=algomojo.AMDispatcher(user_apikey1, api_secretkey1,&quot;PlaceOrder&quot;,api_data,broker1,ver);\n    resp2=algomojo.AMDispatcher(user_apikey2, api_secretkey2,&quot;PlaceOrder&quot;,api_data,broker2,ver);\n    resp3=algomojo.AMDispatcher(user_apikey3, api_secretkey3,&quot;PlaceOrder&quot;,api_data,broker3,ver);\n    resp4=algomojo.AMDispatcher(user_apikey4, api_secretkey4,&quot;PlaceOrder&quot;,api_data,broker4,ver);\n    StaticVarSet(static_name_+&quot;buyCoverAlgo&quot;,1); \/\/Algo Order was triggered, no more order on this bar\n    _TRACE(&quot;Broker 1 : Tradejini , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Sell Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp1 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n    _TRACE(&quot;Broker 2 : Aliceblue , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Sell Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp2 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n            \n    Say( &quot;Order Placed&quot; );\n}\n<\/code><\/pre>\n\n\n\n<p id=\"block-5c442b3b-344d-43f1-9172-8396528b913b\"><strong>7)Create Button Functions (Supports both old and new Amibroker Versions)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">X0 = 20;\nY0 = 100;\nX1 = 100;\n\nLBClick = GetCursorMouseButtons() == 9;\t\/\/ Click\nMouseX  = Nz(GetCursorXPosition(1));\t\t\/\/ \nMouseY  = Nz(GetCursorYPosition(1));\t\t\/\/\n\nprocedure DrawButton (Text, x1, y1, x2, y2, colorFrom, colorTo)\n{\n\tGfxSetOverlayMode(0);\n\tGfxSelectFont(&quot;Verdana&quot;, 9, 700);\n\tGfxSetBkMode(1);\n\tGfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);\n\tGfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);\n}\nGfxSetTextColor(colorWhite);<\/code><\/pre>\n\n\n\n<p id=\"block-552da26a-6fe0-44b2-9a23-326ff83b69e7\"><strong>8)Configure the Buy and Sell Buttons for Multi Broker Execution<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">\nif(EnableAlgo == &quot;Enable&quot;)\n{\n\n\tDrawButton(&quot;Buy&quot;, X0, Y0, X0+X1, Y0+30, colorGreen, colorGreen);\n\tCursorInBuyButton = MouseX &gt;= X0 AND MouseX &lt;= X0+X1 AND MouseY &gt;= Y0 AND MouseY &lt;= Y0+30;\n\tBuyButtonClick = CursorInBuyButton AND LBClick;\n\t\n\tDrawButton(&quot;Sell&quot;, X0, Y0+40, X0+X1, Y0+70, colorRed, colorRed);\n\tCursorInSellButton = MouseX &gt;= X0 AND MouseX &lt;= X0+X1 AND MouseY &gt;= Y0+40 AND MouseY &lt;= Y0+70;\n\tSellButtonClick = CursorInSellButton AND LBClick;\n\t\n\tif( BuyButtonClick AND StaticVarGet(Name()+GetChartID()+&quot;buyAlgo&quot;)==0 ) \n\t{\n\t\tBuyOrder();\n\t\tStaticVarSet(Name()+GetChartID()+&quot;buyAlgo&quot;,1); \n\t}\n\telse\n\t{\n\t\tStaticVarSet(Name()+GetChartID()+&quot;buyAlgo&quot;,0);\n\t}\n\tif( SellButtonClick AND StaticVarGet(Name()+GetChartID()+&quot;sellAlgo&quot;)==0 ) \n\t{\n\t\tSellOrder();\n\t\tStaticVarSet(Name()+GetChartID()+&quot;sellAlgo&quot;,1); \n\t}\n\telse\n\t{\n\t\tStaticVarSet(Name()+GetChartID()+&quot;sellAlgo&quot;,0); \n\t}\n\t\n\t\n\t\n\t\n\n}\n\n_SECTION_END();\n\n_SECTION_BEGIN(&quot;Price&quot;);\nSetChartOptions(0,chartShowArrows|chartShowDates);\n_N(Title = &quot;&quot;);\nPlot( C, &quot;Close&quot;, ParamColor(&quot;Color&quot;, colorDefault ), styleNoTitle | ParamStyle(&quot;Style&quot;) | GetPriceStyle() ); \n_SECTION_END();\n<\/code><\/pre>\n\n\n\n<p id=\"block-833d7e97-9721-4f73-bd64-1c0ed0da6df7\"><strong>Here is the fully functional Amibroker AFL code for button trading module with multi-broker execution.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">\nTitle = &quot; &quot;;\n\n_SECTION_BEGIN(&quot;Button Trading For Old Amibroker Versions&quot;);\n\nRequestTimedRefresh(1, False); \/\/ Send orders even if Amibroker is minimized or Chart is not active\n\n\/\/Broker Authentication Parameters\nuser_apikey1 = ParamStr(&quot;user_apikey1&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey1 = ParamStr(&quot;api_secretkey1&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\nuser_apikey2 = ParamStr(&quot;user_apikey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey2 = ParamStr(&quot;api_secretkey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\nuser_apikey3 = ParamStr(&quot;user_apikey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey3 = ParamStr(&quot;api_secretkey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\nuser_apikey4 = ParamStr(&quot;user_apikey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API key here\napi_secretkey4 = ParamStr(&quot;api_secretkey2&quot;,&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;); \/\/Enter your API secret key here\n\nbroker1 = ParamStr(&quot;Broker Code1&quot;,&quot;tj&quot;); \/\/Broker Short code for Tradejini - tj\nbroker2 = ParamStr(&quot;Broker Code2&quot;,&quot;ab&quot;); \/\/Broker Short code for Aliceblue - ab\nbroker3 = ParamStr(&quot;Broker Code3&quot;,&quot;zb&quot;); \/\/Broker Short code for Zebu - zb\nbroker4 = ParamStr(&quot;Broker Code4&quot;,&quot;en&quot;); \/\/Broker Short code for Enrich - en\nver = ParamStr(&quot;version&quot;,&quot;1.0&quot;); \/\/Enter your API secret key here\n\n\n\n\/\/Trading Parameters\ns_prdt_ali = ParamList(&quot;product alias&quot;,&quot;BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML&quot;,3); \/\/Product Alias\nTsym = ParamStr(&quot;Trading Symbol&quot;,&quot;RELIANCE-EQ&quot;); \/\/Symbol Name\nexch = ParamList(&quot;Exchange&quot;,&quot;NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX&quot;,1); \/\/Exchange\nRet = ParamList(&quot;Ret&quot;,&quot;DAY|IOC&quot;,0); \/\/Retention\nprctyp = ParamList(&quot;prctyp&quot;,&quot;MKT|L|SL|SL-M&quot;,0); \/\/ Pricetype\nPcode = ParamList(&quot;Product code&quot;,&quot;NRML|BO|CNC|CO|MIS&quot;,4); \/\/ Product Code\nqty = Param(&quot;Quantity&quot;,40,0,100000,1); \/\/ Quantity\nAMO = ParamList(&quot;AMO Order&quot;,&quot;NO|YES&quot;,0); \/\/AMO Order\nplaceordertype = ParamList(&quot;Place Order On&quot;,&quot;Realtime|CandleCompletion&quot;,0); \/\/ Place Order Type\nEnableAlgo = ParamList(&quot;Algo Mode&quot;,&quot;Disable|Enable|LongOnly|ShortOnly&quot;,0); \/\/ Algo Mode\nstgy_name = ParamStr(&quot;Strategy Name&quot;,&quot;Test Strategy Chart&quot;); \/\/ Strategy Name\n\nstatic_name_ = Name()+GetChartID()+interval(2)+stgy_name;\nstatic_name_algo = Name()+GetChartID()+interval(2)+stgy_name+&quot;algostatus&quot;;\n\/\/StaticVarSet(static_name_algo, -1); \nGfxSelectFont( &quot;BOOK ANTIQUA&quot;, 14, 100 );\nGfxSetBkMode( 1 );\nif(EnableAlgo == &quot;Enable&quot;)\n{\nAlgoStatus = &quot;Algo Enabled&quot;;\nGfxSetTextColor( colorGreen ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=1)\n{\n_TRACE(&quot;Algo Status : Enabled&quot;+&quot; ChartID = &quot;+GetChartID());\nStaticVarSet(static_name_algo, 1);\n}\n}\nif(EnableAlgo == &quot;Disable&quot;)\n{\nAlgoStatus = &quot;Algo Disabled&quot;+&quot; ChartID = &quot;+GetChartID();\nGfxSetTextColor( colorRed ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=0)\n{\n_TRACE(&quot;Algo Status : Disabled&quot;+&quot; ChartID = &quot;+GetChartID());\nStaticVarSet(static_name_algo, 0);\n}\n}\nif(EnableAlgo == &quot;LongOnly&quot;)\n{\nAlgoStatus = &quot;Long Only&quot;;\nGfxSetTextColor( colorYellow ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=2)\n{\n_TRACE(&quot;Algo Status : Long Only&quot;);\nStaticVarSet(static_name_algo, 2);\n}\n}\nif(EnableAlgo == &quot;ShortOnly&quot;)\n{\nAlgoStatus = &quot;Short Only&quot;;\nGfxSetTextColor( colorYellow ); \nGfxTextOut( &quot;Algostatus : &quot;+AlgoStatus+&quot; ChartID = &quot;+GetChartID() , 20, 40); \nif(Nz(StaticVarGet(static_name_algo),0)!=3)\n{\n_TRACE(&quot;Algo Status : Short Only&quot;);\nStaticVarSet(static_name_algo, 3);\n}\n}\n\n\n\nresp1 = &quot;&quot;;\nresp2 = &quot;&quot;;\nresp3 = &quot;&quot;;\nresp4 = &quot;&quot;;\n\n\n\n\nfunction Buyorder()\n{\n\t\n    algomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\n    api_data =&quot;{\\&quot;stgy_name\\&quot;:\\&quot;&quot;+stgy_name+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;,\\&quot;Tsym\\&quot;:\\&quot;&quot;+Tsym+&quot;\\&quot;,\\&quot;exch\\&quot;:\\&quot;&quot;+exch+&quot;\\&quot;,\\&quot;Ttranstype\\&quot;:\\&quot;&quot;+&quot;B&quot;+&quot;\\&quot;,\\&quot;Ret\\&quot;:\\&quot;&quot;+Ret+&quot;\\&quot;,\\&quot;prctyp\\&quot;:\\&quot;&quot;+prctyp+&quot;\\&quot;,\\&quot;qty\\&quot;:\\&quot;&quot;+qty+&quot;\\&quot;,\\&quot;discqty\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;MktPro\\&quot;:\\&quot;&quot;+&quot;NA&quot;+&quot;\\&quot;,\\&quot;Price\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;TrigPrice\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;Pcode\\&quot;:\\&quot;&quot;+Pcode+&quot;\\&quot;,\\&quot;AMO\\&quot;:\\&quot;&quot;+AMO+&quot;\\&quot;}&quot;;\n    resp1=algomojo.AMDispatcher(user_apikey1, api_secretkey1,&quot;PlaceOrder&quot;,api_data,broker1,ver);\n    resp2=algomojo.AMDispatcher(user_apikey2, api_secretkey2,&quot;PlaceOrder&quot;,api_data,broker2,ver);\n    resp3=algomojo.AMDispatcher(user_apikey3, api_secretkey3,&quot;PlaceOrder&quot;,api_data,broker3,ver);\n    resp4=algomojo.AMDispatcher(user_apikey4, api_secretkey4,&quot;PlaceOrder&quot;,api_data,broker4,ver);\n    StaticVarSet(static_name_+&quot;buyCoverAlgo&quot;,1); \/\/Algo Order was triggered, no more order on this bar\n    _TRACE(&quot;Broker 1 : Tradejini , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Buy Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp1 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n    _TRACE(&quot;Broker 2 : Aliceblue , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Buy Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp2 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n\tSay( &quot;Order Placed&quot; ); \n}\n\nfunction Sellorder()\n{\n    algomojo=CreateObject(&quot;AMAMIBRIDGE.Main&quot;);\n    api_data =&quot;{\\&quot;stgy_name\\&quot;:\\&quot;&quot;+stgy_name+&quot;\\&quot;,\\&quot;s_prdt_ali\\&quot;:\\&quot;&quot;+s_prdt_ali+&quot;\\&quot;,\\&quot;Tsym\\&quot;:\\&quot;&quot;+Tsym+&quot;\\&quot;,\\&quot;exch\\&quot;:\\&quot;&quot;+exch+&quot;\\&quot;,\\&quot;Ttranstype\\&quot;:\\&quot;&quot;+&quot;S&quot;+&quot;\\&quot;,\\&quot;Ret\\&quot;:\\&quot;&quot;+Ret+&quot;\\&quot;,\\&quot;prctyp\\&quot;:\\&quot;&quot;+prctyp+&quot;\\&quot;,\\&quot;qty\\&quot;:\\&quot;&quot;+qty+&quot;\\&quot;,\\&quot;discqty\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;MktPro\\&quot;:\\&quot;&quot;+&quot;NA&quot;+&quot;\\&quot;,\\&quot;Price\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;TrigPrice\\&quot;:\\&quot;&quot;+&quot;0&quot;+&quot;\\&quot;,\\&quot;Pcode\\&quot;:\\&quot;&quot;+Pcode+&quot;\\&quot;,\\&quot;AMO\\&quot;:\\&quot;&quot;+AMO+&quot;\\&quot;}&quot;;\n    resp1=algomojo.AMDispatcher(user_apikey1, api_secretkey1,&quot;PlaceOrder&quot;,api_data,broker1,ver);\n    resp2=algomojo.AMDispatcher(user_apikey2, api_secretkey2,&quot;PlaceOrder&quot;,api_data,broker2,ver);\n    resp3=algomojo.AMDispatcher(user_apikey3, api_secretkey3,&quot;PlaceOrder&quot;,api_data,broker3,ver);\n    resp4=algomojo.AMDispatcher(user_apikey4, api_secretkey4,&quot;PlaceOrder&quot;,api_data,broker4,ver);\n    StaticVarSet(static_name_+&quot;buyCoverAlgo&quot;,1); \/\/Algo Order was triggered, no more order on this bar\n    _TRACE(&quot;Broker 1 : Tradejini , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Sell Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp1 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n    _TRACE(&quot;Broker 2 : Aliceblue , Strategy : &quot;+ stgy_name +&quot;AlgoStatus : &quot;+ EnableAlgo +&quot;Chart Symbol : &quot;+ Name() +&quot;  Trading Symbol : &quot;+  Tsym +&quot;  Quantity : &quot;+ qty +&quot;  Signal : Sell Signal  TimeFrame : &quot;+ Interval(2)+&quot;  Response : &quot;+ resp2 +&quot;  ChardId : &quot;+ GetChartID() + &quot; Latest Price : &quot;+LastValue(C));\n            \n    Say( &quot;Order Placed&quot; );\n}\n\n\nX0 = 20;\nY0 = 100;\nX1 = 100;\n\nLBClick = GetCursorMouseButtons() == 9;\t\/\/ Click\nMouseX  = Nz(GetCursorXPosition(1));\t\t\/\/ \nMouseY  = Nz(GetCursorYPosition(1));\t\t\/\/\n\nprocedure DrawButton (Text, x1, y1, x2, y2, colorFrom, colorTo)\n{\n\tGfxSetOverlayMode(0);\n\tGfxSelectFont(&quot;Verdana&quot;, 9, 700);\n\tGfxSetBkMode(1);\n\tGfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);\n\tGfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);\n}\nGfxSetTextColor(colorWhite);\n\nif(EnableAlgo == &quot;Enable&quot;)\n{\n\n\tDrawButton(&quot;Buy&quot;, X0, Y0, X0+X1, Y0+30, colorGreen, colorGreen);\n\tCursorInBuyButton = MouseX &gt;= X0 AND MouseX &lt;= X0+X1 AND MouseY &gt;= Y0 AND MouseY &lt;= Y0+30;\n\tBuyButtonClick = CursorInBuyButton AND LBClick;\n\t\n\tDrawButton(&quot;Sell&quot;, X0, Y0+40, X0+X1, Y0+70, colorRed, colorRed);\n\tCursorInSellButton = MouseX &gt;= X0 AND MouseX &lt;= X0+X1 AND MouseY &gt;= Y0+40 AND MouseY &lt;= Y0+70;\n\tSellButtonClick = CursorInSellButton AND LBClick;\n\t\n\tif( BuyButtonClick AND StaticVarGet(Name()+GetChartID()+&quot;buyAlgo&quot;)==0 ) \n\t{\n\t\tBuyOrder();\n\t\tStaticVarSet(Name()+GetChartID()+&quot;buyAlgo&quot;,1); \n\t}\n\telse\n\t{\n\t\tStaticVarSet(Name()+GetChartID()+&quot;buyAlgo&quot;,0);\n\t}\n\tif( SellButtonClick AND StaticVarGet(Name()+GetChartID()+&quot;sellAlgo&quot;)==0 ) \n\t{\n\t\tSellOrder();\n\t\tStaticVarSet(Name()+GetChartID()+&quot;sellAlgo&quot;,1); \n\t}\n\telse\n\t{\n\t\tStaticVarSet(Name()+GetChartID()+&quot;sellAlgo&quot;,0); \n\t}\n\t\n\t\n\t\n\t\n\n}\n\n_SECTION_END();\n\n_SECTION_BEGIN(&quot;Price&quot;);\nSetChartOptions(0,chartShowArrows|chartShowDates);\n_N(Title = &quot;&quot;);\nPlot( C, &quot;Close&quot;, ParamColor(&quot;Color&quot;, colorDefault ), styleNoTitle | ParamStyle(&quot;Style&quot;) | GetPriceStyle() ); \n_SECTION_END();\n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders simultaneously to 4 brokers.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[6,15,29],"tags":[36,7,14,37,23],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/62"}],"collection":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":4,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions\/631"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}