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 ....
Eds Sup Res 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | _SECTION_BEGIN ( "Price " ); SetBarsRequired (10000,10000); GraphXSpace = 3; SetChartBkColor ( ParamColor ( "Background Colour" , colorWhite )); Plot ( C , "Close" , ParamColor ( "Color" , colorDefault ), styleNoTitle | ParamStyle ( "Style" ) | GetPriceStyle () ); Chartscale= ParamToggle ( "Chart Scale" , "Linear|Logarithmic" ,0); if ( ChartScale == 0 ) SetChartOptions (1, chartShowDates ); else SetChartOptions (1, chartShowDates | chartLogarithmic ); ///// GFX Functions /////// function GetVisibleBarCount() { lvb = Status ( "lastvisiblebar" ); fvb = Status ( "firstvisiblebar" ); return Min ( Lvb - fvb, BarCount - fvb ); } function GfxConvertValueToPixelY( Value ) { local Miny, Maxy, pxchartbottom, pxchartheight; Miny = Status ( "axisminy" ); Maxy = Status ( "axismaxy" ); pxchartbottom = Status ( "pxchartbottom" ); pxchartheight = Status ( "pxchartheight" ); return pxchartbottom - floor ( 0.5+ ( Value - Miny ) * pxchartheight / ( Maxy - Miny ) ); } function GfxConvertValueToPixelYlog( Value ) { local Miny, Maxy, pxchartbottom, pxchartheight; pxchartheight = Status ( "pxchartheight" ); pxchartbottom = Status ( "pxchartbottom" ); Miny = Status ( "axisminy" ); Maxy = Status ( "axismaxy" ); x = log ( Value / Miny ) / log ( Maxy / Miny ); return pxchartbottom - round ( pxchartheight * x); } _SECTION_BEGIN ( "Support and Resistance" ); // AFL code by Edward Pottasch, Jan 2013 procedure alternate_proc(pk,tr,sumpk,sumtr) { global pkg; global trg; pkg=pk;trg=tr; idxpk=0; idxtr=0; flgtr=0; flgpk=0; for (i=1;i< BarCount ;i++) { if (pk[i] AND sumpk[i]==1 AND !tr[i] AND flgpk==0) { idxpk=i; flgtr=0; } else if ( (pk[i] AND sumpk[i]>1 AND !tr[i]) OR (pk[i] AND flgpk==1) ) { if ( H [i]>= H [idxpk]) { pkg[idxpk]=0; idxpk=i; flgpk=0; } else if ( H [i]< H [idxpk]) { pkg[i]=0; flgpk=0; } } else if (tr[i] AND sumtr[i]==1 AND !pk[i] AND flgtr==0) { idxtr=i; flgpk=0; } else if ( (tr[i] AND sumtr[i]>1 AND !pk[i]) OR (tr[i] AND flgtr==1) ) { if ( L [i]<= L [idxtr]) { trg[idxtr]=0; idxtr=i; flgtr=0; } else if ( L [i]> L [idxtr]) { trg[i]=0; flgtr=0; } } else if (pk[i] AND tr[i]) { if (sumpk[i-1]>sumtr[i-1]) { pkg[i]=0; flgtr=1; idxtr=i; } else if (sumtr[i-1]>sumpk[i-1]) { trg[i]=0; flgpk=1; idxpk=i; } } } } procedure calculatePivots(tfrm,PivotSymmetry,nbar,CleanPivots,x) { TimeFrameSet (tfrm); global tr; global pk; global px0; global px1; global px2; global ph0; global ph1; global ph2; global trl; global pkh; global tx0; global tx1; global tx2; global tl0; global tl1; global tl2; global fact; 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); sumpk= Sum (pk, BarsSince (tr));sumtr= Sum (tr, BarsSince (pk)); if (CleanPivots) { alternate_proc(pk,tr,sumpk,sumtr); pk=pkg; tr=trg; 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); px3= ValueWhen (pk,x,3); tx3= ValueWhen (tr,x,3); 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); ph3= ValueWhen (pk, H ,3); tl3= ValueWhen (tr, L ,3); } 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; 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); px3= ValueWhen (pk,x,3); tx3= ValueWhen (tr,x,3); 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); ph3= ValueWhen (pk, H ,3); tl3= ValueWhen (tr, L ,3); } } function displayLines(pk,tr,lnColorRes,lnColorSup,lnWidthRes,lnWidthSup) { pxchartright= Status ( "pxchartright" ); AllVisibleBars=GetVisibleBarCount(); for (i=0;i< BarCount ;i++) { DisplayRes=1; DisplaySup=1; if (pk[i]) { hval= H [i]; for (j=i;j< BarCount ;j++) { if ( H [j]>hval) { DisplayRes=0; break ; } } if (DisplayRes) { x0=i; y0= H [i]; x1= BarCount ; y1= H [i]; Plot ( LineArray (x0,y0,x1,y1,1), "" ,lnColorRes, styleLine | styleNoRescale | styleNoLabel ,0,0,0,0,lnWidthRes); if (Chartscale==0) YPos=GfxConvertValueToPixelY(y1); else YPos=GfxConvertValueToPixelYLog(y1); GfxSetTextAlign (0); GfxSetBkColor ( colorWhite ); GfxSelectFont ( "Tahoma" ,8,650); YValue = StrRight ( NumToStr ( y1, 4.3,0 ), 9 ); GfxSetTextColor ( colorLightGrey ); //GfxTextOut(""+YValue,pxchartright-60,YPos-12); RequestTimedRefresh ( 0.1 ); } } if (tr[i]) { lval= L [i]; for (j=i;j< BarCount ;j++) { if ( L [j]<lval) { DisplaySup=0; break ; } } if (DisplaySup) { x0=i; y0= L [i]; x1= BarCount ; y1= L [i]; Plot ( LineArray (x0,y0,x1,y1,1), "" ,lnColorSup, styleLine | styleNoRescale | styleNoLabel ,0,0,0,0,lnWidthSup); if (Chartscale==0) YPos=GfxConvertValueToPixelY(y1); else YPos=GfxConvertValueToPixelYLog(y1); GfxSetTextAlign (0); GfxSetBkColor ( colorWhite ); GfxSelectFont ( "Tahoma" ,8,650); YValue = StrRight ( NumToStr ( y1, 4.3,0 ), 9 ); GfxSetTextColor ( colorLightGrey ); //GfxTextOut(""+YValue,pxchartright-60,YPos-12); RequestTimedRefresh ( 0.1 ); } } } } xx= BarIndex (); x=xx; Lx= LastValue (x); nbar= Param ( "N Pivot Bars" ,2,2,50,1); CleanPivots= ParamToggle ( "Use Clean Pivots" , "Off|On" ,0); PivotSymmetry= ParamToggle ( "Use Symmetric Pivots" , "Off|On" ,1); WeeklyTF=( Nz ( StaticVarGet ( "ToggleButtonON_104" ))); weeklyLineColorRes= ParamColor ( "WEEKLY Line Color (resistance)" , colorLightGrey ); weeklyLineColorSup= ParamColor ( "WEEKLY Line Color (support)" , colorLightGrey ); weeklyLineWidth= Param ( "WEEKLY Line Width" ,1,1,10,1); // setup for weekly calculatePivots( inWeekly ,PivotSymmetry,nbar,CleanPivots,x); displayLines(pk,tr,weeklyLineColorRes,weeklyLineColorSup,weeklyLineWidth,weeklyLineWidth); _SECTION_END (); |