This video tutorial explores time-based automated order execution from Amibroker to Algomojo Platform. Generally, Time Based Execution is generally required to close your intraday orders on time or to do automated time-based options hedging to your positions.
You can download the Algomojo Time Based Order Execution Modules by logging into Algomojo-> Tools -> Amibroker Modules
Here is the step by step guidance on how to test Algomojo Time Based Execution Module
Algomojo Time Based Execution Module for Amibroker
//Algomojo Time Based Exection Module//
// Developer: Rajandran R (Founder - Marketcalls / Co-Founder - Algomojo)
// Date: 28-Oct-2020
// Website: algomojo.com / marketcalls.in
_SECTION_BEGIN("Algomojo Timing Module");
RequestTimedRefresh(1, False);
function GetSecondNum()
{
Time = Now( 4 );
return Time;
}
user_apikey = ParamStr("user_apikey","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Enter your API key here
api_secret = ParamStr("api_secret","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); //Enter your API secret key here
otime = ParamTime("Execution Time", "15:15:00", 0);
Otype = ParamList("Execution Type", "Buy|Sell",0);
s_prdt_ali = ParamList("s_prdt_ali","BO:BO|CNC:CNC|CO:CO|MIS:MIS|NRML:NRML",3);
Tsym = ParamStr("Tsym","RELIANCE-EQ");
exch = ParamList("Exchange","NFO|NSE|BSE|CDS|MCX|NCDEX|BFO|MCXSXFO|MCXSX",1);
Ret = ParamList("Ret","DAY|IOC",0);
prctyp = ParamList("prctyp","MKT|L|SL|SL-M",0);
Pcode = ParamList("Pcode","NRML|BO|CNC|CO|MIS",4);
qty = Param("Quatity",40,0,100000,1);
AMO = ParamList("AMO","NO|YES",0);
Timedexecution = ParamList("Timed Order Execution", "Disable|Enable",0);
stgy_name = ParamStr("Strategy Name","Test Strategy Chart");
static_name = Name()+GetChartID()+interval(2)+stgy_name;
if(Timedexecution == "Enable")
{
SetChartBkColor(colorDarkGrey);
if(GetsecondNum() == otime AND StaticVarGet(static_name + otime) == 0)
{
StaticVarSet(static_name + otime, 1);
if( Otype == "Buy" )
{
algomojo=CreateObject("XLAMIBRIDGE.Main");
api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"Tsym\":\""+Tsym+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"B"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+"0"+"\",\"MktPro\":\""+"NA"+"\",\"Price\":\""+"0"+"\",\"TrigPrice\":\""+"0"+"\",\"Pcode\":\""+Pcode+"\",\"AMO\":\""+AMO+"\"}";
resp=algomojo.AMDispatcher(user_apikey, api_secret,"PlaceOrder",api_data);
_TRACE("Strategy : "+ stgy_name +" Symbol : "+ Tsym +" "+ Interval(2)+" Response : "+ resp +" ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
}
if( otype == "Sell")
{
algomojo=CreateObject("XLAMIBRIDGE.Main");
api_data ="{\"stgy_name\":\""+stgy_name+"\",\"s_prdt_ali\":\""+s_prdt_ali+"\",\"Tsym\":\""+Tsym+"\",\"exch\":\""+exch+"\",\"Ttranstype\":\""+"S"+"\",\"Ret\":\""+Ret+"\",\"prctyp\":\""+prctyp+"\",\"qty\":\""+qty+"\",\"discqty\":\""+"0"+"\",\"MktPro\":\""+"NA"+"\",\"Price\":\""+"0"+"\",\"TrigPrice\":\""+"0"+"\",\"Pcode\":\""+Pcode+"\",\"AMO\":\""+AMO+"\"}";
resp=algomojo.AMDispatcher(user_apikey, api_secret,"PlaceOrder",api_data);
_TRACE("Strategy : "+ stgy_name +" Symbol : "+ Tsym +" "+ Interval(2)+" Response : "+ resp +" ChardId : "+ GetChartID() + " Latest Price : "+LastValue(C));
}
}
else if(GetsecondNum() != otime)
{
StaticVarSet(static_name + otime, 0);
}
}
_SECTION_END();
_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();