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 ....
supar 1 for Amibroker (AFL)
Copy & Paste Friendly
Back
sigwd=ParamToggle("sigchange","weekly|daily",1); //HBS mean histogram buy sell and LHBS mean low buy high sell field= ParamToggle("field","fieldd|fieldw",1); font = ParamToggle("font","Show|Hide",1); messageboard = ParamToggle("Message Board","Show|Hide",0); prexplore= ParamToggle("perce/buysell","pers|buysell",1); // Automatic Linear Trend Channel // Trend is defined using an example trend: MA(cp,100) // Amibroker AFL code by Edward Pottasch, November 2011 Factor=Param("Factor",4.2,1,10,0.1); Pd=Param("ATR Periods",4,1,100,1); Up=(H+L)/2+(Factor*ATR(Pd)); Dn=(H+L)/2-(Factor*ATR(Pd)); iATR=ATR(Pd); TrendUp=TrendDown=Null; trend[0]=1; changeOfTrend=0; flag=flagh=0; for (i = 1; i <BarCount-1; i++) { TrendUp[i] = Null; TrendDown[i] = Null; trend[i]=1; if (Close[i]>Up[i-1]) { trend[i]=1; if (trend[i-1] == -1) changeOfTrend = 1; } else if (Close[i]<Dn[i-1]) { trend[i]=-1; if (trend[i-1] == 1) changeOfTrend = 1; } else if (trend[i-1]==1) { trend[i]=1; changeOfTrend = 0; } else if (trend[i-1]==-1) { trend[i]=-1; changeOfTrend = 0; } if (trend[i]<0 && trend[i-1]>0) { flag=1; } else { flag=0; } if (trend[i]>0 && trend[i-1]<0) { flagh=1; } else { flagh=0; } if (trend[i]>0 && Dn[i]<Dn[i-1]){ Dn[i]=Dn[i-1]; } if (trend[i]<0 && Up[i]>Up[i-1]) { Up[i]=Up[i-1]; } if (flag==1) { Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);; } if (flagh==1) { Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);; } if (trend[i]==1) { TrendUp[i]=Dn[i]; if (changeOfTrend == 1) { TrendUp[i-1] = TrendDown[i-1]; changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=Up[i]; if (changeOfTrend == 1) { TrendDown[i-1] = TrendUp[i-1]; changeOfTrend = 0; } } } Plot(TrendUp,"Trend",colorGreen); Plot(TrendDown,"Down",colorRed); Buy = trendup; Sell=trenddown; Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); Short=Sell; Cover=Buy; PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorWhite, colorYellow ) ); PlotShapes( Buy * shapeUpTriangle + Sell * shapeDownTriangle, IIf( Buy, colorWhite, colorYellow ) ); //PlotShapes( Buy * shapeHollowSmallCircle + Sell * shapeHollowSmallCircle, IIf( Buy, colorWhite, colorYellow ) ); PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen); PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite); //PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite); PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed); PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorWhite); //PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNone),colorWhite); PlotShapes(IIf(Short,shapeDownTriangle,shapeNone),colorYellow); PlotShapes(IIf(Short,shapeHollowDownTriangle,shapeNone),colorWhite); //PlotShapes(IIf(Short,shapeHollowCircle,shapeNone),colorWhite); PlotShapes(IIf(Cover,shapeUpTriangle,shapeNone),colorLightBlue); PlotShapes(IIf(Cover,shapeHollowUpTriangle,shapeNone),colorWhite); //PlotShapes(IIf(Cover,shapeHollowCircle,shapeNone),colorWhite); _SECTION_BEGIN("parameters"); sdfact=Param("Standard Deviation Factor",2,0.5,5,0.1); offset=Param("Offset",2,1,50,1); tc=ParamList("Channel Display",List="No Channel|Channel|ChannelRT|Both Channels",1); _SECTION_END(); function getUptrend(cp) { return IIf(cp>MA(cp,100),1,0); } function getDowntrend(cp) { return IIf(cp<=MA(cp,100),-1,0); } // trend definition cp=(H+L)/2; TrendUp=getUptrend(cp); TrendDown=getDowntrend(cp); totalTrend=IIf(TrendUp,TrendUp,TrendDown); dtotalTrend=totalTrend-Ref(totalTrend,-1); vtotalTrend=ValueWhen(dtotalTrend,dtotalTrend); // definition start points up and down trend cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1); cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1); cbull=vtotalTrend>0 AND Ref(vtotalTrend,-1)<0;cbull=Ref(cbull,1);cbull[BarCount-1]=1; cbear=vtotalTrend<0 AND Ref(vtotalTrend,-1)>0;cbear=Ref(cbear,1);cbear[BarCount-1]=1; // definition areas up and down trend nwbull=Ref(Flip(cbull,cbear),-1);nwbear=Ref(Flip(cbear,cbull),-1); xxbull=BarsSince(cbull);xxbull[BarCount-1]=xxbull[BarCount-2]+1; aaabull=LinRegIntercept(cp,xxbull);bbbbull=LinRegSlope(cp,xxbull); daabull=Ref(ValueWhen(cbear,aaabull,0),-1);dbbbull=Ref(ValueWhen(cbear,bbbbull,0),-1); yybull=daabull+dbbbull*(xxbull-1);yybull=IIf(xxbull>Max(offset,1),yybull,Null); wdbull=sdfact*StdErr(cp,xxbull);wdbull=Ref(ValueWhen(cbear,wdbull,0),-1); xxbear=BarsSince(cbear);xxbear[BarCount-1]=xxbear[BarCount-2]+1; aaabear=LinRegIntercept(cp,xxbear);bbbbear=LinRegSlope(cp,xxbear); daabear=Ref(ValueWhen(cbull,aaabear,0),-1);dbbbear=Ref(ValueWhen(cbull,bbbbear,0),-1); yybear=daabear+dbbbear*(xxbear-1);yybear=IIf(xxbear>Max(offset,1),yybear,Null); wdbear=sdfact*StdErr(cp,xxbear);wdbear=Ref(ValueWhen(cbull,wdbear,0),-1); llbull=LinearReg(cp,xxbull);llbull=IIf(xxbull>Max(Offset,1),llbull,Null); llbullp=LinearReg(cp,xxbull)+sdfact*StdErr(cp,xxbull);llbullp=IIf(xxbull>Max(Offset,2),llbullp,Null); llbullm=LinearReg(cp,xxbull)-sdfact*StdErr(cp,xxbull);llbullm=IIf(xxbull>Max(Offset,2),llbullm,Null); llbear=LinearReg(cp,xxbear);llbear=IIf(xxbear>Max(Offset,1),llbear,Null); llbearp=LinearReg(cp,xxbear)+sdfact*StdErr(cp,xxbear);llbearp=IIf(xxbear>Max(Offset,2),llbearp,Null); llbearm=LinearReg(cp,xxbear)-sdfact*StdErr(cp,xxbear);llbearm=IIf(xxbear>Max(Offset,2),llbearm,Null); a=20; _SECTION_BEGIN("HeikenAshiSmoothed"); GraphXSpace=5; //p=45; p = Param("p",50,2,100,1); Om=DEMA(O,p); hm=DEMA(H,p); lm=DEMA(L,p); Cm=DEMA(C,p); HACLOSE=(Om+Hm+Lm+Cm)/4; HaOpen = AMA( Ref( HaClose, -1), 1); HaHigh = Max( Hm, Max( HaClose, HaOpen ) ); HaLow = Min( Lm, Min( HaClose, HaOpen ) ); slope = Param("slope",26,2,100,1); Color20= IIf(LinRegSlope(MA(HaClose,a),slope)<0,colorGreen,colorRed); Plot(MA(HaClose,a),"", color20,styleThick); Color=IIf(Haclose>MA(HaClose,a),colorGreen, colorRed); PlotOHLC( HaOpen, HaOpen, HaClose, HaClose, "" + Name(), Color, styleCandle); _SECTION_END();