Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Fibonacii Trend Break System for Amibroker (AFL)
Moinul
about 2 months ago
Amibroker (AFL)

Rating:
3 / 5 (Votes 2)
Tags:
amibroker

Fibonacii Trend Break System

Indicator / Formula

Copy & Paste Friendly
/**
* 
Author : Nishant Kulkarni
Intraday Fibonacii Trend Break System. This system is based on the double bottom and double top detection technique and fibonacii internal external by David K. 
A line joining two tops when connected together and another line joining bottom line is connected together and when both line extended forms a funnel and 
a break outside gives very strong break out.

It is recomended to have Heikin Ashi plot bellow main price plot as confirmation. Big heikin ashi candles confirm price movement.

Note: Use 1 Hour interval for more stable results.

Disclaimer  Trade with caution. Author does not take any responsibility. The system is to guide traders and does not 
guaranty any performance. The system is used in Indian market condition. For other markets, may need to be altered slightly. However I am personally using this system and booking profit, hence contributing 
this formula for community as give back.

The system also makes use of Fibonacci Internal and External Retracements formula by David K. 
http://www.amibroker.com/library/detail.php?id=1084 

*/

_SECTION_BEGIN("INIT");
   SetChartOptions(0,chartShowArrows|chartShowDates);
   fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
   tchoice=Param("Title Selection ",2,1,2,1);
   PlotCandle = ParamToggle("Plot IHSG Candle", "No,Yes", 0);
_SECTION_END();

_SECTION_BEGIN("Price");
   _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));   
   Plot( C, _DEFAULT_NAME(), colorWhite , styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Index_Compare");
   IndexName = ParamList("IndexName ","COMPOSITE|^NSEBANK|^CNXIT|",0);
   PlotForeign(IndexName,_DEFAULT_NAME(),colorBlue , styleNoTitle | styleOwnScale | styleLine | styleThick );
_SECTION_END();

_SECTION_BEGIN("BBands");
   P = ParamField("Price field",-1);
   Periods = Param("Periods", 15, 2, 100, 1 );
   Width = Param("Width", 2, 0, 10, 0.05 );
   Color = ParamColor("Color", colorLightGrey );
   Style = ParamStyle("Style", styleNoRescale | styleNoTitle | styleNoLabel | styleThick);
   BBTop = BBandTop( P, Periods, Width );
   BBBot = BBandBot( P, Periods, Width );
   BBMiddle = BBBot + ((BBTop-BBBot)/2);
   Plot(BBTop , "BBTop" + _PARAM_VALUES(), Color, Style ); 
   Plot(BBBot, "BBBot" + _PARAM_VALUES(), Color, Style ); 
   Plot(BBMiddle , "BBMiddle" + _PARAM_VALUES(), Color, Style ); 
   
_SECTION_END();

////////////////////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
   fibs = ParamToggle("Plot Fibs","Off|On",1);
   pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
   HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
   pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
   LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
   Back = Param ("Extend Left = 2",1,1,500,1);
   Fwd  = Param("Plot Forward", 0, 0, 500, 1);
   text = ParamToggle("Plot Text","Off|On",1);
   hts  = Param ("Text Shift", -33.5,-50,50,0.10);
   style =ParamStyle("Line Style",styleLine,styleNoLabel);
   x = BarIndex();   
   pRp  = PeakBars( H, pctH, 1) == 0;
   yRp0 = LastValue(ValueWhen( pRp, H, HiLB));
   xRp0 = LastValue(ValueWhen( pRp, x, HiLB));
   pSp  = TroughBars( L, pctL, 1) == 0;
   ySp0 = LastValue(ValueWhen( pSp, L, LoLB));
   xSp0 = LastValue(ValueWhen( pSp, x, LoLB));
   Delta = yRp0 - ySp0;

   function fib(ret) {
      retval = (Delta * ret);
      Fibval = IIf(ret < 1.0 
      AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0 
      AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0 
      AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0 
      AND xSp0 > xRp0, ySp0 + retval, Null)))); 
      return FibVal;
   }

   x0 = Min(xSp0,xRp0)-Back;
   x1 = (BarCount -1);
   //////////////////////////////////////////////////////////////////
   r236 = fib(0.236);   r236I = LastValue (r236,1);
   r382 = fib(0.382);   r382I = LastValue (r382,1);
   r050 = fib(0.50);      r050I = LastValue (r050,1);
   r618 = fib(0.618);   r618I = LastValue (r618,1);
   r786 = fib(0.786);   r786I = LastValue (r786,1);
   e127 = fib(1.27);      e127I = LastValue (e127,1);
   e162 = fib(1.62);      e162I = LastValue (e162,1);
   e200 = fib(2.00);      e200I = LastValue (e200,1);
   e262 = fib(2.62);      e262I = LastValue (e262,1);
   e424 = fib(4.24);      e424I = LastValue (e424,1);
   //////////////////////////////////////////////////////////////////
   p00 = IIf(xSp0 > xRp0,ySp0,yRp0);    p00I = LastValue (p00,1);
   p100 = IIf(xSp0 < xRp0,ySp0,yRp0);    p100I = LastValue (p100,1);
   color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
   color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
   //////////////////////////////////////////////////////////////////
   numbars = LastValue(Cum(Status("barvisible")));
   fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
   //////////////////////////////////////////////////////////////////
   if(fibs==1) {
      Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,styleThick | styleNoRescale | styleNoLabel | styleNoTitle,Null, Null,Fwd);
      Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27, styleThick | styleNoRescale | styleNoLabel | styleNoTitle,Null, Null,Fwd);      
      Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);
      Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",colorWhite,style|styleNoRescale | styleNoLabel | styleDashed,Null, Null,Fwd);      

   }
   //////////////////////////////////////////////////////////////////
   if(text==1) { 
      PlotText(" 0% = " + WriteVal(p00,fraction),    LastValue(BarIndex())-(numbars/hts), p00I  + 0.05, color00);
      PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, colorWhite);
      PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, colorWhite);
      PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, colorWhite);
      PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, colorWhite);
      PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, colorWhite);
      PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
      PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, colorWhite);
      PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, colorWhite);
      PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, colorWhite);
      PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, colorWhite);
      PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, colorWhite);
   }
_SECTION_END();

///////////////////////////////////////////////////////////////////////////////////


_SECTION_BEGIN("Pivot");

   YH = TimeFrameGetPrice("H", inDaily, -1);      // yesterdays high
   YL = TimeFrameGetPrice("L", inDaily, -1);      //            low
   YC = TimeFrameGetPrice("C", inDaily, -1);      //            close
   YO = TimeFrameGetPrice("O", inDaily);         // current day open

   //Normal Pivot
   PP = (YH + YL + YC) / 3;
   R1 = (2 * PP) - YL;
   R2 = PP + (YH - YL);
   R3 = YH + 2*(PP-YL);
   S1 = (2 * PP) - YH;
   S2 = PP - (YH - YL);
   S3 = YL - 2*(YH - PP) ;
   
_SECTION_END();

_SECTION_BEGIN("TITLE");

   //////////////////////////////////////////////////////////////////
   if (tchoice==1 )    {
      _N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} -  {{INTERVAL}}      {{DATE}}    Open:  %g,    High:  %g,    Low:  %g,    Close:  %g    {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1  ) ) ));
   }
   //////////////////////////////////////////////////////////////////WriteVal(HC ,fraction)

   if (tchoice==2 ) {
      Title = EncodeColor(colorWhite)+ Date() + "  Close = " + EncodeColor(colorRed) +Close +
      EncodeColor(colorWhite) + "    Open = " + EncodeColor(colorWhite) + O + 
      EncodeColor(colorWhite) + "    High = " + EncodeColor(5) + H +
      EncodeColor(colorWhite) + "      Low = " + EncodeColor(colorRed) + L +
      EncodeColor(colorWhite) + "    Volume = " + EncodeColor(colorWhite) + V + "\n\n"+
      EncodeColor(colorWhite) + "Pivot Point= " + EncodeColor(colorWhite) + PP +
      EncodeColor(colorWhite) + "    Day's Open= " + EncodeColor(colorWhite) + YO +
      EncodeColor(colorWhite) + "    IHSG = " + EncodeColor(colorWhite) + Foreign("COMPOSITE","C") +"\n\n"+
      EncodeColor(colorRed) + "R1= " + EncodeColor(colorWhite) + R1 +
      EncodeColor(colorRed) + "  R2= " + EncodeColor(colorWhite) + R2 +
      EncodeColor(colorRed) + "  R3= " + EncodeColor(colorWhite) + R3 +"\n"+
      EncodeColor(colorGreen) + "S1= " + EncodeColor(colorWhite) + S1 +
      EncodeColor(colorGreen) + "  S2= " + EncodeColor(colorWhite) + S2 +
      EncodeColor(colorGreen) + "  S3= " + EncodeColor(colorWhite) + S3 +"\n"+
      EncodeColor( colorWhite) +"_______________"+"\n"+
      //EncodeColor( colorWhite)  + "424%  =  "   +    EncodeColor(25)+ e424 + " " +"\n"+
      //EncodeColor( colorWhite)  + "262%  =  "   +    EncodeColor(47)+ e262 + " " +"\n"+
      //EncodeColor( colorWhite)  + "200%  =  "   +    EncodeColor(47)+ e200 + " " +"\n"+
      //EncodeColor( colorWhite)  + "162%  =  "   +    EncodeColor(47)+ e162 + " " +"\n"+
      //EncodeColor( colorWhite)  + "127%  =  "   +    EncodeColor(47)+ e127 + " " +"\n"+
      //EncodeColor( colorRed) + "Res    =  "   +    EncodeColor(32)+ p100 + " "+"\n"+
      //EncodeColor( colorWhite)  + "78%  =  "   +   EncodeColor(42)+ r786 + " " +"\n"+
      //EncodeColor( colorWhite)  + "62%  =  "   +    EncodeColor(43)+ r618 + " "+"\n"+
      //EncodeColor( colorWhite)  + "50%  =  "   +    EncodeColor(41)+ r050 + " "+"\n"+
      //EncodeColor( colorWhite)  + "38%  =  "   +    EncodeColor(44)+ r382 + " "+"\n"+
      //EncodeColor( colorWhite)  + "23%  =  "   +    EncodeColor(45)+ r236+ " " +"\n"+
      EncodeColor( colorGreen) + "Sup  =  "   +    EncodeColor(34)+ p00 + " " ;
   }

_SECTION_END();

_SECTION_BEGIN("Up Trend Line");
   UTValue1=LastValue(Trough(L,1,2));   
   UTValue2=ySp0; 
   UTBar1=BarCount - 1 - LastValue(TroughBars(L,1,2)); 
   price_utbar1=Close[UTBar1];
   UTBar2=xSp0; 
   price_utbar2=Close[UTBar2];
   UpTrendLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 1 );
   UTLine = LineArray( UTBar1, UTValue1, UTBar2,UTValue2, 0 );   
   Plot( UpTrendLine , _DEFAULT_NAME(), colorGreen,styleDots | styleNoTitle | styleNoLabel); 

   Plot( UTLine , _DEFAULT_NAME(), colorGreen,styleDots | styleNoTitle | styleNoLabel); 
_SECTION_END();


_SECTION_BEGIN("Down Trend Line");
   DTValue1=LastValue(Peak(H,1,2)); 
   DTValue2=yRp0; 
   DTBar1=BarCount - 1 - LastValue(PeakBars(H,1,2));    
   price_dtbar1=Close[DTBar1];
   DTBar2=xRp0; 
   price_dtbar2=Close[DTBar2];
   DownTrendLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 1 );
   DTLine = LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 0 );

   Plot( DownTrendLine ,_DEFAULT_NAME(), colorRed,styleDots | styleNoTitle | styleNoLabel); 
   Plot( DTLine ,_DEFAULT_NAME(), colorRed,styleDots | styleNoTitle | styleNoLabel);

   PlotOHLC( DownTrendLine , DownTrendLine , UpTrendLine , UpTrendLine , "", colorDarkGrey, styleCloud | styleNoRescale);   
   
   DTLine = LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back);
   UTLine = LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back);
   
   
   CBuy = Cross(C,DownTrendLine );
   CSell = Cross(UpTrendLine ,C);

   baratcbuy = LastValue(ValueWhen(CBuy,BarIndex()));   
   baratcsell = LastValue(ValueWhen(CSell,BarIndex()));

   CBuy = CBuy AND BarIndex() == baratcbuy ;
   CSell = CSell AND BarIndex() == baratcsell ;

   PlotShapes(shapeUpTriangle* CBuy ,colorBlue,O,L);
   PlotShapes(shapeDownTriangle* CSell ,colorRed,O,H);

   CBuy1 = Cross(C,DTLine );
   CSell1 = Cross(UTLine ,C);
   
   baratcbuy1 = LastValue(ValueWhen(CBuy1,BarIndex()));   
   baratcsell1 = LastValue(ValueWhen(CSell1,BarIndex()));

   CBuy1 = CBuy1 AND BarIndex() == baratcbuy1 ;
   CSell1 = CSell1 AND BarIndex() == baratcsell1 ;

   PlotShapes(shapeHollowUpTriangle* CBuy1 ,colorBlue,O,L-1);
   PlotShapes(shapeHollowDownTriangle* CSell1 ,colorRed,O,H-1);

_SECTION_END();


_SECTION_BEGIN("Auto");

   ScanLookBack = Param("Scan Lookback", 1, 1, 25 );
   Buy  = ( CBuy OR CBuy1) AND  ( (BarCount - baratcBuy )<=ScanLookBack  OR (BarCount - baratcbuy1 )<=ScanLookBack); 
   Sell = ( CSell OR CSell1) AND  ( (BarCount - baratcsell )<=ScanLookBack  OR (BarCount - baratcsell1 )<=ScanLookBack ) ;

   price = C[BarCount-1];

   AlertIf(Buy,"","Buy @"+C+"  Price @ Trigger="+price,1);
   AlertIf(Sell,"","Sell @"+C+"  Price @ Trigger="+price,2);

   Filter =  Buy OR Sell ;

   Var = WriteIf(Buy,"BUY",WriteIf(Sell,"SELL",""));

   AddTextColumn( Var , "Buy/Sell", 1.2 , colorWhite, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));   
   AddColumn(price ,"Price",1.2,colorWhite, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
   AddColumn(C ,"Price @ Trigger",1.2,colorWhite, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));

   stoploss = IIf(Buy, (price  * (1-0.01)) , IIf(Sell, (price  * (1+0.01)),0));
   target1per = IIf(Buy, (price  * (1+0.01)) , IIf(Sell, (price  * (1-0.01)),0));
   target15per = IIf(Buy, (price  * (1+0.015)) , IIf(Sell, (price * (1-0.015)),0));
   target2per = IIf(Buy, (price  * (1+0.02)) , IIf(Sell, (price  * (1-0.02)),0));
   
   AddColumn(stoploss ,"Stop Loss",1.2,colorWhite, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
   AddColumn(target1per ,"1% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
   AddColumn(target15per ,"1.5% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
   AddColumn(target2per ,"2% Target",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));
   AddColumn(V ,"Volume",1.2,colorBlack, IIf( Buy, colorLime, IIf(Sell,colorOrange,colorWhite) ));   
   
  
_SECTION_END();
GraphXSpace = 10; 

0 comments

Leave Comment

Please login here to leave a comment.

Back