Australian (ASX) Stock Market Forum

Probability Cone in AmiBroker

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.

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:

c3d8e4d4b07d7d5bc0919bfcefadae39d3515aae.jpg
Heartedly appreciate your help. Cheers !
 
Sorry for replying late, I was engrossed studying the cone. Out of all, Tomasz has actually pointed out an error in the calculation of the Projection band - it's a great help from Milosz but the other mathematical part needs to be further worked. So, the technique to plot the cone beyond the last visible bar will remain same but as of now the calculation of the levels are not accurate the way an Option's black box would plot and there lies the fun where a discovery awaits - not Holy Grail but effective range forecasting.
 
Top