How to plot dynamic ATM option Straddle Chart

Hi all,
I am trying to create dynamic ATM Option straddle chart. Here "dynamic" word means that straddle chart should be self sustaining and change it's strike with changing underlying.
I have coded the logic, it's not dynamic though. the below code plots the Straddle chart based on the last ATM strike value. If i click somewhere else on the chart straddle chart fetches the ATM strike value based on the underlying value at that time.
Ideally the Straddle chart should not change it's value with different time selection.

_SECTION_BEGIN("DynamicStraddle");

SelectIndex="BANKNIFTY";
ExpiryDate="19";
ExpiryMonth="NOV";
ExpiryYear="20";

dn = DateNum();
newDay = dn != Ref(dn,-1);
Plot( newday, "", colorGrey40, styleHistogram|styleDashed|styleOwnScale|styleNoRescale,0,1);

if (SelectIndex=="NIFTY"){
	IndexMultiplier=50;
	SpotScript="NIFTY 50.NSE_IDX";
}
else {
	IndexMultiplier=100;
	SpotScript="NIFTY BANK.NSE_IDX";
}

Script=SelectIndex+ExpiryDate+ExpiryMonth+ExpiryYear;

SetForeign(SpotScript);	
Spot=(C);


if (SelectIndex=="NIFTY"){
mod=Spot%IndexMultiplier;
if(mod>=25)
Indexround=Spot+IndexMultiplier-mod;
else
Indexround=Spot-mod;
}
else{
Indexround=round(Spot/IndexMultiplier)*100;}
RestorePriceArrays();

Strike=Indexround;
string1=script+Strike+"CE.NFO";
string2=script+Strike+"PE.NFO";

SetForeign(string1); CEc=C; RestorePriceArrays();
SetForeign(string2); PEc=C; RestorePriceArrays();

Straddle= CEc+PEc;
Title=EncodeColor(colorWhite)+Date()+" Combo: "+ Straddle +"\n"+
	  EncodeColor(colorGreen)+ string1 + " : "+ CEc +"\n"+
	  EncodeColor(colorRed)+ string2 + " : "+ PEc ;
Plot( Straddle, "Straddle("+Strike+")", colorYellow, styleLine);
		
_SECTION_END();```

This line here is probably getting Close prices at the selected index when you are clicking.
For the problem you describe, if you just want to use the latest value,
Do

Spot = LastValue( C );

And instead of SetForeign(), consider using the Foreign() single call if its just for "C".

With usage of Spot=(C); i am trying to capture the array values of index closing at varied times.
And, Single SetForeign call is equivalent to multiple Foreign calls. Check out here

The chart looks something like below.
image

Yes, agreed. SetForeign call is equivalent to multiple Foreign calls, but you are making only one Foreign() call of C price per symbol, so why use SetForeign() + RestorePrice, when you can use one Foreign() call that returns the close price per option symbol.
You are not using all 6 or even 3-4 like OHLCV and OI

And regarding your query, i think i got what you are saying.
But for that, you will need to access multiple ATM strikes in each 100pt movement and refer that to create a single array of ATM price.
You'll have to loop over the spot for that.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.