Automatic Fibonacci Retracement Levels plotted in Amibroker.
This helps a lot to those who are starting in understanding Fibonacci adjustments.
Another aspect is that sometime it gets difficult to choose levels from where
the retracement lines should be plotted.
In this AFL levels can be adjusted through Parameters.
Number of Bars can be chosen and the Fibonacci levels can be adjusted as per
individual preferences.
======================================================================
_SECTION_BEGIN("AA - Fibonacci Retracements and Goals");
///////////////////////////////////////////////////
// **************** Parameters ********************
//
Period = Param("Period", 1, 1, 50);
ShowExt = ParamToggle("Show Extension ?", "No|Yes");
///////////////////////////////////////////////////
// **************** Calculations *****************
//
Period = Period*(13*.618);
Hhb = LastValue(Ref(HHVBars(H, Period), -1))+1;
Llb = LastValue(Ref(LLVBars(L, Period), -1))+1;
Hv = LastValue(Ref(HHV(H, Period), -1));
Lv = LastValue(Ref(LLV(L, Period), -1));
Range = (Hv - Lv);
LText = "0 %, 21.4 %, 38.2 %, 50 %, 61.8 %, 78.6 %, 100 %, 1.618 %, 1.72 %, 200 %";
if(Hhb > Llb)
{
Levels[0] = Lv;
Levels[1]= (Range *.214)+Levels[0];
Levels[2]= (Range *.382)+Levels[0];
Levels[3]= (Range *.5)+Levels[0];
Levels[4]= (Range *.618)+Levels[0];
Levels[5]= (Range *.786)+Levels[0];
Levels[6]= Hv;
Levels[7]= (Range *.618)+Levels[6];
Levels[8]= (Range *.72)+Levels[6];
Levels[9]= (Range )+Levels[6];
x0 = BarCount - 1 - Llb;
x1 = BarCount - 1 - Hhb;
}
else
{
Levels[0]= Hv;
Levels[1]= Levels[0]- (Range *.214);
Levels[2]= Levels[0]- (Range *.382);
Levels[3]= Levels[0]- (Range *.5);
Levels[4]= Levels[0]- (Range *.618);
Levels[5]= Levels[0]- (Range *.786);
Levels[6]= Lv;
Levels[7]= Levels[6]- (Range *.618);
Levels[8]= Levels[6]- (Range *.72);
Levels[9]= Levels[6]- (Range );
x0 = BarCount - 1 - Hhb;
x1 = BarCount - 1 - Llb;
}
//////////////////////////////////////////////////////////////////////////////////////
/// **************************** Plotting Area ********************************
//
Plot(C, "", IIf(C > O, colorBrightGreen, colorRed), ParamStyle("Price Style", styleBar, maskPrice));
for(i=0; i<10; i++)
{
if(i!=6)
x = x0;
else
x = x1;
if(i<7 OR ShowExt)
{
Plot(LineArray(x, Levels[i], BarCount, Levels[i]), "", i+2, styleDots);
PlotText(StrExtract(LText, i), BarCount, Levels[i], i+2);
}
}
Title = FullName()+" - "+Name()+"\nO:"+O+", H:"+H+", L:"+L+", C:"+C;
_SECTION_END();
======================================================================
Which is the standard period to be entered in the parameter menu of amibroker? Is it 5 or 10?
ReplyDeleteSatheesh mukundan.....
Look for a significant high or low made by the price in the near past . This is called the lookback period.
ReplyDeleteChange the parameters accordingly to set to that High or Low . For every chart you will have to adjust to the levels . Significant high or low will have larger effect rather than short term high or low.
Sir.. if I am using 5 min chart, which isthe period tobe entered in the parameters option?
ReplyDeleteSunil...
@ Sunil ,
ReplyDeleteI would suggest you to use Fibonacci levels in an Hourly timeframe even if you are doing Intraday Trading on a 5 Minute Chart.
This is because in a 5 minute chart Fib. levels will not have that much effect to act as resistance or support for long.
In an hourly chart suppose the previous High is at an eight period previous Bar than choose 8 periods through parameter.
If a significant high is at 5 or 6 previous bars then choose the period accordingly. You may go as far back as you may like according to the swing high and swing low levels which you see that such levels are not being broken by the price frequently.
No static level in parameter can be chosen for long as the dynamic nature of mkt. will force the price to make new significant high & lows.
Hi there, thanks for sharing. I am new to AFL / amibroker.
ReplyDeleteHow could I adapt this so that the reference would be a moving average on a different time frame than my chart? (so basically the script could plot the Fibo Retracements/Goals of a 100 hours MA on a 30mins charts for instance)
Thanks!
Hello,
DeleteFibonacci levels are basically plotted from Swing High & Swing Low levels as per the trend in place.
The condition which you are requiring means you need dynamic Fibonacci levels. I am also not sure whether
these conditions could be really met for plotting. If they can be fulfilled then also this will surely need lot of coding.
You may either ask in Trading Forums where some coding experts can be
helpful in prompting you in the right direction or take help with official Amibroker website support team.
One forum I can point you to is www.traderji.com . There some Amibroker coding experts in the Amibroker section of the forum
try to help other members.
Hi Trade Catcher, thank for the reply and the usggestion (I have actually created an account on traderji a few years back but havent been active there)!
ReplyDeleteGiven my limited coding experience in AFL, I think the 1st block defines which bars and levels are used for the calculations. Do you think that, instead of using the closing price of the stock, using the closing price of a MA(c,200) would work? (how could I do that by the way?).
I am not too sure as per why you use a -1 and a +1 in the formula (1st block of code where you find the location adn value of the max & min values), is it possible for you to explicit this a little bit?
What are x0 and x1? (confuses me a bit when reading the block of code on "plotting")
I find your logic to add the fibo line very clear and elegant.
Again, thanks for sharing your code, I think I am learning quite a bit just reading it at the moment (discovering useful functions and understanding the flow)
Hi June,
DeleteI would like to say that the above code is not created by me. This has been just shared by me after I found it through an internet source.
I liked the code for Amibroker users thats why I thought of posting it for my blog readers.
I am myself not into coding at all thats why I thought of suggesting you about the forum. There is another website called
www.wisestocktrader.com which is dedicated to Amibroker formulas and coding etc. , I think you might get help there for
your queries. I am really sorry that coding being Greek to me I could not really be a helping hand in that domain.
Regards.
Aryan.