Probability Cone in AmiBroker

Warm Greetings to AFL experts,

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.

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

The challenge that I am attempting to apprehend is to pinpoint (Lookup for) the expiration date ahead of the end of arrays. How do I find the number of bars between a future expiration date (for which a candle is yet to form) and a selected bar?

Please suggest an approach on how to achieve the below:
upload_2018-9-20_11-32-20.png


Thank you !
 
Next 3rd Friday function out of MultiCharts - maybe you can glean something fro it.

inputs:
Series( numericsimple ) ;

variables:
var0( 0 ),
var1( 0 ),
var2( 0 ),
var3( 0 ),
var4( 0 ),
var5( 0 ),
var6( 0 ),
var7( 0 ),
var8( 0 ),
var9( 0 ),
var10( 0 ) ;



var0 = DayOfMonth( Date ) ;
var1 = Month( Date ) ;
var2 = Year( Date ) ;

var3 = DayOfWeek( var2 * 10000 + var1 * 100 + 1 ) ;
if var3 < 6 then
var4 = 6 - var3
else
var4 = 7 ;

var5 = var4 + 14 ;
if var5 > var0 then
var7 = var1 + Series - 1
else
var7 = var1 + Series ;

if var7 > 12 then
begin
var7 = var7 - 12 ;
var8 = var2 + 1 ;
end
else
var8 = var2 ;

var3 = DayOfWeek( var8 * 10000 + var7 * 100 + 1 ) ;
if var3 < 6 then
var4 = 6 - var3
else if var3 = 6 then
var4 = 7 ;
var6 = var4 + 14 ;
var9 = DateToJulian( var8 * 10000 + var7 * 100 + var6 ) ;
var10 = DateToJulian( Date ) ;
Next3rdFriday = var9 - var10 ;
 
The dilemma that I am trying to solve in Amibroker is how do I correct:
Code:
dt = DateTime();
lastbar = BarCount - 1;

_TRACEF( "Next to lastbar Datetime: %0.0f", dt[ lastbar + 1 ] );

So basically I am wondering to figure out a way in AFL in order to get hold of these dates of future bars on which a candle is yet to form?

efe784466eea2f97b9e4421ef7bfc630e50cd395.gif


Thank you!
 
Go to forum.amibroker.com. That's where the Amibroker experts hang out. And if they don't answer then Tomasz (creator of Amibroker) steps in and makes everyone feel stupid for how simple he makes it look.
 
Back
Top