/* Created By : Rajandran R(Founder - Marketcalls / Co-Founder Algomojo ) Created on : 01 Oct 2020. Website : www.marketcalls.in / www.algomojo.com */ _SECTION_BEGIN("Button Trading - Algomojo Fyers Account"); RequestTimedRefresh(1, False); // Send orders even if Amibroker is minimized or Chart is not active broker = ParamStr("Broker","fy"); ver = ParamStr("API Version","1.0"); apikey = ParamStr("APIKey","xxxxxxxxxxxxxxxxx"); apisecret = ParamStr("APIsecret","xxxxxxxxxxxxxxxxx"); client_id = ParamStr("Client ID","xxxxxxxx"); strg_name = ParamStr("Strategy Name","Amibroker Strategy"); exchange = ParamList("Exchange","NSE|BSE|MCX|CDS"); symbol = ParamStr("Symbol Name","RELIANCE-EQ"); qty = Param("Quantity",1,1,10000,1); type = ParamList("Order Type","MKT|LMT|SL-MKT|SL-LMT"); if(type=="MKT") { type = 2; } else if(type=="LMT") { type = 1; } else if(type=="SL-MKT") { type = 3; } else if(type=="SL-LMT") { type = 4; } symbol = exchange+":"+symbol; productType = ParamList("Product Type","INTRADAY|CNC|MARGIN|BO|CO",0); limitPrice = "0"; stopPrice = "0"; validity = "DAY"; disclosedQty = "0"; offlineOrder = "False"; stopLoss = "0"; takeProfit = "0"; tradedelay = Param("Execution Delay",0,0,1); // 0 - Execution with No Delay after a signal, 1- Execution at the end of the candle EnableAlgo = ParamList("Algo Mode","Disable|Enable|LongOnly|ShortOnly",0); // Algo Mode resp=""; static_name_ = Name()+GetChartID()+interval(2)+strg_name; static_name_algo = Name()+GetChartID()+interval(2)+strg_name+"algostatus"; //StaticVarSet(static_name_algo, -1); 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"+" ChartID = "+GetChartID()); 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"+" ChartID = "+GetChartID()); StaticVarSet(static_name_algo, 0); } } if(EnableAlgo == "LongOnly") { AlgoStatus = "Long Only"; GfxSetTextColor( colorYellow ); GfxTextOut( "Algostatus : "+AlgoStatus+" ChartID = "+GetChartID() , 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+" ChartID = "+GetChartID() , 20, 40); if(Nz(StaticVarGet(static_name_algo),0)!=3) { _TRACE("Algo Status : Short Only"); StaticVarSet(static_name_algo, 3); } } function buyorder() { algomojo=CreateObject("AMAMIBRIDGE.Main"); //COM Interface api_data = "{ \"strg_name\": \""+strg_name+"\", \"symbol\":\""+symbol+"\", \"qty\":\""+qty+"\", \"type\":\""+type+"\", \"side\":\"1\", \"productType\":\""+productType+"\", \"limitPrice\":\"0\", \"stopPrice\":\"0\", \"validity\": \"DAY\", \"disclosedQty\":\"0\", \"offlineOrder\": \"False\", \"stopLoss\":\"0\", \"takeProfit\":\"0\" }"; _TRACE("API Data Request :"+api_data); //data transmitted the broker // Data Assembling and Transmitting to the broker and recieve the data from the broker resp=algomojo.AMDispatcher(apikey, apisecret,"PlaceOrder",api_data,broker,ver); _TRACE("API Response :" + resp); } function sellorder() { algomojo=CreateObject("AMAMIBRIDGE.Main"); //COM Interface api_data = "{ \"strg_name\": \""+strg_name+"\", \"symbol\":\""+symbol+"\", \"qty\":\""+qty+"\", \"type\":\""+type+"\", \"side\":\"-1\", \"productType\":\""+productType+"\", \"limitPrice\":\"0\", \"stopPrice\":\"0\", \"validity\": \"DAY\", \"disclosedQty\":\"0\", \"offlineOrder\": \"False\", \"stopLoss\":\"0\", \"takeProfit\":\"0\" }"; _TRACE("API Data Request :"+api_data); //data transmitted the broker // Data Assembling and Transmitting to the broker and recieve the data from the broker resp=algomojo.AMDispatcher(apikey, apisecret,"PlaceOrder",api_data,broker,ver); _TRACE("API Response :" + resp); } function GuiButtonTrigger( ButtonName, x, y, width, Height ) { /// @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 before: %g", IDset ); GuiButton( ButtonName, ++IDset, x, y, width, height, 7 ); //_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; if( BuyClicked AND StaticVarGet(Name()+GetChartID()+"buyAlgo")==0 ) { BuyOrder(); result = 1; StaticVarSet(Name()+GetChartID()+"buyAlgo",1); } else { StaticVarSet(Name()+GetChartID()+"buyAlgo",0); } if( SellClicked AND StaticVarGet(Name()+GetChartID()+"sellAlgo")==0 ) { SellOrder(); result = -1; StaticVarSet(Name()+GetChartID()+"sellAlgo",1); } else { StaticVarSet(Name()+GetChartID()+"sellAlgo",0); } return result; } BuyTrigger = GuiButtonTrigger( "Buy "+qty+" Shares", 0, 100, 200, 30 ); SellTrigger = GuiButtonTrigger( "Sell "+qty+" Shares", 200, 100, 200, 30 ); GuiSetColors( 1, 3, 2, colorRed, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); Title = "Trigger: " + WriteIf(BuyTrigger==1,"Buy Triggered",WriteIf(BuyTrigger==-1,"Sell Triggered","0")); SetChartOptions(0 , chartShowArrows | chartShowDates); Plot(Close,"Candle", colorDefault, styleCandle); _SECTION_END();