Extension or Retracement Formula Required

**

Extension or Retracement Formula Required ~ Fibonacci Drawing / Indicator Q’s.

**

Retracement / Extension Indicators or Tool
I am wanting to essentially have 2 x Fibonacci Drawing Indicators within Amibroker; or at least an additional one to what is already included in the software: I am not fussy whether the additional one I upload is either an Indicator type or actual Drawing tool type as long as it’s an overlay I can adjust like the installed type.

The reason: ~ I wish to have the ability to draw another type of retracement or extension, such as the Fibonacci retracement, but with differing percentages. I know I can alter the percentages within the installed drawing parameters of the existing drawing tool within the program but then I remove the ability to have this drawing tool as a Fibonacci retracement, which I already use a lot.

This alternate retracement tool I after is simply the same type of point to point positioning between to price points or chart positions but it has the percentage lines or 12.5%, 25%, 37.5%, 50%, 62.5%, 75%, 87.5% & 100% as opposed to the Fib numbers/percentages.

I have search reasonably extensively on the Forum site content list, Wisestocktrader.com & other sites but to no success for either advice or any designed code that is able to be manipulated. There are a couple of formula for a Fib Retrace, but they are not an over lay but more a whole chart structure of how the writer reds / sees his charts.

hello @danbmcdonald

Here is a nice example how to start this code that you are asking for.
I hope you have the skill to code (i can imagine that must be 20 lines of code no more).
if no one reply you, maybe i will try this weekend, i like this idea and “must be a fun” for me

Hi PanoS,

Thanks for the reply and advice. I am not a Coder or script writter within Amibroker. My computer skills do not extend to this level; I do wish this was different but no. So I’ll not be able to have any fun doing what you suggested.

You are the first to reply to my inquiry, no one else has come forward as yet.

If you feel that you would like to give this an attempt then it would be greatly appreciated.

Regards,

Dan

hello @danbmcdonald

here is the code for the Retracements that you ask

_SECTION_BEGIN("xFibo_with_Color_fixed");
/** Fibonacci Retracements fixed to 12.5%
// 12.5%, 25%, 37.5%, 50%, 62.5%, 75%, 87.5%
// By Panos Version 1   21-Oct-2017  xFibo with GfxLines
// example = xFibo("F1",colorYellow, 150 );
/// @link http://forum.amibroker.com/t/extension-or-retracement-formula-required/2682/3
/// foto @link http://tinyurl.com/ycupqekg
*/

Plot( C, "", colorDefault, styleCandle );

GfxSetOverlayMode( 1 );
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)

function  xFibo( StudyID, Color, extend )
{
    trendline = Study( StudyID, GetChartID() );

    X1 = StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), BarIndex() ) );
    X2 = EndX = LastValue( ValueWhen( trendline, BarIndex() ) );		//	printf("X1 StartX  = %g,\n X2 EndX = %g\n", StartX, EndX );
    Y1 = StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
    Y2 = EndY = LastValue( ValueWhen( trendline, trendline ) );			//	printf("\nY1 StartY  = %g,\nY2  EndY = %g\n", StartY, EndY );

    DiffY = ( Y2 - Y1 ) ;
    GfxSelectPen( Color );

    // Show me the lines 12.5%, 25%, 37.5%, 50%, 62.5%, 75%, 87.5%, 100%
    for( i = 0; i <= 1 ; i = i + 0.125 )
    {
       // printf( "\n i " + i );
        lineY = Y2 - ( DiffY * i );
        GfxMoveTo( StartX, lineY );  GfxLineTo( EndX + extend , lineY );
    }
}

extend= Param("Extent Lines", 0, -200, 200,10 );
xFibo("F1",colorDarkOliveGreen, extend ) ;
xFibo("F2",colorBlueGrey, extend);
xFibo("F3",colorAqua,extend);
_SECTION_END();

Fibo_trendline

3 Likes

PanoS,

Thanks heaps mate. Greatly appreciate your efforts and time. I’ll have to figure out how to use a different command button instead of the F1,F2, F3 options as I am using a Mac which doesn’t have these buttons as a primary standalone option. (I use Amibroker through pararrells, which works fine apart from the different keyboard obviously).

I’ll let you know how I go!

Cheers again.

i have no idea which buttons are missing :thinking:
in my foto where is the Study ID can you Press the arrow Down ?
If you say YES. Then instead of type F1 you can Click on... SU or RE or UP

and change those 3 line.

extend= Param("Extent Lines", 0, -200, 200,10 );
xFibo("SU",colorDarkOliveGreen, extend ) ;
xFibo("RE",colorBlueGrey, extend);
xFibo("UP",colorAqua,extend);

i hope it helps.

Mac_keyboard

Hi PanoS.... Okay I have attempted to do what you have asked ~ changed code
and also options in the Parameters function box. But to no success....

Maybe I am not activating the formula/code correctly?? Let me explain what
I am doing and see if you can see a glaringly obvious error in my actions:
( I am using the original instructions here with the F1, F2 F3
configuration..:

  1. I create the folder and the formula sheet, then enter the code in as you
    wrote:

  1. Then I draw a trend line. Click on it to highlight it.

  2. Then to activate the code I press F1, or F2 or F3, as per picture (is
    this how you do it on your Mac?)

And what I get as a result is this:

F1 = Amibroker help window opens up ~ .

F2 = Nothing occurs

F3 = Symbol Finder window opens up ~ .

You will have to excuse any issues that are occurring due to my operator
error. It's highly likely that it is my fault and something that I am
doing.

I hope this explains my problem. Apologies for making this harder then it
seems to be.

Thanks again.

Dan

Cheers,

*Dan *

Hello @danbmcdonald

I really think you need to read more carefully.

In the foto where I try to describe how the code is working, I wrote TYPE ( that mean write) and NOT press the f1 button in your keyboard.

And then again in my second reply with a second foto plus the 3 lines of code to change, you did NOT read carefully. why?

In study ID box WE HAVE TO TYPE=write OR we have to select with the mouse the readymade that program has ( that is = SU, RE, UP ….)

So I have the feeling you have to read it again.

So that means the problem is not because you are running AB on MAC but to understand and read the manual or what we say…

Thanks you listen. I think now is more clear to you as a new user

PS. With this AFL code you are able to draw NOT one line, but also you can insert in your chart 3 different lines.
And in every line inside in Study ID you have to Type different combination of letters (that are hardcoded in the AFL as f1, f2, f3,)

Now, If you ask me why I decide this combination of letters?
Is because for me is easy to remember Fibo_first_trendline_is = F1 :wink:
with different color every of those 3 lines. IF you wish to draw in your chart more than one….

Happy days :smiley:

1 Like

Hello PanoS again,

You are right I did not read or understand the context of your directions.
I have done so and now have success. FYI I have changed the type of chart
to a BAR CHART as this is how I use Form Reading and altered the colours to
suit!

You are a champion !!

I have one more question for you regarding this formula… how do you, or
can you I should ask, have the values (price) plotted on the lines: say on
the right-hand side end of each line?

No stress if this cannot be done as you have already given me something
that is a tool i use every day now - thank you.

Dan

Cheers,

*Dan *

PanoS,

Would you take a look at my other request and see if you have a solution already completed in your knowledge base of formulas OR have the ability to create what I am asking? = A Measuring Device (such as a ruler) that can be used to measure the number of BARS or DAYS between an X & Y position, with the text of the days/bars # displayed in the array line. The Community Broker Forum Feed is called MEASURING DEVICE: Measuring Device

Cheers,

Dan

Everything is possible with Amibroker.

What I read in your other post you are looking for analysis. you said:
<<But I am looking for something a little more detailed
so I can use it in analysis >>

And for that reason NO one will start to write a code for you if you donot say your plan to him. You MUST say I need that for this, this and this… and this is my strategy … and this is my exploration. Do not get me wrong, I hope you understand why?
Just remember to make a tool for fun, it is different than to make a strategy

So until you decide, I recommend you go to the library to check for Fibonacci afl
One of the codes, that maybe you like is this one.
http://www.amibroker.com/members/library/formula.php?id=1371

I think, you must have a look again in build in Fibonacci tools that amibroker Programm has and without lot of coding you can run Analysis as you wish in first place
I am waiting for your comments

Hello Dan
I had to write here an update, because there was a conflict with this combination that i use in studyID F1… as I notice amibroker use it in build in Fibonacci Retracement tool.

So in this below code, we have to TYPE the p1, p2, or p3 instead, as a Study ID.

And @danbmcdonald because I like you,:smiley: I also updated as you wish with 3 parameters Show Fibo number, values, and bars.
.

_SECTION_BEGIN("xFibo_with_Color_fixed_12.5% Ver2");
/** Fibonacci Retracements fixed to 12.5%
// 12.5%, 25%, 37.5%, 50%, 62.5%, 75%, 87.5%
// By Panos Version 2   29-Oct-2017  xFibo with GfxLines
// updated with 3 parameters  Show Fibo number, values, bars
// example = xFibo("p1",colorYellow, 150 );
/// @link http://forum.amibroker.com/t/extension-or-retracement-formula-required/2682/12
 
* How to use this code:
* draw a trend line on this chart panel,
* double-click on the trend line to bring up properties dialog
* and TYPE  “p1” as study ID and press OK
* Note that, you can draw in your chart 3 different lines and in every single trend line type p1, p2 ,p3    
* if you Comment below Plot() line you can use the afl as drag and drop.
*/

Plot( C, "", colorDefault, styleCandle );

GfxSetOverlayMode( 1 );
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)

function  xFibo( StudyID, Color, extend )
{
    trendline = Study( StudyID, GetChartID() );
	bi= BarIndex();

    X1 = StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), bi ) );
    X2 = EndX = LastValue( ValueWhen( trendline, bi ) );		//	printf("X1 StartX  = %g,\n X2 EndX = %g\n", StartX, EndX );
    Y1 = StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
    Y2 = EndY = LastValue( ValueWhen( trendline, trendline ) );			//	printf("\nY1 StartY  = %g,\nY2  EndY = %g\n", StartY, EndY );

    DiffY = ( Y2 - Y1 ) ;
    GfxSelectPen( Color );
    GfxsetBkMode( colorDefault );
    GfxSetTextColor( color );
    // Show me the lines 12.5%, 25%, 37.5%, 50%, 62.5%, 75%, 87.5%, 100%
    for( i = 0; i <= 1 ; i = i + 0.125 )
    {
        printf( "\n i " + i );
        lineY = Y2 - ( DiffY * i );
        GfxMoveTo( StartX, lineY );  GfxLineTo( EndX + extend , lineY );

		if( ParamToggle( "Show Fibo number? ", "No|Yes")) GfxTextOut( ""+i*100+"%", X1, lineY );
		if( ParamToggle( "Show values(price) ", "No|Yes" ))  GfxTextOut( ""+lineY, X2, lineY );
	}
	
	Bars=  bi[x2]-bi[x1] ;
	if( ParamToggle( "Bars between X & Y ", "No|Yes" ))  GfxTextOut( "Bars: "+Bars  , X1+Bars/3, Y1 );
}

extend= Param("Extent Lines", 0, -200, 200,10 );
xFibo("P1",colorDarkOliveGreen, extend ) ;
xFibo("P2",colorBlueGrey, extend);
xFibo("P3",colorAqua,extend);
_SECTION_END();

Hi PanoS,

Thankyou for the info and update mate. I’ll adjust as directed.

BTW the code is working very well for me! Thanks again.

Cheers.

Okay PanoS.

Regarding the Request for a Measuring Device:, let's call the Formula BAR/DAY COUNTING RULER

I have had a look at the suggested code and it's no good for me as it doesn't do what I am after. So I will explain so that the fun can begin!!

NEED

  • A tool that is drawn on the chart between 2 points, such as draw a line between X and Y points, so it shows in text the number of bars and or days that exist between the 2 points.
  • The chart is to be in StyleBar Format
  • The text is needed to be near the XY line drawn.
  • THEN I also would like to have the exact length of the original XY line be extended or mirrored to a Z point; in either direction the original line is drawn (i.e. forward or backwards).

The STRATEGY

  • This is so I can measure the number of days and the number of bars between major turning points, that are defined by trend change, specific dates (luna cycle points) and world events (such as President Trump election).
  • I wish to count forward also certain bar numbers to determine potential future turning points from the above mentioned points.

RESEARCH

  • I have attempted to try and use fibonarcci extensions, time extensions and normal line draws and they do give me bar counts, but I want to have this in text after I leave the drawn line on the chart.

REFERENCE
Please see the below pictures for evidence of the line drawn and the text plotted.

Untitled 3
Untitled 2

Is this what you mean by explanation of a plan ??

Regards,

Dan

Hello,

Here is some code to start with, not sure who is the author but props to whoever it is.

if (ParamToggle("Enabled", "No|Yes", 1))
{
  EnableTextOutput(False);
  
  what = ParamList("Object", "Bar count|Price change (close)|Price change (high/low)|Average volume|Total volume|Average BW MFI", 0);
  mColor = ParamColor("Color", colorRed);
  mStyle = ParamStyle("Style", styleLine | styleDashed, styleDashed | styleThick);
  mbgColor = ParamColor("Label Bg Color", colorWhite);
  showInTitle = ParamToggle("Show in title", "No|Yes", 1);
  
  SelectedBar = SelectedValue(BarIndex());
  StartRangeBar = BeginValue(BarIndex());
  FinishRangeBar = EndValue(BarIndex());
  
  // determine start & end of range
  if (StartRangeBar > 0 AND FinishRangeBar < BarCount - 1) // range defined by markers
  {
    start = StartRangeBar;
    end = FinishRangeBar;
  }
  else
  {
    if (StartRangeBar > 0) // range defined by start marker & selection
    {
      start = StartRangeBar;
      end = SelectedBar;
    }
    else // range defined by selected bar and end
    {
      start = SelectedBar;
      end = FinishRangeBar;
    }
  }
  if (start > end) { tmp = start; start = end; end = tmp; }
  
  // measuring
  switch (what)
  {
    // bar count
    case "Bar count":
      Value = end - start;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring bars: " + WriteVal(Value, 1.0);
      break;
    // price change (close)
    case "Price change (close)":
      Value = (Close[end] / Close[start]) * 100 - 100;
      Value2 = (Close[end] - Close[start]);
      Label = WriteVal(Value, 1.2);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring price change (close): " + WriteVal(Value, 1.2)+"%/ " + WriteVal(Value2, 1.3)+" abs.";
      if (start != end) Plot(LineArray(start, Close[start], end, Close[end]), "", mColor, mStyle | styleNoLabel);
      break;
    // price change (high/low)
    case "Price change (high/low)":
      if (High[end] >= High[start]){
        Value = (High[end] / Low[start]) * 100 - 100;
        Value2 = (High[end] - Low[start]); }
      else{
        Value = (Low[end] / High[start]) * 100 - 100;
        Value2 = -(High[start] - Low[end]);}
      Label = WriteVal(Value, 1.2);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring price change (high/low): " + WriteVal(Value, 1.2)+"%/ " + WriteVal(Value2, 1.3)+" abs.";
      if (start != end)
      {
        if (High[end] >= High[start])
          Plot(LineArray(start, Low[start], end, High[end]), "", mColor, mStyle | styleNoLabel);
        else
          Plot(LineArray(start, High[start], end, Low[end]), "", mColor, mStyle | styleNoLabel);
      }
      break;
    // Average volume
    case "Average volume":
      Bars = end - start + 1; // (inclusive)
      Value = 0;
      for (i = start; i <= end AND i < BarCount; i++) Value += Volume[i];
      Value = Value / Bars;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring average volume: " + WriteVal(Value, 1.0);
      break;
    // Total volume
    case "Total volume":
      Value = 0;
      for (i = start; i <= end AND i < BarCount; i++) Value += Volume[i];
      Value = Value;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring total volume: " + WriteVal(Value, 1.0);
      break;
    // Average BW MFI
    case "Average BW MFI":
      Bars = end - start + 1; // (inclusive)
      Value = 0;
      for (i = start; i <= end AND i < BarCount; i++) Value += 100000 * (High[i] - Low[i]) / Volume[i];
      Value = Value / Bars;
      fmt = 1;
      if (log10(Value) < 0) fmt += (-floor(log10(Value)) + 2) / 10;
      Label = WriteVal(Value, fmt);
      if (showInTitle) Title = "\n" + EncodeColor(mColor) + "Measuring average BW MFI: " + WriteVal(Value, fmt);
      break;
  }
  
  if (start != end)
  {
    // get highest visible value
    Hh = -1e8;
    for (i = Status("firstvisiblebarindex"); i < Status("lastvisiblebarindex") AND i < BarCount; i++)
    {
      if (High[i] > Hh) Hh = High[i];
    }
    VGrid = (Status("axismaxy") - Status("axisminy")) * 0.01;
    VH = Hh;
    if(what == "Price change (close)" OR what == "Price change (high/low)" )
    percent = "%/" + Prec(Value2,5);
    else percent = "";
    Plot(LineArray(start, VH, end, VH), "", mColor, mStyle | styleNoLabel);
    PlotText(Label + percent, start + (end - start) / 2 - 2, VH + VGrid, mColor, mbgColor);
  }
  EnableTextOutput(True);
}
Plot(c,"close",colorblack,stylecandle);

Anthony

Hi Anthony,

Thanks for the code. Appreciated. Unfortunatly I am not skilled in writing code so I could not finish this off to make it work for my needs.

Thanks all the same mate.

Cheers

Hello Dan
I confuse now let me know please. According to the subject did you solve your needs with below link or not?


if yes…Just press the solved button in the post that you believe is the best one that solve your problem. Everyone knows that this particular post is solved, and in the future they can visit your post to read what happen, and how you solve the code / problem
I am going to reply you later in the other thread since I know that we are clear here.
Also we can continue chatting about for the same subject in this one. No problem
Thank you
The “Solved” button (checkmark) becomes visible when you click on (…) button left to the “Reply” button

Hello Dan,

Here is a first version for measuring device.

//Measuring tool modification
//under development

if (ParamToggle("Enabled", "No|Yes", 1))
{
  EnableTextOutput(False);
  
  what = ParamList("Object", "Bar count", 0);
  mColor = ParamColor("Color", colorRed);
  mStyle = ParamStyle("Style", styleLine | styleDashed, styleDashed | styleThick);
  mbgColor = ParamColor("Label Bg Color", colorWhite);
  showInTitle = ParamToggle("Show in title", "No|Yes", 1);
  
  SelectedBar = SelectedValue(BarIndex());
  StartRangeBar = BeginValue(BarIndex());
  FinishRangeBar = EndValue(BarIndex());
  
  // determine start & end of range
  if (StartRangeBar > 0 AND FinishRangeBar < BarCount - 1) // range defined by markers
  {
    start = StartRangeBar;
    end = FinishRangeBar;
  }
  else
  {
    if (StartRangeBar > 0) // range defined by start marker & selection
    {
      start = StartRangeBar;
      end = SelectedBar;
    }
    else // range defined by selected bar and end
    {
      start = SelectedBar;
      end = FinishRangeBar;
    }
  }
  if (start > end) { tmp = start; start = end; end = tmp; }
  
  // measuring
  switch (what)
  {
    // bar count
    case "Bar count":
      Value = end - start;
      Label = WriteVal(Value, 1.0);
      if (showInTitle) 
      Title = "\n" + EncodeColor(mColor) + "Measuring bars: " + WriteVal(Value, 1.0);
      break;
      }
    
 
  
  if (start != end)
  {
    // get highest visible value
    Hh = -1e8;
    for (i = Status("firstvisiblebarindex"); i < Status("lastvisiblebarindex") AND i < BarCount; i++)
        
      if (High[i] > Hh) Hh = High[i];
      {
    
    VGrid = (Status("axismaxy") - Status("axisminy")) * 0.01;
    VH = Hh;
    }
    Plot(LineArray(start, VH, end, VH), "", mColor, mStyle | styleNoLabel);
    plotText(Label , start + (end - start) / 2 - 2, VH + VGrid, mColor, mbgColor);
    
   // Plot vertical lines forward and back 
    bi=BarIndex();
    x=start;
    y=end;
        
    conditionback = bi==(x - value);
    conditionforward = bi==(y + value);  
    
    line_style=ParamStyle("Style",styleDashed|stylethick );
    line_color=ParamColor("Vert_Color", colorblack);
    
    Plot(conditionback,"",line_color,stylehistogram|Line_style|styleOwnScale| styleNoLabel);
    Plot(conditionforward,"",line_color,styleHistogram|Line_style|styleOwnScale| styleNoLabel);
    
    
    
    Plot(LineArray(start-value, VH, end+value, VH), "", mColor, mStyle | styleNoLabel);
        PlotText(Label , start - value / 2 - 2, VH + VGrid, mColor, mbgColor);
        PlotText(Label , end + value / 2 - 2, VH + VGrid, mColor, mbgColor);
        
  }
 EnableTextOutput(True);
 }
 
Plot(C,"Close",colorBlack,stylebar);

Anthony