Hello @patryk
yes it is related. Now is NOT fixed to a limit to number 6 any more
nIndex = Nz( StaticVarGet( "riEXT" ), 1); //was fixed to nIndex = 6 ( is the Num of the loop )
Now nIndex is controlled from the line 119 StaticVarSet( "riEXT", riEXT+1 ); // add plus +1 to RangeIndex Counter
As for the chart timing is very good for local or intraday database we use GFX function
I also add a SAFE combination of 3 buttons to Remove ONLY From this indicator and symbol
Any way to calculate 3 or more points there are many ways in the afl. and there is on example By @Kuba here that using matrix if you interest to store your values.
/** @link https://forum.amibroker.com/t/ichimoku-wave-range/24923/10
"Drawing Multiple Fibonacci Extention"
By Panos 08-04-2021
how to use the mouse clicks:
1. first press the GuiCheckBox
2. Second press the "Extention" guibutton then click on the chart the three points
3. By pressing the Ctlr on keyboard you can delete a single line
4. Extra Button added with comfirmation to delete or not
to understand how the staticVars are working i wrote like a debugger, please Open interpretation window to read
*/
_SECTION_BEGIN( "Drawing Multiple Fibonacci Extention" );
Title = " Fibonacci Extention version 2 Template ";
Version(6.28);
// #include <AFLRevisionInclude3.afl>
Plot( C, "Price", colorDefault, stylebar );
bi = BarIndex();
symbol = Name();
tframe = Interval();
chartID = symbol + tframe + GetChartID();
b = GetCursorMouseButtons();
// Delete specific range index, press Ctrl and then DoubleClick ON the Circle
if( GetAsyncKeyState( 17 ) < 0 ) { RequestMouseMoveRefresh(); GfxCircle( GetCursorXPosition(1), GetCursorYPosition(1), 5 ); }
function RemoveOneRangeIndex( ButtonID, CheckID , SVx, SVy )
{
global y0, x0;
if( GetAsyncKeyState( 17 ) < 0 )
if( GuiGetCheck( ButtonID ) == 0 AND GuiGetCheck( CheckID ) == 1 ) // Allowed to Delete Only if range button is OFF
{
y= GetCursorYPosition(0);
x= GetCursorXPosition(0);
RequestMouseMoveRefresh();
GfxSelectSolidBrush( colorred ); GfxSelectPen( colorYellow );
GfxCircle( x0, y0, 0.5 ); // place a Circle - Dot in the chart
pnt1 = y0 + ( y0 * 0.001 ); pnt2 = y0 - ( y0 * 0.001 ); // +- Yaxis
if( y < pnt1 AND Y >pnt2 AND x0 == Lookup(bi,x) ) //x0 == Lookup(bi,x)
{
GfxSelectFont( "Arial", 12, 500 );
GfxTextOut( "Remove", X0+5, y0 ); //point to select to Remove
if( b & 9 )
{
StaticVarRemove( SVx );
StaticVarRemove( SVy );
}
}
}
}
/// initialize the staticVars
prefix = "OnlyClicksEXT" + Name(); // This version includes prefix for ALL statickvars
nIndex = Nz( StaticVarGet( "riEXT" ), 1); //was fixed to nIndex = 6 ( is the Num of the loop )
_TRACE("#,nIndex = " +nIndex);
ClickCounter = Nz(StaticVarGet("ClickCounter"+chartID),1); // a Click Counter start from ONE
RangeIndex = Nz( StaticVarGet( "RangeIndex" ), 1); // a RangeIndex Counter start from ONE
// Fibonacci Extention, Expansions can help us determine where price might head after the retracement is exhausted.
SVfextx = prefix+"EXTx";
SVfexty = prefix+"EXTy";
riEXT = Nz( StaticVarGet( "riEXT" ), 1); // if (riEXT > nIndex-1 ) StaticVarAdd( "riEXT",1);
fextx = Nz(StaticVarGet( SVfextx +riEXT +ClickCounter),0); // Fibo Extention (Expansion)
fexty = Nz(StaticVarGet( SVfexty +riEXT+ClickCounter),0); // 3 Clicks Group
id = GuiGetEvent( 0, 0 ); event = GuiGetEvent( 0, 1 );
GuiToggle( "3 Extention ", 13, 18, 50, 80, 24, 1|64|128); if( id == 13 AND event == 64 ) GfxTextOut( "Fibonacci Extention", 100, 50);
GuiSetColors( 10, 16, 1, colorOrange, colorBlack, colorRed, colorYellow, colorBlue, colorYellow, colorYellow, colorBlack, colorYellow );
GuiCheckBox ( "EXP",23 , 2, 50, 80, 24, 1);
// IF switcher is ON do this amound of clicks
totalClick = 0;
if( GuiGetCheck(23) ) totalClick = 3; // just 2 clicks allowed
//////// xGuiTriger Remove ALL avalable Static Var //////////
////// - NOTE: Remove ONLY From this indicator and symbol ///////
GuiToggle( "Remove",100, 5, 25, 50, 20, 1|64|128); if( id == 100 AND event == 64 ) GfxTextOut( "Remove All Range form this symbol", 100, 25);
if( GuiGetCheck(100)) //Ask User For confirmation
{
GuiToggle( "YES Remove",101, 5, 80, 90, 20, 1|64|128); if( id == 101 AND event == 64 ) GfxTextOut( "Remove All Range form this symbol", 100, 25);
GuiToggle( "No Thanks",102, 105, 80, 90, 20, 7 );
if ( GuiGetCheck(101)) { StaticVarRemove( prefix+"*" ); StaticVarRemove( "riEXT*" ); GuiSetCheck(100,0); }
if ( GuiGetCheck(102)) GuiSetCheck(100,0);
RequestMouseMoveRefresh(); // for Local database only
}
GuiSetColors( 100, 102, 0 , colorLightYellow, colorBrown, 0, -1, -1,-1,-1,colorred );
//GuiSetColors( 100, 102, 1, colorOrange, colorBlack, colorRed, colorYellow, colorBlue, colorYellow, colorYellow, colorBlack, colorYellow );
///////////////////////////////////////////////////////////////
///// Part 2 Mouse Clicking Control /////////////////////////
//////////// if Left button is Pressed /////////////////
if( b & 8 ) // flag = 8 is set when window just received mouse click
{
x = GetCursorXPosition( 0 ); // X-coordinate in DateTime format. y - value gives PRICE
y = GetCursorYPosition( 0 );
//barNo = Lookup( bi, x, 0);
if( b & 1 AND SelectedValue(bi) - bi[0] ) // barNo >0 replaced to SelectedValue(bi) - bi[0] as the user @patryk has problems
{
/////////////////////////////////////////////////////////////////////////////
////////////////// Fibonacci Extention (Expansion) - 3 Clicks //////////////
if( GuiGetCheck(13) AND ClickCounter <= totalClick )
{
StaticVarSet( SVfextx +riEXT + ClickCounter, x,1); // DateTime of the bar ...
StaticVarSet( SVfexty +riEXT + ClickCounter, y,1 );
StaticVarset( "ClickCounter" + chartID, ClickCounter + 1 ); // Add +1 to ClickCounter
Say( "" + ClickCounter ); Say( "Range " + riEXT,1 );
GuiSetCheck( 23,1 ); // Click button 23 to show me the lines
if( ClickCounter == 3 ) // Once the last mouse Click has occured
{
StaticVarset( "ClickCounter" + chartID, 1 ); // restart the ClickCounter
StaticVarSet( "riEXT", riEXT+1 ); // add plus +1 to RangeIndex Counter
GuisetCheck( 13, 0 ) ; // Reset the button toggle
}
}
}
}
//////////// TextOut the Next Click or the range /////////////////////////////
if( ( GuiGetCheck(13) ) AND ClickCounter<= totalClick)
{
GfxsetBkMode( 1 ); // 1 set transparent mode
GfxSetTextColor( colorYellow );
GfxSelectFont("Times New Roman", 14, 700, True );
GfxTextOut( " Place " + ClickCounter + " of ( " + totalClick + " Clicks ) ", 20 ,status( "pxchartbottom" )-20);
RequestMouseMoveRefresh();
}
/////////////////////////////////////////////////////////////
// PART 3 Fibonacci Extention (Expansion)
/////////////////////////////////////////////////////////////
//GfxSetOverlayMode( 1 );
GfxSetCoordsMode( 1 ); //1 = bar/price mode (instead of pixel)
for ( i =1; i < riEXT ; i++ )
{
x0 = Lookup(bi,StaticVarGet( SVfextx+i+"1" ));
x1 = Lookup(bi,StaticVarGet( SVfextx+i+"2" ));
x2 = Lookup(bi,StaticVarGet( SVfextx+i+"3" ));
y0 = StaticVarGet( SVfexty+i+"1" );
y1 = StaticVarGet( SVfexty+i+"2" );
y2 = StaticVarGet( SVfexty+i+"3" );
if(GuiGetCheck(23)) // show/ hide the FText lines
{
if( x0 != 0 AND x2 != 0 ) // draw on chart if range is selected
{
yRange = ( y1 - y0 ) ;
y_000 = y0 + yRange;
y_038 = y2 + ( yRange * 0.382 ); // 38.2%
y_050 = y2 + ( yRange * 0.500 ); // 50.0%
y_061 = y2 + ( yRange * 0.618 ); // 61.8%
y_078 = y2 + ( yRange * 0.786 ); // 78.6%
if( b == 9 ) _TRACE( "#, EXT y_000= " + y_000 + ", yRange =" + yRange + ", y_050 =" + y_050 );
_TRACE( "# , EXT nIndex " + i + "GuiGetCheck(23)" + GuiGetCheck(23) );
Y_100 = y2+ yRange;
y_112 = y2+( yRange * 0.128 )+yRange ; // 112.8%
y_127 = y2+( yRange * 0.272 )+yRange ; // 127.2%
y_161 = y2+( yRange * 0.618 )+yRange ; // 161.8%
y_261 = y2+( yRange * 1.618 )+yRange ; // 261.8%
// PLEASE NOTE: that in BELOW code we DONOT use pixels at the second parameter of GfxMoveTo() GfxLineTo()
// THAT MEANS WE DONOt have TO USE GfxSetCoordsMode( 3 ); // 3 = X coordinate is bar index, Y is pixel
//GfxsetBkMode( 1 );
GfxSelectPen( colorBlue, 3, penstyle = 2 ); // penstyle: Dash=1, Dot=2
GfxMoveTo( X0, y0 ); GfxLineTo( x1, y1 ); GfxLineTo( x2, y2 ); // wave line 1,2,3
// Extentions
GfxSelectPen( colorGreen, 1, penstyle = 2 );
GfxMoveTo( X1, y_050 ); GfxLineTo( x2, y_050 );
GfxMoveTo( X1, y_061 ); GfxLineTo( x2, y_061 ); // 61.8%
GfxMoveTo( X1, (y1-y0)+y2 ); GfxLineTo( x2, Y_100 ); // 100.0%
GfxMoveTo( X1, y_112 ); GfxLineTo( x2, y_112 ); // 112.8%
GfxMoveTo( X1, y_127 ); GfxLineTo( x2, y_127 ); // 127.2%
GfxMoveTo( X1, y_161 ); GfxLineTo( x2, y_161 ); // 161.6%
GfxMoveTo( X1, y_261 ); GfxLineTo( x2, y_261 ); // 261.8%
// text out
GfxsetBkMode( 1 );
GfxSetTextColor( colorGold );
GfxSetTextAlign( 6 );
GfxSelectFont( "Arial", 8, 500 );
TxtPos = 75;
GfxTextOut( "("+i+")", x1 , y1 ); // show range Index
GfxTextOut( "50%" , x2 , y_050 );
GfxTextOut( "61.8%" , x2 , y_061 );
GfxTextOut( "100%" , x2 , y_100 );
GfxTextOut( "112.8%", x2 , y_112 );
GfxTextOut( "127.2%", x2 , y_127 );
GfxTextOut( "161%" , x2 , y_161 );
GfxTextOut( "261.8%", x2 , y_261 );
}
// Delete specific range index, press Ctrl and then DoubleClick ON the Circle
RemoveOneRangeIndex( 13, 23 , SVfextx+i+"*", SVfexty+i+"*" );
}
} //end index loop
// END Fibonacci Extention (Expansion)
//////////////////////////////////////////////////////////////////////
//////// for debugger = interpretation window - show me what static vars i have until now
"<b> \nSVfextx11= " +StaticVarGet( SVfextx+"11" ) + ",\t SVfexty11= " +StaticVarGet( SVfexty+"11" ) +
"\nSVfextx12= " +StaticVarGet( SVfextx+"12" ) + ",\t SVfexty12= " +StaticVarGet( SVfexty+"12" ) +
"\nSVfextx13= " +StaticVarGet( SVfextx+"13" ) + ",\t SVfexty21= " +StaticVarGet( SVfexty+"13" ) ;
"\nSVfextx21= " +StaticVarGet( SVfextx+"21" ) + ",\t SVfexty22= " +StaticVarGet( SVfexty+"21" ) +
"\nSVfextx22= " +StaticVarGet( SVfextx+"22" ) + ",\t SVfexty31= " +StaticVarGet( SVfexty+"22" ) +
"\nSVfextx23= " +StaticVarGet( SVfextx+"23" ) + ",\t SVfexty32= " +StaticVarGet( SVfexty+"23" ) ;
_SECTION_END();