Using mouse button clicks to set pivots for Fibonacci retracements / extensions

hI,

CLICKED REPLY BY MISTAKE.
Once again thanks for the guidance, if I do not succeed will have to ask for assistance again.
I am well aware of the Fib price (ext. and ret.) and fib time drawing studies inbuilt into Amibroker.

The issue is that when one does price and time studies from multiple pivots the chart is covered with
many horizontal and vertical lines - really messy,

I am trying to draw all the fib. price studies in the RHS (blank) 0f the chart and if I succeed I will further
venture to do the same for the time studies, small vertical lines above and below the price chart - so the
price chart is "clean".

While going thru the AFL library did notice some one had put in a request a few "years" ago - no one followed up.

Once again thanks for ur help.

Hi,

I keep being told to use the fib price and time tools in Amibroker.

Just to clarify what I am trying to acheive, posting 2 charts
below - hope that provides an answer as to why I am trying to write an AFL for Fib price and time studies!

image

image

1 Like

Hi @JEETU

Hmmm
Now looks little bit better what you trying to achieve.
I can see a highlight box in area between 112.8 up to 127.2
But the yellow area?
For me Is not very clear your final Project.

1 Like

Hi PanoS,

The horizontal rectangles (blue outline with light blue fill and lime outline and yellow fill) are based on the fib price analysis on the "messy chart" and the small violet vertical rectangle and small violet vertical line are based on time analysis on the "messy chart".

The logic of the blue rectangles is from another software (MTPredicftor) I use and the concept of the rectangles with lime outline and yellow fill is for "Fib. clusters" .

The fib cluster and fib time analysis is based on a book called "High Probability Trading strategies"
by Robert C. Miner(dynamictraders.com) and a book called "Fibonacci Trader" by Calroln Boroden(fibonacciqueen.com).

With the amazing capability of AFL I am sure that I can obtain the same results without messing up the chart.

Draw back is that apart from my limited experience with AFL I have no programming experience.

To keep it simple and for a start :--- In Amibroker from the drawing tools I can draw multiple horizontal and vertical lines on a chart, then delete any line by selecting and pressing "delete" on the key board - the question is "WHAT IS THE AFL FOR THAT".

Even if the issue of drawing Hi Lo tags (one of my above posts) with the click of a mouse button is solved it will be a major breakthrough --- but I am still stuggling.

The above two suggestions are for shifting a drawn object using click of a mouse button WHEREAS I want to draw using the click of a mouse button.

One can only try and hope for help!

1 Like

what about if you DONOT using mouse clicks?
can you check this version here just for the idea (it is old AFL)

1 Like

Hi,

It seems like I am not clear to people reading my posts, so if u like to understand what I am trying to acheive
proceed with the following steps:

  1. Open Amibroker and click on " help" then click on "help contents".
  2. From the contents selecct "AFL" then select "Allphabetical list of all AFL funcions".
  3. In the alphbetical list selecct "line array" then under Reference select "Fibonacci internal and external retracements" (my basic formua came from here - this I modified to plot fib levels in the RHS of the chart-see the first chart posted above).
  4. Kindly scroll down to the end of the formula and read the "comments", - now I am trying to achieve what "Kevin" mentioned on 18th October 2008 (10 years ago !!! and also do the same for time analysis.

If any one has made progress and is willing to share it will be much appreciated.

Hi
i wrote this afl with Not really "messy chart" for me :wink:
@JEETU i dont know if it is very close what you try to do.

_SECTION_BEGIN("xFibo Ver 2");
// Fibonacci Retracements using Gfx* functions by Panos 05-07-2018
// EXAMPLE   xFiboRetracements("P6",colorBlue ) ;

Plot( C, "Price", colorDefault, styleCandle );
GfxSetOverlayMode( 1 ); 
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)

function  xFiboRetracements( StudyID, Color )
{
	trendline = Study(StudyID, GetChartID() );
	bi =BarIndex();
	
	X0= StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), BarIndex() ) );
	X1= EndX = LastValue( ValueWhen( trendline, BarIndex()) );			// printf("X1 StartX  = %g,\n X1 EndX = %g\n", StartX, EndX );
	Y0= StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
	Y1= EndY = LastValue( ValueWhen( trendline, trendline ) );		// printf("\nY1 StartY  = %g,\nY2  EndY = %g\n", StartY, EndY );

		LineY = ( Y1 - Y0 ) ;
		//y0 = Y1;
		y382 = Y1 - ( LineY * 0.382 );
		y50  = Y1 - ( LineY * 0.50 );
		y618 = Y1 - ( LineY * 0.618 );	// 61.8%
		y786 = Y1 - ( LineY * 0.786 ); 	// 78.6%  
		Y100 = Y0;
		y112 = Y0 - ( LineY * 0.128 );	// 1.128
		y127 = Y0 - ( LineY * 0.272 );	// 1.272
		y161 = Y0 - ( LineY * 0.618 );	// 1.618%

	GfxSelectPen( Color );
	Bars=  bi[x1]-bi[x0];
	if( ParamToggle( "Measuring X & Y ", "No|Yes" )) ext= Bars; else ext= 0;
	GfxMoveTo( X0, y1 );	GfxLineTo( X1+ext, y1 );   // 0% 
	GfxMoveTo( X0, y100 );	GfxLineTo( X1, y100 );   // 100%
		if( ParamToggle( "Show Fibo Retracements? ", "No|Yes" ) )
	{
	GfxMoveTo( X0, y382);	GfxLineTo( X1, y382 );   // 38.2%
	GfxMoveTo( X0, y50 );	GfxLineTo( X1, y50 );   // 50%
	GfxMoveTo( X0, y618 );	GfxLineTo( X1, y618 );   // 61.8%
	GfxMoveTo( X0, y786 );	GfxLineTo( X1, y786 );   // 78.6%
	GfxMoveTo( X0, y112 );	GfxLineTo( X1, y112 );  // 112.8%
	GfxMoveTo( X0, y127 );	GfxLineTo( X1, y127 );  // 127%
	GfxMoveTo( X0, y161 );	GfxLineTo( X1, y161 );  // 161.8%
	}

	if( ParamToggle( "Show Fibo number? ", "No|Yes" ) )
	{
		GfxSelectFont( "Tahoma", 8 );
		GfxSetBkMode( colorDefault );
		GfxSetTextColor( colorBrown );
		GfxTextOut( "0%", X1, y1 );
		GfxTextOut( "100%", X1, y100 );
		GfxSetTextColor( ColorRGB( 100, 200, 100 ) );
		GfxTextOut( "38.2%", X1, y382 );
		GfxTextOut( "50%", X1, y50 );
		GfxTextOut( "61.8%", X1, y618 );
		GfxTextOut( "78.6%", X1, y786 );
		
		GfxSetTextColor( colorBlueGrey );
		GfxTextOut( "112.8%", X1, y112 );
		GfxTextOut( "127%", X1, y127 );
		GfxTextOut( "161.8%", X1, y161 );
	}

		GfxsetBkMode( colorDefault );
		GfxSetTextColor( colorAqua );
		if( ParamToggle( "Bars,Change,% ? ", "No|Yes" ) )
	{  // TrendLine Bars , Change ,Percent
			InfoPosition= Y1 + ( LineY * 0.10 );
		perc = NumToStr(abs(((y1-y0)/(y0+1e-9 ))*100),1.2);
		InfoTxt = "Change: "+abs(LineY)+ ",("+ perc  +  " % ), Bars: "+ Bars+"";
		GfxTextOut( InfoTxt, x0-5, InfoPosition );
	}
	
	if( ParamToggle( "Bars between X & Y ", "No|Yes" ))  GfxTextOut( "Bars: "+Bars  , X0+Bars/3, Y1 );
	
	if( ParamToggle( "Show Gfx Rectangle ", "No|Yes" ) )
	{
	GfxFillSolidRect(   BarCount +3, y112, BarCount +50, y127, color );
	// GfxFillSolidRect(   BarCount -1, y112, Status("pxwidth")-80, y127, color );  // also with Pixels
	// Text inside Rectangle box
	GfxSetTextColor( colorGold);
	GfxSelectFont( "Tahoma", 10 );
	GfxTextOut(  StrFormat("%g - %g",y112,y127 ), BarCount +4, y112+(y127-y112)/2);
	}
}
xFiboRetracements("P1",colorDarkOliveGreen ) ;
xFiboRetracements("P2",colorDarkGreen ) ;
xFiboRetracements("P3",colorDarkTeal ) ;
xFiboRetracements("P4",colorBlueGrey ) ;

_SECTION_END();

12 Likes

Hi PanoS,

You are a genius.

What a lovely surprise I had when I checked my email and then also on the forum.

The information you have provided will keep me busy for some days !

Yes, I still use MTPredictor (MTP) for EOD scanning, will post a few screen shots.

It will be excellent if we can select the pivots (trough low and peak high) using a click of the mouse button,
in MTP selections are with the click of a mouse button.

In MTPredictor there is a drawing tool called "Hi Lo Tag", I have been trying to write an AFL for this, it is

posted above. More on this when I post the screen capture.

Once again, thanks a ton.

One question for you, "is it possible to slow down / pause your video recording"

Thanks again.

1 Like

Hi,

I am trying to post 3 clips;--

[ii]. from MTPredictor - showing the plot of multiple hi / lo tags.

image

[ii]. from Amibroker showing only a tag plotted from the "high".

image

[iii] from Amibroker showing only a tag from a "low"

image

The AFL is;--

t

////// USING LEFT MOUSE BUTTON "CLICK"TO DRAW A HORIZONTAL LINE  AND DISPLAY VALUE OF SELECTED HIGH OR LOW 

_SECTION_BEGIN("MLB CLICK");


GfxSetCoordsMode( 1 );
GfxSetOverlayMode(  0 ) ;
// MLB  click

MLBClicked = GetCursorMouseButtons() ==9;

    MouseX = Nz( GetCursorXPosition( 1 ) );
    MouseY = Nz( GetCursorYPosition( 0 ) );
    

  
selectBi = SelectedValue( BarIndex() );
selectH = SelectedValue( H );
selectL = SelectedValue( L );

    CursoraboveH = MouseY> selectH ;
    CursorbelowL = MouseY < SelectL;
  
if (  CursoraboveH  AND MLBClicked)
    { 
    
GfxSelectPen( colorGreen, 1, 2 );
GfxMoveTo( selectBi, selectH  );
GfxLineTo( BarCount+2, selectH );
 PlotText( "H = "+H, BarCount+3,selectH  ,colorGreen) ; 
    }
if (  CursorbelowL AND MLBClicked )
{
   
GfxSelectPen( colorRed, 1, 2 );
GfxMoveTo( selectBi, selectL  );
GfxLineTo( BarCount+2, selectL );
PlotText( "L = "+L, BarCount+3,selectL  ,colorRed) ;
}

_SECTION_END();


In Amibroker with the above AFL, even though the high / low tag plots it disappears in a few seconds, further
only one tag can be plottes at a time.
The focus at present is to be able to plot as many hi / lo tags as one wants !

The eventual goal is to use the left click of the mouse button to perform multiple tasks, come on guys it is the age of mouse clicks!!

I do not know how to record a video of the screen, once I learn that I will post a recording of the multiple tasks which may be done using the left click of a mouse button.

If it is a coding issue then I request the Amibroker team to provide some support / code snippet for using the left click of a mouse button to perform tasks.

Download Bandicam for free. Easy to use for screen capture of short videos.

1 Like

I recommend this freeware program: https://www.screentogif.com/ for recording short animated gifs. It is worth noting, that only files not larger than 500KB can be uploaded.

1 Like

@JEETU you can do almost everything in AFL (probably 99% of the things you can think of), but each custom solution requires good AFL knowledge and experience. If you lack such skills it will be difficult for you to make a code meeting your criteria. Besides you can already find many codes on the forum making use of mouse button clicks. I gave you a link to one of such codes in my upper link. You can easily find another examples.

I know it might not be the perfect solution in your case, but remember that if you want to avoid clustering your charts with too many objects, you can make use of different custom Layers which can be switched on/off to show or hide groups of objects. You can have as many custom layers as you want - and you can rename them according to your needs. For example:

Layers3

https://www.amibroker.com/guide/h_layers.html
https://www.amibroker.com/video/layers.html

7 Likes

Hi,

Thanks for all the feed back, definitely helps in the AFL learning curve.

However the issue remains - no one has provided a solution to the questions I have asked !

What I have learnt is how to post a "screen clip" of a chart and soon I may also be able to post a video clip -
does not help in learning AFL.

I know I have very limited programming skills !

I only come to the forum after - "supply of paracetamol runs low / very few hair left - cause I have pulled them out / no coffee left / dog refuses to go for a walk", so guys my request to all of you is to provide a solution to my query so that I may progress on the AFL learning curve.

thanks for the guidance, warm regards

Hello
@JEETU In your Code example you are using SelectedValue() and that is fine.
But now the program need to remember what you select, and for that reason you need this specific X or Y Value to store in static variable, or in a ascii file.
In your case here you NEED to store both X-axis and Y-axis.

@Milosz gave you many links… I don’t know if you bought already new box of tea or coffee? But before you run out again, you have to focus on StaticVariables

It is very easy to write this code that you are looking for.
If you stuck somewhere let us know, and came back with more charting ideas.
Happy coding

Hi,

Thanks, you guys are great, always nudging but not providing the solution.
If you provide the solution I will not learn anything -- this way, with trial and error I
will learn and it will stay with me - once again thanks to you and MIosz.

Ya , from what little I have learnt, I was inclined towards "functions" and "static variables" - still
trying to understand their use.

Coffee is out and has been replaced with herbal ( Ginseng) green tea.

Once again thanks for your guidance .

Hellow Milosz,
Can you please share the afl code for drawing fibonacci time extensions & arcs ( as shown in the above display).
Thanks in advance

Hellow Milosz, Basically i am looking AFL code which draws fibonacci time extensions & fibonacci fans automatcally. ( not fibonacci arc)
Thanks

Thank you so much PanoS. This gives good break though for my current development.
I was actually looking for topic where AFL identifies the drag and drop of a drawing.
This helped Me.

Main idea is to create an AFL which triggers the order placing API functions based on line position(Like in TV, we can modify the order entry price(Limit), Stop loss and Target order by moving the horizontal line on the chart).

Everyone please direct me if we have any blogs already related to the topic i mentioned.

Thank you for your time.

Hello

If you go to Amibroker menu > insert > BUY Line ,SELL line exist already If you are with interactive Brokers.

I don’t know your afl coding background and how exactly you imagine to make your tool.

But If you are looking for a GFX button like this. It is already exist from a Amibroker Member.
gfxbutoons

If you looking just mouse clicks on the chart let me know.

Also in the amibroker member area must be few afl there

Thank you @PanoS.

I am not using IB so can't make use of the option.
and i am a programmer its been few months i started with AFL gone though all the standard documentation and have decent hands on with AFL.

My requirement is, on click of a button based on the LTP i want to place BUY, SL and Target lines(with buttons), on click of buttons(which are on the lines) i want to manage the order placement and option to move the individual line on chart.

In this i can handle the order management part as i already have API and development exposure on it.
Regarding the Mouse clicks for the i got below Blog and will try to understand code and try to get back if any doubts, Thank you.

GetCursorYPosition() on GuiButton