Ichimoku wave range

Hello everyone,
I'm using Ichimoku technique and part of it is wave theory. According to this theory ABCD waves have four basic scenarios where the price may get (waves N, NT, V and E). I would like to have these levels drawn on the chart automatically:

1

The perfect solution would be to have a drawing tool, something like Fibonacci Extension, where I can specify expected price levels as a formula related to prices in points A, B and C. Unfortunately, Fibonacci Extension works on percentages between two points, here I have three points involved.

What I did so far is: I use Fibonacci Retracement drawing it between points A and C, set Study ID as "FR" and with below code I'm calculating value of point B and drawing expected price levels:

Fibo = Study("FR", GetChartID() );

StartX = LastValue( ValueWhen( ExRem( Fibo, 0 ), DateTime() ) );
EndX = LastValue( ValueWhen( Fibo, DateTime() ) );
StartY = LastValue( ValueWhen( ExRem( Fibo, 0 ), Fibo ) );
EndY = LastValue( ValueWhen( Fibo, Fibo ) );

pointA = LastValue(Study("F5", GetChartID() ));
pointC = LastValue(Study("F1", GetChartID() ));

BarsA = LastValue(BarsSince(DateTime() == StartX));
BarsC = LastValue(BarsSince(DateTime() == EndX));

if (StartY < EndY)
{
pointB = LastValue(ValueWhen( Fibo, HHV(H, BarsA)));
}
else
{
pointB = LastValue(ValueWhen( Fibo, LLV(L, BarsA)));
}

if ((pointA != 0) AND (pointB != 0) AND (pointC != 0))
{
Plot( pointB + (pointB - pointA), "E", colorBlue );
Plot( pointB + (pointB - pointC), "V", colorBlue );
Plot( pointC + (pointC - pointA), "NT", colorBlue );
Plot( pointC + (pointB - pointA), "N", colorBlue );
}

Problem with this solution is that I can draw lines only with relation to one Fibonacci Retracement tool. According to this topic it is not possible to refer to multiple studies with same ID.
Using Fibonacci Extension instead seems better solution at first sight because it is generated with three points but Fibonacci Extension doesn't have Study ID field and I haven't found a way to get coordinates of third point (ThirdX, ThirdY). In the end there is a problem with defining Fibonacci level which are only in perentages.

I kindly ask for suggestion how to have expected levels drawn easily. I see three possible solutions:

  1. create new drawing tool (not quite sure if possible [link])
  2. find a way to refer to multiple studies with same ID.
  3. other :slight_smile:

I'm just asking for a hint because I ran out of ideas...

Thanks in advance
Patryk

1 Like

Hy Patryk, sorry wheter I'm wrong, I'm not sure to have understood well, but If your problem is to plot your indicator with different settings on the same 'ID Chart', you can draw different 'Study ID'.

I made this way:

setStudyID = ParamList("Study ID", "F0|F1|F2", 0); //This way you will be able to draw the same Indicator with different settings based on different Study ID, three in this case: F0, F1, F2
ChartID = GetChartID();
Fibo = Study(setStudyID, ChartID);

I hope this can help

Hi Bartleboom,
thanks for suggestion, it isn't quite what I am looking for but it is a little improvement.
I defined three Study ID's - FR, FS and FT (F0, F1, F2 are default ID's for retracement levels), this way I am able to switch between expected price levels of three Fibonacci Retracements but only one at a time:

2

When I choose from parameter list 'FS' I see expected levels for FS retracement, when I choose 'FR' I have levels for FR retracement.

It is a step forward but still not the best one. I would like to have expected levels of different waves to see where they are overlapping. And I would like to leave the old retracements just to be able to see historical cases. This way when adding new retracement I need to delete one old one (or create many ID's).

Thanks & regards,
Patryk

Hi Patrick, sorry, my fault.
With the previous suggestion try to paste your indicator twice or more on the chart you wish.
The first indicator will be set on Study_ID = F0,
the second one on Study_ID = F1
and so on...
Immagine 2021-04-05 160936
I did it for multi VAP periods and details so that on the same chart_ID I can have as many as VAPs I want with different settings
Best regards

Bartleboom, I think I know where the confusion comes from. I am using Fibonacci Retracement drawing tool [link], you are talking about self-made (or built-in) indicator. So with indicators yes, it is possible to use few of them of the same type (for example few moving averages based on different periods) and perform separate calculations for them. With drawing tools it is a little different - you can put many of the same type on one chart but you can't do additional calculations for all of them. You can refer to drawn tool through Study ID but you can refer only to one instance of the tool (first one).
To use your hint I would need to create an indicator which will draw expected levels based on three given points. Any idea how to do that?

hello @patryk
maybe here you will start with :wink:

to make your life easier the main afl code start from line 53 to 150 line.

/** @link https://forum.amibroker.com/t/ichimoku-wave-range/24923/6

"Drawing Multiple Fibonacci Extention"
By Panos 05-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 

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 1 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) )
            { 
                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 = "OnlyClicksMM" + Name();    // This version includes prefix for ALL statickvars 
nIndex = 6;  		//nIndex ( is the Num of the loop )

ClickCounter = Nz(StaticVarGet("ClickCounter"+chartID),1);  // a Click Counter start from ONE
RangeIndex = Nz( StaticVarGet( "RangeIndex" ), 1);		// a RangeIndex Counter start from ONE
// reset the RangeIndex back to 1, if used range are more than nIndex
if (RangeIndex > nIndex-1 )  StaticVarSet( "RangeIndex", 1 );

// 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 )  StaticVarSet( "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 


///////////////////////////////////////////////////////////////
///// 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 barNo >0 )
    {
        /////////////////////////////////////////////////////////////////////////////
        ////////////////// Fibonacci Extention (Expansion) - 3 Clicks  //////////////
        if( GuiGetCheck(13) AND ClickCounter <= totalClick ) 
        {
            StaticVarSet( SVfextx +riEXT + ClickCounter, x,1);  
            StaticVarSet( SVfexty +riEXT + ClickCounter, y,1 ); 
            StaticVarset( "ClickCounter" + chartID, ClickCounter + 1 );
            Say( "" + ClickCounter ); Say( "Range " + riEXT,0 );
            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" );

_TRACE( "# , 3EXT nIndex " + i );

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)
 //////////////////////////////////////////////////////////////////////


////////////  TextOut the Next Click or the range /////////////////////////////
// if(DebugOn) 	 _TRACE("#, Message ClickCounter= " + ClickCounter);
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();
}

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

fiboExtention

7 Likes

Hi PanoS,
that's a nice piece of code :slight_smile:
I will need some time to digest it, in case of troubles I will ask you for help.

Thanks!

2 Likes

Hi Panos once again,
as predicted I need to ask you for help :slight_smile:
Your code wasn't working on my computer at the beginning, the part that was causing problems is:

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

barNo variable was null all the time so nothing was drawn. After checking Lookup function and replacing it with

barNo = SelectedValue(bi) - bi[0];

(as suggested here) I got the lines drawn. I tried also setting SetBarsRequired( sbrAll, sbrAll ) but Lookup was still not working.
With above modification drawing works fine but next problem is with deleting. In your version I could not delete anything (I succeed one time). The red circle was appearing but I could not manage to point the spot where "Remove" was active. And again it is Lookup function which is the problem:

             if( y < pnt1 AND y >pnt2 AND 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 );
                }
            }

But here replacing it with

if( y < pnt1 AND y > pnt2 AND  x0 == SelectedValue(bi) - bi[0]);

didn't help much. This way wherever I clicked I got all drawings removed. I did one more modification:

                if( b & 4)
                {
                    StaticVarRemove( SVx );
                    StaticVarRemove( SVy );
                }

and with this middle click deleting works after clicking the red circle but still I get all drawings deleted. In your opinion, changing Lookup to SelectedValue(bi) - bi[0] is OK? How can I modify deleting function to work properly?

And another thing - how many fibo extensions I can draw at a time? I am not sure yet but seems that nIndex parameter is somehow related. Usually I can draw two-three instances of fibo extensions and that's it. When trying to draw another, nothing is happening or everything vanishes. I suppose there is limitation from computer memory/CPU...

Patryk

1 Like

As far AmiBroker's built-in drawing tools are considered, there is no limit on number of drawings of any kind.

1 Like

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

Thanks PanoS, your code is great, now works better. I will adapt it to my needs and also check the link you provided. A lot of learning for me :slight_smile:

Cheers!

Hello @patryk
i am happy that you found this example with static variables useful.
If you need anything else..... just knock the door. :wink:

Οf the last code " version 2 Template "
Since we change the assign of the "nIndex" ,we need to add the third parameter of the StaticVarSet **persistent = True **

So. i will like to replace the line 120.
And Next time when you open the AB, your drawing will be there, ready to see on the chart

// line 120  set persistent = True,  
StaticVarSet( "riEXT", riEXT+1, True );  // add plus +1 to RangeIndex Counter

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.