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 ....
ATR ZigZag 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | // ATR ZigZag, Multiple Timeframe // E.M.Pottasch, Nov 2016 Version ( 5.87 ); GfxSetZOrder( -5 ); GfxSetCoordsMode( 1 ); x = BarIndex (); fvb = FirstVisibleValue( x ); lvb = LastVisibleValue( x ); perBull = Param ( "perBull" , 20, 1, 150, 1 ); perBear = Param ( "perBear" , 20, 1, 150, 1 ); multBull = Param ( "multBull" , 2, 1, 4, 0.05 ); multBear = Param ( "multBear" , 2, 1, 4, 0.05 ); tf = Param ( "Time Frame (min)" , 5, 1, 1440 * 10, 1 ); // 1440 minutes is 1 day tfrm = in1Minute * tf; tog2 = ParamToggle ( "Plot Trail" , "No|Yes" , 0 ); tog4 = ParamToggle ( "Show Labels" , "No|Yes" , 1 ); tog7 = ParamToggle ( "Draw Zig Zag" , "No|Yes" , 1 ); fact = Nz ( Max ( tfrm / 60, Interval () / 60 ) / ( Interval () / 60 ) ); function vstop_func() { tvHigh = C ; tvLow = C ; sup = tvHigh - multBull * ATR ( perBull ); res = tvLow + multBear * ATR ( perBear ); // following Trail code is from TJ // http://traders.com/Documentation/FEEDbk_docs/2009/06/TradersTips.html trailARRAY = Null ; trailstop = 0; for ( i = 1; i < BarCount ; i++ ) { if ( C [ i ] > trailstop AND C [ i - 1 ] > trailstop ) trailstop = Max ( trailstop, sup[ i ] ); else if ( C [ i ] < trailstop AND C [ i - 1 ] < trailstop ) trailstop = Min ( trailstop, res[ i ] ); else trailstop = IIf ( C [ i ] > trailstop, sup[ i ], res[ i ] ); trailARRAY[ i ] = trailstop; } return trailARRAY; } TimeFrameSet ( tfrm ); trBull = multBull * ATR ( perBull ); trBear = multBear * ATR ( perBear ); trailArray = vstop_func(); ts = IIf ( trailArray > C , trailArray, Null ); // dntrend tl = IIf ( trailArray < C , trailArray, Null ); // uptrend TimeFrameRestore (); ts = TimeFrameExpand ( ts, tfrm, expandLast ); tl = TimeFrameExpand ( tl, tfrm, expandLast ); lll = LLV ( L , BarsSince ( ! IsEmpty ( tl ) ) ); lll = IIf ( ts, lll, Null ); trm = ts AND L == lll; hhh = HHV ( H , BarsSince ( ! IsEmpty ( ts ) ) ); hhh = IIf ( tl, hhh, Null ); pkm = tl AND H == hhh; tr = ExRem ( Reverse( trm ), Reverse( pkm ) ); pk = ExRem ( Reverse( pkm ), Reverse( trm ) ); tr = Reverse( tr ); pk = Reverse( pk ); for ( i = 0; i < 3; i++ ) { VarSet ( "px" + i, ValueWhen ( pk, x, i ) ); VarSet ( "tx" + i, ValueWhen ( tr, x, i ) ); VarSet ( "ph" + i, ValueWhen ( pk, H , i ) ); VarSet ( "tl" + i, ValueWhen ( tr, L , i ) ); } ll = tr AND tl1 < tl2; hl = tr AND tl1 > tl2; hh = pk AND ph1 > ph2; lh = pk AND ph1 < ph2; dt = pk AND ph1 == ph2; db = tr AND tl1 == tl2; GraphXSpace = 5; SetChartBkColor ( colorBlack ); SetChartOptions ( 1, chartShowDates , chartGridMiddle, 0, 0, 0 ); SetBarFillColor ( IIf ( C > O , ColorRGB ( 0, 75, 0 ), IIf ( C <= O , ColorRGB ( 75, 0, 0 ), colorLightGrey ) ) ); Plot ( C , "" , IIf ( C > O , ColorRGB ( 0, 255, 0 ), IIf ( C <= O , ColorRGB ( 255, 0, 0 ), colorLightGrey ) ), 64, Null , Null , 0, 0, 1 ); PlotShapes ( shapeSmallCircle *trm, ColorRGB ( 0, 30, 0 ), 0, L , -10 ); PlotShapes ( shapeSmallCircle *pkm, ColorRGB ( 50, 0, 0 ), 0, H , 10 ); PlotShapes ( shapeSmallCircle *tr, IIf ( ValueWhen ( trm, x, 1 ) < ValueWhen ( pkm, x, 0 ), ColorRGB ( 0, 255, 0 ), ColorRGB ( 255, 255, 255 ) ), 0, L , -10 ); PlotShapes ( shapeSmallCircle *pk, IIf ( ValueWhen ( pkm, x, 1 ) < ValueWhen ( trm, x, 0 ), ColorRGB ( 255, 0, 0 ), ColorRGB ( 255, 255, 255 ) ), 0, H , 10 ); function drawPivotLabels() { sz = 5; for ( i = lvb; i > fvb; i-- ) { { if ( ll[i] ) { PlotTextSetFont( "LL" , "Arial Black" , sz, i, L [i], colorGreen , colorDefault , -25 ); } if ( hl[i] ) { PlotTextSetFont( "HL" , "Arial Black" , sz, i, L [i], colorGreen , colorDefault , -25 ); } if ( db[i] ) { PlotTextSetFont( "DB" , "Arial Black" , sz, i, L [i], colorLightBlue , colorDefault , -25 ); } if ( hh[i] ) { PlotTextSetFont( "HH" , "Arial Black" , sz, i, H [i], colorRed , colorDefault , 20 ); } if ( lh[i] ) { PlotTextSetFont( "LH" , "Arial Black" , sz, i, H [i], colorRed , colorDefault , 20 ); } if ( dt[i] ) { PlotTextSetFont( "DT" , "Arial Black" , sz, i, H [i], colorOrange , colorDefault , 20 ); } } } } function drawZigZag() { for ( i = lvb; i > fvb; i-- ) { if ( tr[i] ) { GfxSelectPen ( colorOrange , 1 ); GfxMoveTo ( tx1[i], tl1[i] ); GfxLineTo ( px1[i], ph1[i] ); } if ( pk[i] ) { GfxSelectPen ( colorLightBlue , 1 ); GfxMoveTo ( px1[i], ph1[i] ); GfxLineTo ( tx1[i], tl1[i] ); } } } Title = Name () + " | " + Now ( 2 ); if ( tog4 ) drawPivotLabels(); if ( tog7 ) drawZigZag(); if ( tog2 ) { Plot ( ts, "" , colorRed , styleStaircase | styleNoRescale , Null , Null , 0, 0, 1 ); Plot ( lll, "" , colorRed , styleDashed | styleNoRescale , Null , Null , 0, 0, 1 ); Plot ( tl, "" , colorGreen , styleStaircase | styleNoRescale , Null , Null , 0, 0, 1 ); Plot ( hhh, "" , colorGreen , styleDashed | styleNoRescale , Null , Null , 0, 0, 1 ); } |