- Joined
- 16 September 2018
- Posts
- 2
- Reactions
- 2
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.
How do you identify and plot on a future date? And is my StdDev calculation correct? How to Lookup for a BarIndex at a future DateTime? Something like below:
Heartedly appreciate your help. Cheers !
Code:
_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++;
}
}
else
{
//Not able to think !!!
}
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();
How do you identify and plot on a future date? And is my StdDev calculation correct? How to Lookup for a BarIndex at a future DateTime? Something like below:
Heartedly appreciate your help. Cheers !