Option Button Trading to Trade ATM, ITM, OTM Options – Amibroker AFL Code

Here is a simple button trading module that can be used to send option trading orders with buttons. Users can configure the button to send ATM, ITM, OTM Options, and with one touch one will be able to send small/large options orders in a split second. Entry Order and Exit order buttons are provided to users.

Supported Brokers: All Algomojo Supported Brokers
AlgoPlatform : Algomojo
Supported Amibroker Version : 6.22 or above

ButtonsType
Long CE EntryEntry Order
Long CE ExitExit Order
Long PE EntryEntry Order
Long PE ExitExit Order
Short CE EntryEntry Order
Short CE ExitExit Order
Short PE EntryEntry Order
Short PE ExitExit Order

Button Offset Parameter Controls in Amibroker

Option TypeOffset
ATM0
OTMPositive Value
ITMNegative Value

Execution Logic for Placing Options Order

Execution Logic for Exiting Options Order

Setting up the Options Button Trading AFL File

1)Save the AFL file under the name Algomojo Options Button Trading.afl under Amibroker/formulas/Algomojo folder. Create Algomojo Folder if it doesn’t exist.

/*
Created By : Algomojo
Created on : 09 Feb 2023
Website : www.algomojo.com
*/

_SECTION_BEGIN("Algomojo - Options Button Trading Module");
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();



_SECTION_BEGIN("Amibroker Version Check");

RequestTimedRefresh(1,False);

Version(6.22);

//Static Variables will be saved in Amibroker every 30 seconds once
SetOption("StaticVarAutoSave",60);

// Send orders even if Amibroker is minimized or Chart is not active
RequestTimedRefresh(1, False); 
EnableTextOutput(False);

_SECTION_END();


_SECTION_BEGIN("Algomojo Options Controls");


// Send orders even if Amibroker is minimized or Chart is not active
RequestTimedRefresh(1, False); 

broker =Paramlist("Broker","an|ab|fp|fs|fy|gc|pt|sm|tc|up|zb|ze",0);;
ver = "v1";

//input controls
apikey = Paramstr("ApiKey","xxxxxxxxxxxxxxxxx");
apisecret = Paramstr("ApiSecret","xxxxxxxxxxxxxxxxx");
strategy = ParamStr("Strategy Name","Options Strategy");
product = ParamList("product","NRML|MIS",0);
pricetype = ParamList("pricetype","MARKET",0); 
price = 0;
triggerprice = 0;
exchange = ParamList("Exchange","NFO",0); 
splitorder = ParamList("Split Order","NO|YES");
split_quantity = Param("Split Quantity",1,1,5000,1);


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



clear = ParamTrigger("Clear Static Variables","Clear");
static_var_options = "staticvar_options"+Name()+Interval(2)+GetChartID() + strategy;

if(clear)
{

StaticVarRemove(static_var_options+"*");
_TRACE("Static Variables Cleared");
}

function removeinteralmemory(opt_type,legno)
{
StaticVarRemove(static_var_options+"Options_Trans"+opt_type+legno);
StaticVarRemove(static_var_options+"Options_OrderNo"+opt_type+legno);
StaticVarRemove(static_var_options+"Options_Symbol"+opt_type+legno);
StaticVarRemove(static_var_options+"Options_OrderStatus"+opt_type+legno);
StaticVarRemove(static_var_options+"Options_NetQty"+opt_type+legno);

}

//Internal Memory
opt_type="CE";
legno = 1;
printf("\n---------------Leg 1 Long CE Orders Internal Memory----------");
printf("\nOrderType : "+StaticVarGetText(static_var_options+"Options_Trans"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"Options_OrderNo"+opt_type+legno));
printf("\nSymbol : "+StaticVarGetText(static_var_options+"Options_Symbol"+opt_type+legno));
printf("\nStatus : "+StaticVarGetText(static_var_options+"Options_OrderStatus"+opt_type+legno));
printf("\nNetQty : "+StaticVarGetText(static_var_options+"Options_NetQty"+opt_type+legno));


opt_type="PE";
legno = 2;
printf("\n---------------Leg 2 Long PE Orders Internal Memory----------");
printf("\nOrderType : "+StaticVarGetText(static_var_options+"Options_Trans"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"Options_OrderNo"+opt_type+legno));
printf("\nSymbol : "+StaticVarGetText(static_var_options+"Options_Symbol"+opt_type+legno));
printf("\nStatus : "+StaticVarGetText(static_var_options+"Options_OrderStatus"+opt_type+legno));
printf("\nNetQty : "+StaticVarGetText(static_var_options+"Options_NetQty"+opt_type+legno));



opt_type="CE";
legno = 3;
printf("\n---------------Leg 3 Short CE Orders Internal Memory----------");
printf("\nOrderType : "+StaticVarGetText(static_var_options+"Options_Trans"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"Options_OrderNo"+opt_type+legno));
printf("\nSymbol : "+StaticVarGetText(static_var_options+"Options_Symbol"+opt_type+legno));
printf("\nStatus : "+StaticVarGetText(static_var_options+"Options_OrderStatus"+opt_type+legno));
printf("\nNetQty : "+StaticVarGetText(static_var_options+"Options_NetQty"+opt_type+legno));


opt_type="PE";
legno = 4;
printf("\n---------------Leg 4 Short PE Orders Internal Memory----------");
printf("\nOrderType : "+StaticVarGetText(static_var_options+"Options_Trans"+opt_type+legno));
printf("\nOrderNo : "+StaticVarGetText(static_var_options+"Options_OrderNo"+opt_type+legno));
printf("\nSymbol : "+StaticVarGetText(static_var_options+"Options_Symbol"+opt_type+legno));
printf("\nStatus : "+StaticVarGetText(static_var_options+"Options_OrderStatus"+opt_type+legno));
printf("\nNetQty : "+StaticVarGetText(static_var_options+"Options_NetQty"+opt_type+legno));





function getorderno(resp)
{

orderno = "";


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

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

return orderno;

}


function GetSymbol(resp)
{

tradingsymbol = "";


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

_TRACE("Trading Symbol is : "+tradingsymbol);

return tradingsymbol;

}

function GetOrderStatus(order_id)
{

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

api_data = "{ \"broker\": \""+broker+"\",
            \"order_id\":\""+order_id+"\" }";
_TRACE("OpenPositions API Request"+api_data);

//Sending The Broker Request for NetOpenPositions
resp=algomojo.AMDispatcher(apikey,apisecret,"OrderStatus",api_data,"am",ver);

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

_TRACE("Order Status : "+orderstatus);
for(i=0; i<5; i++)  ThreadSleep(100);
return orderstatus;

}


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

api_data = "{ \"broker\": \""+broker+"\",
            \"symbol\":\""+TSymbol+"\",
            \"product\":\""+product+"\"
            }";
_TRACE("OpenPositions API Request"+api_data);

//Sending The Broker Request for NetOpenPositions
resp=algomojo.AMDispatcher(apikey,apisecret,"OpenPositions",api_data,"am",ver);
_TRACE("OpenPositions API Response : "+resp);
for(i=0; i<5; i++)  ThreadSleep(100);
return resp;

}

function NetOpenPositions(TSymbol)
{
flag = 0;

resp = OpenPositions(TSymbol);

posNetqty =0;

sym = StrExtract( resp, 2,'{' );
//_TRACE("Symbol Extract"+sym);

if( sym != "")
{

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

  if(Strfind(posdetails,"netqty"))
  {
   
   flag = 1; //turn on the flag
   posdetails = StrExtract(posdetails,1,':');
   posNetqty = StrToNum(StrTrim(posdetails,"\""));
   
  }
  

} //end of for loop


} //end of if loop



return posNetqty;

}



//placeoptionorder(1,spot,expiry,iInterval,btn12_qty,"B","CE",offset_btn12); 

function PlaceOptionsOrder(legno,spot_symbol,expiry_date,strike_int,quantity,action, opt_type, offset)
{

if(opt_type=="PE")
{
offset = -offset;  //changing the polarity
}


//create the Trading Bridge
algomojo = CreateObject("AMAMIBRIDGE.Main");  //calling the bridge dll

//Prepart the API data

api_data =  "{
        \"broker\":\""+broker+"\",
        \"strategy\":\""+strategy+"\",
        \"spot_symbol\":\""+spot_symbol+"\",
        \"expiry_date\":\""+expiry_date+"\",
        \"action\":\""+action+"\",
        \"product\":\""+product+"\",
        \"pricetype\":\""+pricetype+"\",
        \"quantity\":\""+quantity+"\",
        \"price\":\"0\",
        \"triggerprice\":\"0\",
        \"option_type\":\""+opt_type+"\",
        \"strike_int\":\""+strike_int+"\",
        \"offset\":\""+offset+"\",
        \"splitorder\":\""+splitorder+"\",
        \"split_quantity\":\""+split_quantity+"\"
        }";

_TRACE("Broker API Request"+api_data);

resp = algomojo.AMDispatcher(apikey,apisecret,"PlaceFOOptionsOrder",api_data,"am",ver);

_TRACE("Broker API Respone"+resp);

//Store the Transaction Type, OrderNo,Trading Symbol,OrderStatus,Netqty

Trans = action;
StaticVarSetText(static_var_options+"Options_Trans"+opt_type+legno,Trans,True); 
OrderNo = GetOrderNo(resp);
StaticVarSetText(static_var_options+"Options_OrderNo"+opt_type+legno,OrderNo,True);
Symbol = GetSymbol(resp);
StaticVarSetText(static_var_options+"Options_Symbol"+opt_type+legno,Symbol,True);
Orderstatus = GetOrderStatus(OrderNo);  //Get the Orderstatus from OrderHistory
StaticVarSetText(static_var_options+"Options_OrderStatus"+opt_type+legno,Orderstatus,True);
NetQty = NumToStr(NetOpenPositions(Symbol),1);  //Get the Netqty from the Positions Book
StaticVarSetText(static_var_options+"Options_NetQty"+opt_type+legno,NetQty,True);

if(VoiceAlert == "Enable")
	Say( "Order Placed" );

return resp;
}


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

if(ExitSymbol!="")
{

Netqty = NetOpenPositions(ExitSymbol);

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

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



//Creating the Trading Bridge
algomojo=CreateObject("AMAMIBRIDGE.Main");
//Preparing the API data

amo = "NO";
trigger_price = "0";

api_data = "{ \"broker\": \""+broker+"\",
            \"strategy\":\""+strategy+"\",
            \"exchange\":\""+exchange+"\",
            \"symbol\":\""+ExitSymbol+"\",
            \"action\":\""+TType+"\",
            \"product\":\""+product+"\",
            \"pricetype\":\""+pricetype+"\",
            \"quantity\":\""+abs(Netqty)+"\",
            \"price\":\""+price+"\",      
            \"disclosed_quantity\":\""+"0"+"\",
            \"trigger_price\":\""+trigger_price+"\",
            \"amo\":\""+amo+"\",
            \"splitorder\":\""+splitorder+"\",
            \"split_quantity\":\""+split_quantity+"\"  }"; 
            


_TRACE("Squareoff API Request"+api_data);
//Testing
//if(Netqty==0 AND ExitSymbol!="")
//Live Trading
if(Netqty!=0 AND ExitSymbol!="")
{
resp=algomojo.AMDispatcher(apikey, apisecret,"PlaceOrder",api_data,"am",ver);
	
}


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

if(VoiceAlert == "Enable")
	Say( "Order Placed" );

return resp;

}


_SECTION_END();




_SECTION_BEGIN("Button Controls");


//Default strike is ATM, Positve Offset = OTM, Negative Offset = ITM -> AFL Side
spot = Paramlist("spot_symbol","NIFTY|BANKNIFTY|FINNIFTY",0);
expiry = ParamStr("Expiry Date","23FEB23");
iInterval= Param("Strike Interval",50,1,5000,1);
lotsize= Param("Lot Size",50,1,5000,1);
quantity = Param("Quantity in Lot Size",1,1,100000,1)*lotsize;

//Long CE Entry and Exit Button Controls
btn12_qty = Param("Long CE Qty",50,0,10000,1);
offset_btn12 = Param("Long CE Offset",0,-20,20,1);  
optiontype12 = WriteIf(offset_btn12 == 0, "ATM", WriteIf(offset_btn12<0,"ITM","OTM"));
btn1_name = optiontype12+"-"+abs(offset_btn12)+" Long CE Entry "+btn12_qty+" shares";
btn2_name = optiontype12+"-"+abs(offset_btn12)+" Long CE Exit "+btn12_qty+" shares";

btn34_qty = Param("Long PE Qty",50,0,10000,1);
offset_btn34 = Param("Long PE Offset",0,-20,20,1);  
optiontype34 = WriteIf(offset_btn34 == 0, "ATM", WriteIf(offset_btn34<0,"ITM","OTM"));
btn3_name = optiontype34+"-"+abs(offset_btn34)+" Long PE Entry "+btn34_qty+" shares";
btn4_name = optiontype34+"-"+abs(offset_btn34)+" Long PE Exit "+btn34_qty+" shares";

btn56_qty = Param("Short CE Qty",50,0,10000,1);
offset_btn56 = Param("Short CE Offset",0,-20,20,1);  
optiontype56 = WriteIf(offset_btn56 == 0, "ATM", WriteIf(offset_btn56<0,"ITM","OTM"));

btn5_name = optiontype56+"-"+abs(offset_btn56)+" Short CE Entry "+btn56_qty+" shares";
btn6_name = optiontype56+"-"+abs(offset_btn56)+" Long CE Exit "+btn56_qty+" shares";

btn78_qty = Param("Short PE Qty",50,0,10000,1);
offset_btn78 = Param("Short PE Offset",0,-20,20,1); 
optiontype78 = WriteIf(offset_btn78 == 0, "ATM", WriteIf(offset_btn78<0,"ITM","OTM")); 
btn7_name = optiontype78+"-"+abs(offset_btn78)+" Shortong PE Entry "+btn78_qty+" shares";
btn8_name = optiontype78+"-"+abs(offset_btn78)+" Short PE Exit "+btn78_qty+" shares";

_SECTION_END();



_SECTION_BEGIN("Algo Dashboard");


static_name_ = Name()+GetChartID()+interval(2)+strategy;
static_name_algo = Name()+GetChartID()+interval(2)+strategy+"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");
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);
}
}

_SECTION_END();



_SECTION_BEGIN("Algomojo Button GUI Creation and Event Handling");

resp = "";





function CreateGUI( 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 = 1;
	return result;
	
}


function HandleEvents()
{

	result = 0;
	id = GuiGetEvent( 0, 0 );// receiving button id
	event = GuiGetEvent( 0, 1 );// receiving notifyflag
	clickevent = event == 1;
	
	
	
	
	
	LongCEEntry = id == 1 && clickevent;
	LongCEExit = id == 2 && clickevent;
	LongPEEntry = id == 3 && clickevent;
	LongPEExit = id == 4 && clickevent;
	ShortCEEntry = id == 5 && clickevent;
	ShortCEExit = id == 6 && clickevent;
	ShortPEEntry = id == 7 && clickevent;
	ShortPEExit = id == 8 && clickevent;
	
	
	
	result = 0;
	
	
	if(EnableAlgo == "Enable")
	{
	
	if( LongCEEntry AND StaticVarGet(Name()+GetChartID()+"LongCEEntry")==0 ) 
	{
		_TRACE("Call Long Entry");
		orderresponse = PlaceOptionsOrder(1,spot,expiry,iInterval,btn12_qty,"BUY","CE",offset_btn12); 
		result = 1;
		StaticVarSet(Name()+GetChartID()+"LongCEEntry",1); 
	}
	else
	{
		
		StaticVarSet(Name()+GetChartID()+"LongCEEntry",0);
	}
	
	if( LongCEExit AND StaticVarGet(Name()+GetChartID()+"LongCEExit")==0 ) 
	{
		_TRACE("Call Long Exit");
		sqoffstatus = SquareOffPosition(1,"CE");
		result = 1;
		StaticVarSet(Name()+GetChartID()+"LongCEExit",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"LongCEExit",0);
	}
	
	if( LongPEEntry AND StaticVarGet(Name()+GetChartID()+"LongPEEntry")==0 ) 
	{
		_TRACE("Put Long Entry");
		orderresponse = PlaceOptionsOrder(2,spot,expiry,iInterval,btn34_qty,"BUY","PE",offset_btn34); 
		result = 1;
		StaticVarSet(Name()+GetChartID()+"LongPEEntry",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"LongPEEntry",0);
	}
	
	if( LongPEExit AND StaticVarGet(Name()+GetChartID()+"LongPEExit")==0 ) 
	{
		_TRACE("Put Long Exit");
		sqoffstatus = SquareOffPosition(2,"PE");
		result = 1;
		StaticVarSet(Name()+GetChartID()+"LongPEExit",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"LongPEExit",0);
	}
	
	if( ShortCEEntry AND StaticVarGet(Name()+GetChartID()+"ShortCEEntry")==0 ) 
	{
		_TRACE("Call Short Entry");
		orderresponse = PlaceOptionsOrder(3,spot,expiry,iInterval,btn56_qty,"SELL","CE",offset_btn56); 
		result = 1;
		StaticVarSet(Name()+GetChartID()+"ShortCEEntry",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"ShortCEEntry",0);
	}
	
	if( ShortCEExit AND StaticVarGet(Name()+GetChartID()+"ShortCEExit")==0 ) 
	{
		_TRACE("Call Short Exit");
		sqoffstatus = SquareOffPosition(3,"CE");
		result = 1;
		StaticVarSet(Name()+GetChartID()+"ShortCEExit",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"ShortCEExit",0);
	}
	
	if( ShortPEEntry AND StaticVarGet(Name()+GetChartID()+"ShortPEEntry")==0 ) 
	{
		_TRACE("Put Short Entry");
		
		orderresponse = PlaceOptionsOrder(4,spot,expiry,iInterval,btn78_qty,"SELL","PE",offset_btn78); 
		result = 1;
		StaticVarSet(Name()+GetChartID()+"ShortPEEntry",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"ShortPEEntry",0);
	}
	
	if( ShortPEExit AND StaticVarGet(Name()+GetChartID()+"ShortPEExit")==0 ) 
	{
		_TRACE("Put Short Exit");
		sqoffstatus = SquareOffPosition(4,"PE");
		result = 1;
		StaticVarSet(Name()+GetChartID()+"ShortPEExit",1); 
	}
	else
	{
		StaticVarSet(Name()+GetChartID()+"ShortPEExit",0);
	}
	}
	
	
	return result;  //result = 1 - order is successfully placed, 0 - Algotrading is in disabled state or orders are not went through
	


}

	
	LongCEEntry = CreateGUI( btn1_name, 20, 100, 300, 30 );
	LongCEExit = CreateGUI( btn2_name, 300, 100, 300, 30 );
	
	LongPEEntry = CreateGUI( btn3_name, 20, 150, 300, 30 );
	LongPEExit = CreateGUI( btn4_name, 300, 150, 300, 30 );
	
	ShortCEEntry = CreateGUI( btn5_name, 20, 200, 300, 30 );
	ShortCEExit = CreateGUI( btn6_name, 300, 200, 300, 30 );
	
	ShortPEEntry = CreateGUI( btn7_name, 20, 250, 300, 30 );
	ShortPEExit = CreateGUI( btn8_name, 300, 250, 300, 30 );
	
	handleevents();
	
	
	
	GuiSetColors( 1, 2, 2, colorGreen, colorBlack, colorGreen, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 
	GuiSetColors( 3, 4, 2, colorred, colorBlack, colorRed, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 


	GuiSetColors( 5, 6, 2, colorBlue, colorBlack, colorBlue, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 
	GuiSetColors( 7, 8, 2, colorLavender, colorBlack, colorLavender, colorWhite, colorBlue, colorYellow, colorRed, colorBlack, colorYellow ); 

_SECTION_END();

_SECTION_BEGIN("Price");

SetChartOptions(0, chartShowArrows | chartShowDates); //x-Axis will be plottted
_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 the candles
Plot(Close,"Close",colorDefault,GetPriceStyle() | styleNoTitle);

_SECTION_END();

Now Drag and Drop the Algomojo Options Button Trading to the new blank charts. Configure the API Key, API Secret Key, Broker Name, Spot, Expiry Date, Strike Interval, and the Button Controls, Offset and Quantity.

What are the Internal Memory Tracks?

Internal Memory tracks the OrderType, OrderNo, Traded Symbol, Order Status, and Net Quantity. Any fresh entry orders will create internal memory and exiting the positions will automatically erase the internal memory. The Internal Memory is persistently saved every 30 seconds means even if the Amibroker is closed and reopened the internal memory is restored with the help of persistent static variables.

Managing the Internal Memory

Press Clear Static Variables to Reset the Internal Memory if in case you want to start fresh and there are no open positions for the current button trading module.

Bingo! Now with the press of the button you will be able to place options orders automatically.

3 thoughts on “Option Button Trading to Trade ATM, ITM, OTM Options – Amibroker AFL Code”

  1. Option Button Trading to Trade ATM, ITM, OTM Options – Amibroker AFL Code
    Can it be comapitable with 6.2.1

Leave a Comment

Your email address will not be published. Required fields are marked *