Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Intraday Straddle Execution Module – Amibroker for AngelOne Users

11 min read

This tutorial focus on how to automate your time-based index straddle/strangle management with intraday stop-loss levels with time-based entry and exits using Algomojo Platform and Amibroker. Modern Internal memory management is used to speed up the execution and management of Index Straddle.

Trading ActivityOrders to be Placed
Time Based EntryEnter Straddle/Strangle at 9.30a.m (Two legged Order)
Calculate the Short Call Average PriceCalculate the Short call Stoploss
Calculate the Short Put Average PriceCalculate the Short Put Stoploss
Place Stoploss OrdersPlace the Stoploss for both Short call and Short Put if the entry order status is completed
Check Open PositionsCheck the Open Positions for the Qty traded
Time Based ExitSquare of Short Call and Short Put legs for the qty present in the open positions around 3.15p.m.

Supported Brokers : Angel Broking (AngelOne)
Supported Algo Platform: Algomojo Platform
Supported Amibroker Version: Amibroker 6.0 or Higher
Supported Trading Instruments: Index Options

Intraday Straddle Management – Amibroker AFL Code

// Angel One - Intraday Straddle Module
// Developer: Rajandran R (Founder - Marketcalls / Co-Founder - Algomojo)
// Date: 19-Apr-2022
// Website: algomojo.com / marketcalls.in

_SECTION_BEGIN("Angel Broking - Broker Controls");

RequestTimedRefresh(1, False);
SetOption("staticVarAutoSave",60); //every 60 seconds once the internal memory will be autosaved to persistvars.bin automatically 
EnableTextOutput(False);  //avoid bringing unwated string variables into the Interpretation Box


broker =ParamStr("Broker","an"); //Broker Short Code - an- angel broking
ver = ParamStr("API Version ","1.0");
clnt_id = ParamStr("Client ID","xxxx"); //Enter your trading client ID
user_apikey = ParamStr("apikey","xxxxxxxxxxxxxxxxxxxxx"); //Enter your API key here
api_secretkey = ParamStr("secretkey","xxxxxxxxxxxxxxxxxxxxx"); //Enter your API secret key here

_SECTION_END();



_SECTION_BEGIN("Algomojo AngelOne - Intraday Time Based Straddle Controls");

stgy_name = ParamStr("Strategy Name","Time Based Straddle");
entrytime = ParamTime("Entry Time","09:20:00");
exittime = ParamTime("Exit Time","15:15:00");
stopsenabled = ParamList("Stoploss Controls","Disabled|Enabled",0);
stoppercentage = Param("Stoploss Percentage",30,10,100,1);
stoplossslippagebuffer = Param("Stoploss Slippage Buffer",2,0.25,100,0.25);  //Getting LMT Price from the Trigger Price
transtype = Paramlist("Options Transaction Type","SELL",0);
variety = "NORMAL";
spot_sym = Paramlist("Spot Symbol","NIFTY|BANKNIFTY",0);
expiry_dt = ParamStr("Expiry Date","28APR22");


ordertype = "MARKET";
quantity = Param("Quantity",50,1,10000,1);

symboltoken = "";
duration = "DAY";
price = "0";
squareoff = "0";
stoploss = "0";
triggerprice = "0";
trailingStopLoss = "0";
disclosedquantity = "0";
exchange = ParamList("Exchange","NFO",0);

producttype = Paramlist("Product Type","CARRYFORWARD|INTRADAY",0);

if(spot_sym == "NIFTY")
{
lotsize = 50;
strike_interval = 50;

}

if(spot_sym == "BANKNIFTY")
{
lotsize = 25;
strike_interval = 100;

}

quantity = Param("Quantity(Lots)",1,1,100,1)*lotsize;

//Positive Offset - OTM, Zero Offset - ATM, Negative Offset - ITM
CEoffset = Param("CE Offset",0,-10,10,1);
PEoffset = -1*Param("PE Offset",0,-10,10,1);

DelaySLOrders = Param("Delay SL Orders (mS)",2000,0,10000,10);

EnableAlgo = ParamList("Algo Mode","Disable|Enable",0); // Algo Mode

clear = ParamTrigger("Clear Static Variables","Clear");
static_var_options = "staticvar_options"+Name()+Interval(2)+GetChartID() + stgy_name;
static_name_algo = Name()+GetChartID()+interval(2)+stgy_name+"algostatus";

if(clear)
{

StaticVarRemove("staticvar_options*");
_TRACE("Static Variables Cleared");
}


_SECTION_END();






_SECTION_BEGIN("Angelone - Intraday Straddle - Internal Memory Display");


function removeinternalmemory(typeoforder,opt_type,legno)
{

StaticVarRemove(static_var_options+typeoforder+"Options_symbol"+opt_type+legno);
StaticVarRemove(static_var_options+typeoforder+"Options_transtype"+opt_type+legno);
StaticVarRemove(static_var_options+typeoforder+"Options_orderno"+opt_type+legno);
StaticVarRemove(static_var_options+typeoforder+"Options_orderstatus"+opt_type+legno);
StaticVarRemove(static_var_options+typeoforder+"Options_averageprice"+opt_type+legno);
StaticVarRemove(static_var_options+typeoforder+"Options_executedordertime"+opt_type+legno);

}




//Internal Memory - Main ATM CE
opt_type="CE";
legno = 1;
printf("\n---------------Leg 1 CE Orders (Main) Internal Memory----------");


printf("\nSymbol : "+StaticVarGetText(static_var_options+"Options_symbol"+opt_type+legno));
printf("\nTranType : "+StaticVarGetText(static_var_options+"Options_transtype"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"Options_orderno"+opt_type+legno));
printf("\nOrder Status : "+StaticVarGetText(static_var_options+"Options_orderstatus"+opt_type+legno));
printf("\nOptions_averageprice : "+StaticVarGetText(static_var_options+"Options_averageprice"+opt_type+legno));
printf("\nExecutionTime : "+StaticVarGetText(static_var_options+"Options_executedordertime"+opt_type+legno));

//Internal Memory - Stoploss ATM CE
opt_type="CE";
legno = 1;
printf("\n---------------Leg 1 CE Orders (Stoploss) Internal Memory----------");


printf("\nSymbol : "+StaticVarGetText(static_var_options+"SLOptions_symbol"+opt_type+legno));
printf("\nTranType : "+StaticVarGetText(static_var_options+"SLOptions_transtype"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"SLOptions_orderno"+opt_type+legno));
printf("\nOrder Status : "+StaticVarGetText(static_var_options+"SLOptions_orderstatus"+opt_type+legno));
printf("\nOptions_averageprice : "+StaticVarGetText(static_var_options+"SLOptions_averageprice"+opt_type+legno));
printf("\nExecutionTime : "+StaticVarGetText(static_var_options+"SLOptions_executedordertime"+opt_type+legno));

//Internal Memory - Main ATM PE
opt_type="PE";
legno = 2;
printf("\n---------------Leg 2 PE Orders (Main) Internal Memory----------");


printf("\nSymbol : "+StaticVarGetText(static_var_options+"Options_symbol"+opt_type+legno));
printf("\nTranType : "+StaticVarGetText(static_var_options+"Options_transtype"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"Options_orderno"+opt_type+legno));
printf("\nOrder Status : "+StaticVarGetText(static_var_options+"Options_orderstatus"+opt_type+legno));
printf("\nOptions_averageprice : "+StaticVarGetText(static_var_options+"Options_averageprice"+opt_type+legno));
printf("\nExecutionTime : "+StaticVarGetText(static_var_options+"Options_executedordertime"+opt_type+legno));

//Internal Memory - Stoploss ATM PE
opt_type="PE";
legno = 2;
printf("\n---------------Leg 2 PE Orders (Stoploss) Internal Memory----------");


printf("\nSymbol : "+StaticVarGetText(static_var_options+"SLOptions_symbol"+opt_type+legno));
printf("\nTranType : "+StaticVarGetText(static_var_options+"SLOptions_transtype"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"SLOptions_orderno"+opt_type+legno));
printf("\nOrder Status : "+StaticVarGetText(static_var_options+"SLOptions_orderstatus"+opt_type+legno));
printf("\nOptions_averageprice : "+StaticVarGetText(static_var_options+"SLOptions_averageprice"+opt_type+legno));
printf("\nExecutionTime : "+StaticVarGetText(static_var_options+"SLOptions_executedordertime"+opt_type+legno));


_SECTION_END();

function GetSecondNum()
{
Time = Now(4);
return Time;
}

function getorderbook()
{
api_data = "{}";
algomojo=CreateObject("AMAMIBRIDGE.Main");  // Calling the DLL Bridge
resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"OrderBook",api_data,broker,ver);
_TRACE("Orderbook Response"+resp);
return resp;

}


function GetSymbol(resp)
{

symbol="";
symbol = StrExtract(resp,2,'{');
symbol = StrExtract(symbol,0,',');
symbol = StrExtract(symbol,1,':');
symbol = StrExtract(symbol,1,'"');

_TRACE("Symbol is :"+symbol);

return symbol;
}

function GetOrderID(resp)
{

orderno = "";


orderno = StrExtract(resp,2,'{');
orderno = StrExtract(orderno,1,',');
orderno = StrExtract(orderno,1,':');
orderno = StrExtract(orderno,1,'"');

_TRACE("Order No is : "+orderno);

return orderno;


}



function GetOrderStatus(resp,orderno)
{


ordstatus="";

ordstatus = StrExtract(resp,1,'[');

for( item = 1; ( istatus = StrExtract( ordstatus, item,'{' )) != ""; item++ )
{


if(Strfind(istatus,orderno) AND StrFind(istatus,producttype)) //Matches the symbol and //Matches the Order Type
{

flag = 1; //turn on the flag

for( jitem = 0; ( posdetails = StrExtract( istatus, jitem,',' )) != ""; jitem++ )
{

 if(Strfind(posdetails,"orderstatus"))
  {
   posdetails = StrExtract(posdetails,1,':');
   orderstatus = StrTrim(posdetails,"\"");
    _TRACE("Status : "+orderstatus);
  }



} //end of for loop
}

}//end of for loop

return orderstatus;

}

function GetAveragePrice(resp,orderno)
{


averageprice = "";


ordstatus = StrExtract(resp,1,'[');

for( item = 1; ( istatus = StrExtract( ordstatus, item,'{' )) != ""; item++ )
{


if(Strfind(istatus,orderno) AND StrFind(istatus,producttype)) //Matches the symbol and //Matches the Order Type
{

flag = 1; //turn on the flag

for( jitem = 0; ( posdetails = StrExtract( istatus, jitem,',' )) != ""; jitem++ )
{

 if(Strfind(posdetails,"averageprice"))
  {
   posdetails = StrExtract(posdetails,1,':');
   averageprice = StrTrim(posdetails,"\"");
    _TRACE("Average Price : "+averageprice);
  }



} //end of for loop
}

}//end of for loop



return averageprice;

}

function GetExecutedTime(resp,orderno)
{


exchtime = "";


ordstatus = StrExtract(resp,1,'[');

for( item = 1; ( istatus = StrExtract( ordstatus, item,'{' )) != ""; item++ )
{


if(Strfind(istatus,orderno) AND StrFind(istatus,producttype)) //Matches the symbol and //Matches the Order Type
{

flag = 1; //turn on the flag

for( jitem = 0; ( posdetails = StrExtract( istatus, jitem,',' )) != ""; jitem++ )
{

 if(Strfind(posdetails,"exchorderupdatetime"))
  {
   posdetails = StrExtract(posdetails,1,':');
   exchtime = StrTrim(posdetails,"\"");
    _TRACE("Exchange Order Upate Time : "+exchtime);
  }



} //end of for loop
}

}//end of for loop


return exchtime;
}


function shortstraddlememory(typeoforder,transaction_type,resp1,resp2)
{

orderbookresp = getorderbook();


//Get the Transaction Type, Trading Symbol, OrderNo, AveragePrice, Netqty

legno = 1;
opt_type = "CE";
symbol1 = GetSymbol(resp1);
StaticVarSetText(static_var_options+typeoforder+"Options_symbol"+opt_type+legno,symbol1,True); //Get the Transaction Type

transtype1 = transaction_type;
StaticVarSetText(static_var_options+typeoforder+"Options_transtype"+opt_type+legno,transtype1,True);
orderno1 = GetOrderID(resp1);
StaticVarSetText(static_var_options+typeoforder+"Options_orderno"+opt_type+legno,orderno1,True); 
respOB1 = orderbookresp; //read the data from orderbook
orderstatus1 = GetOrderStatus(respOB1,orderno1);
StaticVarSetText(static_var_options+typeoforder+"Options_orderstatus"+opt_type+legno,orderstatus1,True); 
averageprice1 = GetAveragePrice(respOB1,orderno1);
StaticVarSetText(static_var_options+typeoforder+"Options_averageprice"+opt_type+legno,averageprice1,True); 
executedordertime1 = GetExecutedTime(respOB1,orderno1);
StaticVarSetText(static_var_options+typeoforder+"Options_executedordertime"+opt_type+legno,executedordertime1,True);  
	
	
legno = 2;
opt_type = "PE";
symbol2 = GetSymbol(resp2);
StaticVarSetText(static_var_options+typeoforder+"Options_symbol"+opt_type+legno,symbol2,True); //Get the Transaction Type

transtype2 = transaction_type;
StaticVarSetText(static_var_options+typeoforder+"Options_transtype"+opt_type+legno,transtype2,True);
orderno2 = GetOrderID(resp2);
StaticVarSetText(static_var_options+typeoforder+"Options_orderno"+opt_type+legno,orderno2,True); 
respOB2 = orderbookresp; //read the data from orderbook
orderstatus2 = GetOrderStatus(respOB2,orderno2);
StaticVarSetText(static_var_options+typeoforder+"Options_orderstatus"+opt_type+legno,orderstatus2,True); 
averageprice2 = GetAveragePrice(respOB2,orderno2);
StaticVarSetText(static_var_options+typeoforder+"Options_averageprice"+opt_type+legno,averageprice2,True); 
executedordertime2 = GetExecutedTime(respOB2,orderno2);
StaticVarSetText(static_var_options+typeoforder+"Options_executedordertime"+opt_type+legno,executedordertime2,True);  
	
}


function PlaceOrder(symbol,transtype,SLtag,LimitPrice,Stoplevel)
{

//Create Access to the Bridge
algomojo=CreateObject("AMAMIBRIDGE.Main");



api_data = "{
    
      	\"stgy_name\": \""+stgy_name+"\",
        \"variety\":\""+variety+"\",
        \"tradingsymbol\":\""+symbol+"\",
        \"symboltoken\":\""+symboltoken+"\",
        \"transactiontype\":\""+transtype+"\",
        \"exchange\":\""+exchange+"\",
        \"ordertype\":\""+ordertype+"\",
        \"producttype\":\""+producttype+"\",
        \"duration\":\""+duration+"\",
        \"price\":\""+LimitPrice+"\",
        \"squareoff\":\""+squareoff+"\",
        \"stoploss\":\""+stoploss+"\",
        \"quantity\":\""+quantity+"\",
        \"triggerprice\": \""+Stoplevel+"\",
        \"trailingStopLoss\": \""+trailingStopLoss+"\",
        \"disclosedquantity\":\""+disclosedquantity+"\"
	 
}";

_TRACE("API Request :" + api_data);

//PlaceOrder, Broker, Ver -> Build the endpoint url for the place order functionality
//API data is transmitted with the API Key, API Secret to the end point url
resp = algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceOrder",api_data, broker,ver);
_TRACE("API Response :"+resp);

return resp;

}

function PlaceSLOptionsOrder(symbol,opt_type,legno, averageprice)
{

_TRACE("Place Stoploss Order");


if(stopsenabled=="Enabled")
{
//compute the stoploss

stoplevel = StrToNum(averageprice) * (1+ stoppercentage/100);

//Round of the Stop to nearest tick size 105.06 -> 105.05, Options Tick Size - 0.05

TickSz = 0.05;

stoplevel = TickSz * round(stoplevel/TickSz); //final rounded off to nearest tick size - trigger price
LimitPrice = stoplevel + stoplossslippagebuffer;  //slippage is restricted to 2 points (Slippage Buffer)

resp = PlaceOrder(symbol,"BUY","SL",LimitPrice,Stoplevel);

//place the stoplossorder

	



}

return resp;

}


function PlaceOptionsOrder(transaction_type,opt_type,offset, legno)
{

	algomojo=CreateObject("AMAMIBRIDGE.Main");
    
    api_data =  "{
        \"stgy_name\":\""+stgy_name+"\",
        \"variety\":\"NORMAL\",
        \"spot_sym\":\""+spot_sym+"\",
        \"expiry_dt\":\""+expiry_dt+"\",
        \"opt_type\":\""+opt_type+"\",
        \"transactiontype\":\""+transaction_type+"\",
        \"ordertype\":\""+ordertype+"\",
        \"quantity\":\""+quantity+"\",
        \"price\":\""+price+"\",
        \"triggerprice\":\""+triggerprice+"\",
        \"producttype\":\""+producttype+"\",
        \"strike_int\":\""+strike_interval+"\",
        \"offset\":\""+offset+"\"
      }";
   
    _TRACE("API Request"+api_data);
    resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceFOOptionsOrder",api_data,broker,ver);
    _TRACE("API Response : "+resp);

//Save the Symbol, Orderno, OrderStatus, AveragePrice, ExecutedOrder Time to Internal Memory (Persistant)

    
	
	
    
	
	
	return resp;

}




function cancelorder(Orderno)
{

algomojo=CreateObject("AMAMIBRIDGE.Main");

api_data = "{
	 \"variety\": \""+variety+"\",
	  \"orderid\": \""+OrderNo+"\"
}";

_TRACE("Cancel API Request"+api_data);


resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"CancelOrder",api_data,broker,ver);
_TRACE("Cancel API Response : "+resp);


}


function cancelSLorders()
{

//Cancel both ATM CE/PE SL orders 
//Clearing the Internal memory of ATM CE/PE order details


opt_type = "CE";
legno = 1;
//get the Stoploss OrderID (Call Options)
CEorderid = StaticVarGetText(static_var_options+"SLOptions_orderno"+opt_type+legno);

cancelorder(CEorderid); //cancel pending CE Stoploss Order
removeinternalmemory("SL",opt_type,legno);

opt_type = "PE";
legno = 2;
//get the Stoploss OrderID (Put Options)
PEorderid = StaticVarGetText(static_var_options+"SLOptions_orderno"+opt_type+legno);

cancelorder(PEorderid); //cancel pending CE Stoploss Order
removeinternalmemory("SL",opt_type,legno);

}


function GetPositionsBook()
{
//Creating the Trading Bridge
algomojo=CreateObject("AMAMIBRIDGE.Main");

api_data = "{ }";
_TRACE("PositionBook API Request"+api_data);

//Sending The Broker Request for NetOpenPositions
resp=algomojo.AMDispatcher(user_apikey, api_secretkey,"Positions",api_data,broker,ver);
_TRACE("PositionBook API Response : "+resp);

return resp;

}



function NetOpenPos(ExitSymbol)
{

flag = 0;

resp = GetPositionsBook();

posNetqty ="0";

for( item = 1; ( sym = StrExtract( resp, item,'{' )) != ""; item++ )
{



if(Strfind(sym,ExitSymbol) AND StrFind(sym,productType)) //Matches the symbol and //Matches the Order Type
{

flag = 1; //turn on the flag

for( jitem = 0; ( posdetails = StrExtract( sym, jitem,',' )) != ""; jitem++ )
{

 if(Strfind(posdetails,"tradingsymbol"))
  {
   posdetails = StrExtract(posdetails,1,':');
   possym = StrTrim(posdetails,"\"");
    _TRACE("\nTrading Symbol : "+possym);
  }

  if(Strfind(posdetails,"netqty"))
  {
   posdetails = StrExtract(posdetails,1,':');
   posNetqty = StrTrim(posdetails,"\"");
   _TRACE("\nNetQty : "+posNetqty);
  }
  

} //end of for loop
}

}//end of for loop


if(flag==0)
{
_TRACE("\nTrading Symbol Not Found");
 posNetqty ="0";
_TRACE("\nNetQty : "+posNetqty);
}

return posNetqty;



}



function SquareOffPosition(opt_type,legno)
{
resp ="";
TType = "";
ExitSymbol = StaticVarGetText(static_var_options+"Options_Symbol"+opt_type+legno);

//NetQty if position then only squareoff should happen
Netqty = StrToNum(NetOpenPos(ExitSymbol));

if(StaticVarGetText(static_var_options+"Options_transtype"+opt_type+legno)=="BUY")
{
TType = "SELL";
}

if(StaticVarGetText(static_var_options+"Options_transtype"+opt_type+legno)=="SELL")
{
TType = "BUY";
}

//Create Access to the Bridge
algomojo=CreateObject("AMAMIBRIDGE.Main");

Netqty = 50;

api_data = "{
    
      	\"stgy_name\": \""+stgy_name+"\",
        \"variety\":\""+variety+"\",
        \"tradingsymbol\":\""+ExitSymbol+"\",
        \"symboltoken\":\""+symboltoken+"\",
        \"transactiontype\":\""+TType+"\",
        \"exchange\":\""+exchange+"\",
        \"ordertype\":\""+ordertype+"\",
        \"producttype\":\""+producttype+"\",
        \"duration\":\""+duration+"\",
        \"price\":\""+price+"\",
        \"squareoff\":\""+squareoff+"\",
        \"stoploss\":\""+stoploss+"\",
        \"quantity\":\""+Netqty+"\",
        \"triggerprice\": \""+triggerprice+"\",
        \"trailingStopLoss\": \""+trailingStopLoss+"\",
        \"disclosedquantity\":\""+disclosedquantity+"\"
	 
}";

_TRACE("Squareoff API Request :" + api_data);

//PlaceOrder, Broker, Ver -> Build the endpoint url for the place order functionality
//API data is transmitted with the API Key, API Secret to the end point url
//Testing
//if(Netqty==0 AND ExitSymbol!="")
//Live Trading
if(Netqty!=0 AND ExitSymbol!="")
{
resp = algomojo.AMDispatcher(user_apikey, api_secretkey,"PlaceOrder",api_data, broker,ver);
removeinternalmemory("",opt_type,legno);

}

if(resp!="")
{
_TRACE("Squareoff API Response : "+resp);
}
else
{
_TRACE("Squareoff Order Not Triggered");
}

return resp;

}


_SECTION_BEGIN("Intraday Straddle - Execution Module");

if(EnableAlgo != "Disable")
    {
		//if the time set as per the parameter control is reached
		if(GetSecondNum() == entrytime AND StaticVarGet(static_var_options + entrytime) == 0)
		{
			//send the straddle orders
			StaticVarSet(static_var_options + entrytime,1);
			
			
			resp1 = PlaceOptionsOrder(TransType, "CE", CEoffset,1);
			resp2 = PlaceOptionsOrder(TransType, "PE", PEoffset,2);
			
			shortstraddlememory("",TransType,resp1,resp2);
			
			for(i=0; i<5; i++)  ThreadSleep(100);
			
					
			symbol1 = StaticVarGetText(static_var_options+"Options_Symbol"+"CE"+1);
			symbol2 = StaticVarGetText(static_var_options+"Options_Symbol"+"PE"+2);
			
			averageprice1 = StaticVarGetText(static_var_options+"Options_averageprice"+"CE"+1);
			averageprice2 = StaticVarGetText(static_var_options+"Options_averageprice"+"PE"+2);
			
			SLresp1 = PlaceSLOptionsOrder(symbol1,"CE",1, averageprice1);
			SLresp2 = PlaceSLOptionsOrder(symbol2,"PE",2, averageprice2);
		
			shortstraddlememory("SL","BUY",SLresp1,SLresp2);
			
		}
		//reset the static variable if the otime is not matching
		else if(GetSecondNum() != entrytime)
		{
			StaticVarSet(static_var_options + entrytime,0);
		}
		
		//if the time set as per the parameter control is reached
		if(GetSecondNum() == exittime AND StaticVarGet(static_var_options + exittime) == 0)
		{
			//send the straddle orders
			StaticVarSet(static_var_options + exittime,1);
			cancelSLorders();
			SquareOffPosition("CE",1);
			SquareOffPosition("PE",2);
			
			
			
		
		}
		//reset the static variable if the otime is not matching
		else if(GetSecondNum() != exittime)
		{
			StaticVarSet(static_var_options + exittime,0);
		}
    
    
    
    }//end of Main if loop

SetChartOptions(0, chartShowArrows | chartShowDates); //x-Axis will be plottted
//plot the candles
Plot(Close,"Close",colorDefault,GetPriceStyle() | styleNoTitle);


_SECTION_END();


_SECTION_BEGIN("Algo Dashboard Status");


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);
}
}

_SECTION_END();

How to Setup Intraday Straddle Module?

1)Apply the AFL Code with proper Algomojo API Key and API secret key and Stoploss controls , Set the Entry and Exit time

2)Press Clear Static Variables to clear the temporary memory

3)Temporary Multi Legged Memory Management can be seen at Amibroker -> Window -> Interpretation Box as shown below

Expiry Symbol Format

For AngelOne Account holders weekly and monthly Option Symbol Format: BANKNIFTY02JUN2233500CE

Hence the Expiry Date needs to be entered as 02JUN22

AngelOne- Symbol Format

4)Ensure Log Window is open to capture the Trace Logs

5)Bingo Now you have setup the complete end to end automated straddle/strangle execution. Straddle/Strangle Control can be controlled via offset parameters.

6)Code is designed in such a way that stop loss is placed for individual price legs and not for the combined premium of Straddle/Strangle Spreads

7)Make the Algo Enable and send time-based straddle execution (Supports both entry and exit conditions).

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Algomojo Platform Now Open to Finvasia (Shoonya) Users

Algomojo, a leading Algotrading platform for DIY traders, is excited to announce that it is now open to Finvasia (Shoonya) users. This partnership aims...
Rajandran R
5 min read

Algomojo Platform Now Open to 5Paisa Users

Algomojo, a leading Algotrading platform for DIY traders, is excited to announce that it is now open to 5Paisa users. This partnership aims to...
Rajandran R
5 min read

Algomojo Platform Now Open to Goodwill Commodities Users

Algomojo, a leading Algotrading platform for DIY traders, is excited to announce that it is now open to Goodwill Commodities users. This partnership aims...
Rajandran R
5 min read

2 Replies to “Intraday Straddle Execution Module – Amibroker for AngelOne Users”

Leave a Reply

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