Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Plotting Dynamic Intraday Straddle Charts using Amibroker

4 min read

Recently Intraday Straddle sellers are on the rise and so the questions to us about how to plot intraday straddle spread dynamically during the day. And Build a Historical chart to visualize weekly options / monthly options spread. In this blog you will learn how to create dynamic Intraday Straddle Charts using Amibroker

A short straddle is an options trading strategy where an investor sells both a call option and a put option with the same ATM strike price and expiration date.

Dynamic Intraday Straddle Spread Charts

Requirements

1)Realtime Datafeed with Options Trading Instruments loaded in a Watchlists. Also, make sure that the symbols are loaded into the data manager

In my case, I used Globaldatafeeds for Realtime Option Chartst to build dynamic intraday straddles

Preference Settings

Goto Amibroker -> Tools -> Preferences -> Intraday and uncheck Align minute bars to regular market hours

Amibroker AFL Code to Plot the Underlying with Dynamic ATM Strike Levels

//Coded by Rajandran R - Author - Marketcalls / Creator - OpenAlgo
//website - www.marketcals.in / www.openalgo.in
//Version 1.0.0.0
//Coded Date : 07-Mar-2023

//Symbol Format - NIFTY29JUL2115700CE.NFO     Spot+Expiry+StrikePrice+OptionType(CE/PE).NFO

_SECTION_BEGIN("Dynamic ATM Strike Levels");

SetChartOptions(0, chartShowArrows | chartShowDates); //x-Axis will be plottted
//plot the candles
Plot(Close,"Close",colorDefault,styleCandle | styleNoTitle);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

spot = Paramstr("Spot Symbol","NIFTY");
expiry = ParamStr("Expiry Date","29MAR23");
Symbol = Paramstr("Underlying Symbol","NIFTY-I.NFO");
dynamic = ParamList("Dynamic Straddle","EVERYDAY|EVERYHOUR",0);
iInterval = Param("Strike Interval",50,1,10000,1);
offsetCE = Param("CE Offset",0,-40,40,1);
offsetPE = Param("PE Offset",0,-40,40,1);
dynamic = ParamList("Dynamic Straddle","EVERYDAY|EVERYHOUR",0);


newday = Day()!=Ref(Day(),-1);
newhour = Hour()!=Ref(Hour(),-1);


if(dynamic == "EVERYDAY")
{
Plot( newday, "", colorYellow, styleHistogram | styleOwnScale, 0, 1 );
}
if(dynamic == "EVERYHOUR")
{
Plot( newhour, "", colorYellow, styleHistogram | styleOwnScale, 0, 1 );
}

SetForeign(Symbol);
if(dynamic == "EVERYDAY")
{
Underlying = TimeFrameGetPrice("O",inDaily,0); //Fetch the Todays Open from the daily charts
}
if(dynamic == "EVERYHOUR")
{
Underlying = TimeFrameGetPrice("O",inHourly,0); //Fetch the Todays Open from the hourly charts
}
RestorePriceArrays();

//Maintain Array to Store ATM Strikes for each and every bar
strike = IIf(Underlying % iInterval > iInterval/2, Underlying - (Underlying%iInterval) + iInterval,
			Underlying - (Underlying%iInterval));
			
Plot(strike,"ATM Strike",colorPink,styleDashed);



_SECTION_END();

Amibroker AFL Code to Plot Dynamic Intraday Straddle

//Coded by Rajandran R - Author - Marketcalls / Creator - OpenAlgo
//website - www.marketcals.in / www.openalgo.in
//Version 1.0.0.0
//Coded Date : 07-Mar-2023

//Symbol Format - NIFTY29JUL2115700CE.NFO     Spot+Expiry+StrikePrice+OptionType(CE/PE).NFO

_SECTION_BEGIN("Dynamic Intraday Short Straddle Charts");

EnableTextOutput(False);

spot = Paramstr("Spot Symbol","NIFTY");
expiry = ParamStr("Expiry Date","16MAR23");
Symbol = Paramstr("Underlying Symbol","NIFTY-I.NFO");
dynamic = ParamList("Dynamic Straddle","EVERYDAY|EVERYHOUR",0);
levels = ParamList("Show Levels","SHOW|HIDE",0);
iInterval = Param("Strike Interval",50,1,10000,1);
offsetCE = Param("CE Offset",0,-40,40,1);
offsetPE = Param("PE Offset",0,-40,40,1);
fontsize = Param("Font Size",10,10,40,1);
newday = Day()!=Ref(Day(),-1);
newhour = Hour()!=Ref(Hour(),-1);


if(dynamic == "EVERYDAY")
{
Plot( newday, "", colorYellow, styleHistogram | styleOwnScale, 0, 1 );
}
if(dynamic == "EVERYHOUR")
{
Plot( newhour, "", colorYellow, styleHistogram | styleOwnScale, 0, 1 );
}

SetForeign(Symbol);
if(dynamic == "EVERYDAY")
{
Underlying = TimeFrameGetPrice("O",inDaily,0); //Fetch the Todays Open from the daily charts
}
if(dynamic == "EVERYHOUR")
{
Underlying = TimeFrameGetPrice("O",inHourly,0); //Fetch the Todays Open from the hourly charts
}
RestorePriceArrays();

//Maintain Array to Store ATM Strikes for each and every bar
strike = IIf(Underlying % iInterval > iInterval/2, Underlying - (Underlying%iInterval) + iInterval,
			Underlying - (Underlying%iInterval));
strikeCE = strike + (offsetCE * iInterval);
strikePE = strike - (offsetPE * iInterval);

//Plot(strike,"ATM Strike",colorYellow,styleThick);

//Derives the Symbol Format from the Strike Price
SymbolCE = spot+expiry+strikeCE+"CE.NFO";
SymbolPE = spot+expiry+strikePE+"PE.NFO";

printf("\nDatafeed CE Symbol :"+SymbolCE);
printf("\nDatafeed PE Symbol :"+SymbolPE);

bi = BarIndex();
fvb = FirstVisibleValue(bi);
lvb = LastVisibleValue(bi);

bars = lvb-fvb;
printf("\nBars :"+bars);

for(i=BarCount-bars;i<BarCount;i++)
{
VarSet(spot+expiry+strikeCE[i]+"CE",Foreign(spot+expiry+strikeCE[i]+"CE.NFO","C"));
VarSet(spot+expiry+strikePE[i]+"PE",Foreign(spot+expiry+strikePE[i]+"PE.NFO","C"));
}

leg1close = Null;
leg2close = Null;

for(i=0;i<BarCount;i++)
{
if(i<BarCount-bars)
{
leg1close[i] = Null;
leg2close[i] = Null;
}
else
{

CEClose = VarGet(spot+expiry+strikeCE[i]+"CE");
PEClose = VarGet(spot+expiry+strikePE[i]+"PE");

leg1close[i] = CEClose[i];
leg2close[i] = PEClose[i];
}

combinedpremium[i] = leg1close[i] + leg2close[i];

}


printf("\nCE Premium :"+leg1close);
printf("\nPE Premium :"+leg2close);

Plot(combinedpremium,"Combined Premium",colorred,styleThick);

SetForeign(Symbol);
Usymbol = Close;
RestorePriceArrays();

if(dynamic == "EVERYDAY" AND Levels =="SHOW")
{

for( i = 0; i < BarCount; i++ ) 
 {  
if( newday[i] ) PlotTextSetFont("Underlying : "+Usymbol[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-30);
if( newday[i] ) PlotTextSetFont("CE :"+strikeCE[i]+"\nPE :"+strikeCE[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-50);
if( newday[i] ) PlotTextSetFont("CE Prem :"+leg1close[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-90);
if( newday[i] ) PlotTextSetFont("PE Prem :"+leg2close[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-110);


}

}
if(dynamic == "EVERYHOUR" AND Levels =="SHOW")
{
for( i = 0; i < BarCount; i++ ) 
 {  
if( newhour[i] ) PlotTextSetFont("Underlying : "+Usymbol[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-30);
if( newhour[i] ) PlotTextSetFont("CE : "+strikeCE[i]+"\nPE : "+strikeCE[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-50);
if( newhour[i] ) PlotTextSetFont("CE Prem :"+leg1close[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-90);
if( newhour[i] ) PlotTextSetFont("PE Prem :"+leg2close[i],"Arial", fontsize,i,combinedpremium[i],colorWhite,colorGreen,-110);

}}


SetChartOptions(0, chartShowArrows | chartShowDates); //x-Axis will be plottted
//plot the candles
//Plot(Close,"Close",colorDefault,styleCandle | styleNoTitle);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, 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. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Fisher Transform – Amibroker AFL Code

The Fisher Transform is a technical analysis indicator developed by John F. Ehlers, designed to identify potential turning points in the price movements of...
Rajandran R
2 min read

My Experience Converting SSL Hybrid from PineScript to Amibroker…

As a trader and coding enthusiast, I often find myself needing to translate trading indicators from one programming language to another. Recently, I embarked...
Rajandran R
8 min read

Line Trading – OpenAlgo Automation Module for Amibroker Users

The line Trading Automation tool is designed for Manual traders who want to perform level-based trade execution faster and also bring some advanced trade...
Rajandran R
59 sec read

Leave a Reply

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