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 ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
trendlines for Amibroker (AFL)
Copy & Paste Friendly
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | // Trendlines AFL code by Edward Pottasch, Mar 2013 xx= BarIndex ();x=xx;Lx= LastValue (x); nbar= Param ( "N Pivot Bars" ,5,2,50,1); npiv= Param ( "number of pivots" ,2,1,5,1); tf= Param ( "Time Frame (min)" ,1,1,10080,1);tfrm= in1Minute *tf; CleanPivots= ParamToggle ( "Filter Pivots" , "No|Yes" ,1); PivotSymmetry= ParamToggle ( "Symmetric Pivots" , "No|Yes" ,0); TimeFrameSet (tfrm); if (PivotSymmetry) { fc=1; pk= H > Ref ( HHV ( H ,nbar*fc),-1) AND Ref ( HHV ( H ,nbar),nbar)<= H ; tr= L < Ref ( LLV ( L ,nbar*fc),-1) AND Ref ( LLV ( L ,nbar),nbar)>= L ; } else { fc=2; pk= H > Ref ( HHV ( H ,nbar*fc),-1) AND Ref ( HHV ( H ,nbar),nbar)<= H ; tr= L < Ref ( LLV ( L ,nbar*fc),-1) AND Ref ( LLV ( L ,nbar),nbar)>= L ; } px0= ValueWhen (pk,x,0); tx0= ValueWhen (tr,x,0); px1= ValueWhen (pk,x,1); tx1= ValueWhen (tr,x,1); px2= ValueWhen (pk,x,2); tx2= ValueWhen (tr,x,2); ph0= ValueWhen (pk, H ,0); tl0= ValueWhen (tr, L ,0); ph1= ValueWhen (pk, H ,1); tl1= ValueWhen (tr, L ,1); ph2= ValueWhen (pk, H ,2); tl2= ValueWhen (tr, L ,2); if (CleanPivots) { pk= IIf ((ph0>=ph1 AND tx0>px0 AND px0!=px1) OR (ph1<ph2 AND px2>tx1) OR (ph0>=ph1 AND tx0<px0 AND tx0==tx1 AND px0!=px1) , False ,pk); tr= IIf ((tl0<=tl1 AND px0>tx0 AND tx0!=tx1) OR (tl1>tl2 AND tx2>px1) OR (tl0<=tl1 AND px0<tx0 AND px0==px1 AND tx0!=tx1) , False ,tr); } pkh= IIf (pk, H , Null );trl= IIf (tr, L , Null ); TimeFrameRestore (); fact= Nz ( Max (tfrm/60, Interval ()/60)/( Interval ()/60)); if (fact==0)fact=1; Lkbk= Nz (tfrm/ Interval ()); if (Lkbk>1) { pk= TimeFrameExpand (pk,tfrm,expandFirst); pkh= TimeFrameExpand (pkh,tfrm,expandFirst); pkhs= IIf (! IsEmpty (pkh),1,0);pkhs=pkhs- Ref (pkhs,-1); pk=pk AND H ==pkh; cond1= Sum (pk, BarsSince (pkhs==1)+1)==1 AND pk; pk=pk AND cond1; tr= TimeFrameExpand (tr,tfrm,expandFirst); trl= TimeFrameExpand (trl,tfrm,expandFirst); trls= IIf (! IsEmpty (trl),1,0);trls=trls- Ref (trls,-1); tr=tr AND L ==trl; cond1= Sum (tr, BarsSince (trls==1)+1)==1 AND tr; tr=tr AND cond1; } SetChartOptions (0, chartShowDates ); SetBarFillColor ( IIf ( C > O , colorBrightGreen , IIf ( C <= O , colorRed , colorLightGrey ))); Plot ( C , "\nPrice" , IIf ( C > O , ColorRGB (0,255,0), IIf ( C <= O , ColorRGB (255,0,0), colorLightGrey )),64,0,0,0,0); PlotShapes ( shapeSmallCircle *tr, colorGreen ,0, L ,-10); PlotShapes ( shapeSmallCircle *pk, colorRed ,0, H ,10); for (i=1;i<=npiv;i++) { y0= ValueWhen (tr, L ,i-1); y1= ValueWhen (tr, L ,i); x0= ValueWhen (tr,xx,i-1); x1= ValueWhen (tr,xx,i); aa=(y0-y1)/(x0-x1); ls1=aa*(xx-x1)+y1; dls1=ls1- Ref (ls1,-1); ls1= IIf (dls1<0, Null ,ls1); if (i==1) Plot (ls1, "" , colorBrightGreen , styleLine | styleNoRescale ,0,0,0,1); if (i>1) { ls1= IIf (tr, Null ,ls1); Plot (ls1, "" , colorDarkGreen , styleNoLine | styleDots | styleThick | styleNoRescale ,0,0,0,1); } y0= ValueWhen (pk, H ,i-1); y1= ValueWhen (pk, H ,i); x0= ValueWhen (pk,xx,i-1); x1= ValueWhen (pk,xx,i); aa=(y0-y1)/(x0-x1); hs1=aa*(xx-x1)+y1; dhs1=hs1- Ref (hs1,-1); hs1= IIf (dhs1>0, Null ,hs1); if (i==1) Plot (hs1, "" , colorRed , styleLine | styleNoRescale ,0,0,0,1); if (i>1) { hs1= IIf (pk, Null ,hs1); Plot (hs1, "" , colorOrange , styleNoLine | styleDots | styleThick | styleNoRescale ,0,0,0,1); } } |