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();```