Let's say an Option expires at a future date (on a candle yet to form beyond the Barcount - 1
) for which there is no Quote yet and I want to visualize the probable range of the security assuming constant volatility as per the selected bar. Below is an attempt which obviously throws Error 10: Array subscript out of range
whenever a bar is selected that provoke the lines to be plotted beyond Barcount - 1
.
_SECTION_BEGIN( "Probability Cone" );
SetChartOptions( 0, chartShowDates );
PrcFld = ParamField( "Price Field", 3 );
chPrcFld = ParamToggle( "Choice Field Hi-Lo", "Field|H-L", 0 );
//volTyp = ParamList( "Vol. Type", "GARCH|VIX|IV", 2 );
vol = 0.10; //Assumed Volatility (ideally based on volTyp)
intrvl = Param( "No. of days ahead", 5, 1, 252 );
stdPer = Param( "Std. Dev.", 2, 1, 5, 0.5 );
bi = SelectedValue( BarIndex() );
stdDev = Null;
u = Null;
d = Null;
ctr = 0;
if( ( bi + intrvl ) <= Status( "lastvisiblebar" ) )
{
for( i = bi; i <= bi + intrvl; i++ )
{
stdDev[ i ] = stdPer * ( PrcFld[ bi ] * vol[ bi ] * sqrt( ctr / 365 ) );
if( chPrcFld )
{
u[ i ] = H[ bi ] + stdDev[ i ];
d[ i ] = L[ bi ] - stdDev[ i ];
}
else
{
u[ i ] = PrcFld[ bi ] + stdDev[ i ];
d[ i ] = PrcFld[ bi ] - stdDev[ i ];
}
ctr++;
}
}
Plot( C, "", colorDefault, styleCandle );
Plot( u, "", colorBlue, styleLine | styleNoLabel | styleNoRescale, Null, Null, 0, 1, 2 );
Plot( d, "", colorYellow, styleLine | styleNoLabel | styleNoRescale, Null, Null, 0, 1, 2 );
//PlotText( NumToStr( u[ bi + intrvl ], 1.2 ), bi + intrvl + 2, u[ bi + intrvl ], colorBlue );
//PlotText( NumToStr( d[ bi + intrvl ], 1.2 ), bi + intrvl + 2, d[ bi + intrvl ], colorYellow );
Title = "{{DATE}} C " + C;
_SECTION_END();
Is there a solution for this?
Thank you!