Hello,
Starting from this forum code I like to make my own version with a couple of changes :
https://forum.amibroker.com/t/probability-cone/8110/15
Main thing i can't resolve is to anchor the Cone on the Chart. Now when i click on whatever place, the cone is moved to a new bar, So I need it stay anchored at the original position I choosed on the graph.
// Probability Cone 01
// https://forum.amibroker.com/t/probability-cone/8110/15
_SECTION_BEGIN( "Probability Cone" );
// By Lennon
// Modified and expanded by Milosz Mazurkiewicz
/// @link https://forum.amibroker.com/t/probability-cone/8110/15
PF = ParamField( "Price Field", 3 );
CF = ParamToggle( "Choice Field Hi-Lo", "Field|H-L", 0 );
Vol = Param( "Assumed Volatility", 0.1, 0.01, 5, 0.01 ); //(ideally based on volTyp)
FutureBars = Param( "Number of days ahead", 30, 1, 252 );
StdPer = Param( "Standard Deviation", 2, 1, 5, 0.1 );
DE = Param("Days to expiry", 22, 0, 150, 1);
// ****** NEW --> Here is my problem ***********
Displacement = ParamToggle( "Displacement", "No|Yes", 1 );
SetChartOptions( 0, chartShowArrows | chartShowDates, chartGridMiddle, 0, 0, FutureBars );
bi = BarIndex();
Point = SelectedValue(bi); // LastValue( bi ); // Point = SelectedValue(bi);
LVB = status( "lastvisiblebar" );
PF = PF[Point];
StMatrix = Matrix( 2, FutureBars );
for( i = 0; i < FutureBars; i++ )
{
StdDev = StdPer * PF * Vol * sqrt( i / 365 ) ;
if( CF )
{
StMatrix[0][i] = H[ Point ] + stdDev;
StMatrix[1][i] = L[ Point ] - stdDev;
}
else
{
StMatrix[0][i] = PF + stdDev;
StMatrix[1][i] = PF - stdDev;
}
}
GfxSetCoordsMode( 1 );
GfxMoveTo( Point, PF[Point] );
GfxSelectFont( "ArialNarrow", 7, 400 );
ColorUp = ColorBlend( colorbrightGreen, colorWhite, 0.9 );
ColorDown = ColorBlend( colorSkyblue, colorWhite, 0.2 );
for( i = 0; i < FutureBars; i++ )
{
y1 = StMatrix[0][i];
y2 = StMatrix[1][i];
GfxSelectPen( colorGreen, 2 );
GfxSelectSolidBrush( colorGreen );
GfxLineTo( Point + i, y1 );
GfxCircle( Point + i, y1, -2 );
if( i % 2 == 0 and i != 0 ) PlotTextSetFont( "" + Prec( y1, 2 ), "Arial Narrow", 8, Point + i, y1, colorBlack, ColorUp, 20 );
if (i == DE) GfxSelectPen( colorOrange, 2 );
else GfxSelectPen( colorLightGrey, 1 );
GfxLineTo( Point + i, y2 );
if( i % 2 == 0 AND i != 0 ) PlotText( "" + Prec( y2, 2 ), Point + i, y2, colorBlack, ColorDown, -20 );
GfxSelectSolidBrush( colorRed );
GfxSelectPen( colorRed, 2 );
GfxCircle( Point + i, y2, -2 );
GfxLineTo( Max( Point + i - 1, Point ), StMatrix[1][Max( i - 1, 0 )] );
GfxMoveTo( Point + i, y1 );
if( i > LVB - Point ) break;
}
GfxSelectPen( colorGold, 2 );
GfxMoveTo( Point, PF[Point] );
GfxLineTo( Point + i - 1, PF[Point] );
Plot( C, "", colorDefault, styleCandle );
_SECTION_END();
Best regards,
Carlos