Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
TSL & Chandelier Exit for Amibroker (AFL)
Is a Trailing Stop Loss. A combination between TSL Chandelier Style and
TSL Metastock Style.
Screenshots
Indicator / Formula
// CHANDELIER EXIT //LISTING 1 Version(5.20); // requires v5.20 SetBarsRequired(sbrAll); // get start date //Start = Cross( DateNum(), ParamDate("Start date", "2000-01-04" ) ); Start = Cross(MACD(),Signal()) ; Started = Flip( Start, 0 ); //StopMode = ParamList("Stop Mode", "Fixed|Chandelier|Modified ATR" ); //StopMode = ParamList("Stop Mode", "Chandelier|Modified ATR|Fixed" ); StopMode = ParamList("Stop Mode", "Chandelier" ); //StopLevel = Param("FixedPerc %", 3, 0.1, 50, 0.1)/100; //StopATRFactor = Param("ATRmultiple", 2, 0.5, 10, 0.1 ); StopATRPeriod = Param("ATRperiod", 5, 3, 50 ); //StopATRFactorRes = Param("kATRres", 3, 0.1, 10, 0.1 ); //StopATRFactorSup = Param("kATRsup", 3, 0.1, 10, 0.1 ); LkBkPer= Param ("LkBkPer",10,1,20,1); // calculate support and resistance levels if( StopMode == "Fixed" ) // fixed percent trailing stop { sup = C * ( 1 - stoplevel ); res = C * ( 1 + stoplevel ); } else // Chandelier ATR-based stop if( StopMode == "Chandelier" ) { //sup = C - StopATRFactor * ATR( StopATRPeriod ); //ORIGINAL //res = C + StopATRFactor * ATR( StopATRPeriod ); //ORIGINAL //sup = C - StopATRFactorSup * ATR( StopATRPeriod ); //res = C + StopATRFactorRes * ATR( StopATRPeriod ); //Chandelier Exit (long) = 22-day High - ATR(22) x 3 ; //TEORIA CHUCK LEBEAU //Chandelier Exit (short) = 22-day Low + ATR(22) x 3 ; //TEORIA CHUCK LEBEAU //MSupp= (LLV(HHV(H,ATRper)-ATR(ATRper),LkBkPer)) ; //STIL METASTOCK //MRes= (HHV(LLV(L,ATRper)+ATR(ATRper),LkBkPer)) ; //STIL METASTOCK sup= (LLV(HHV(H,StopATRPeriod)-ATR(StopATRPeriod),LkBkPer)) ; //STIL METASTOCK res= (HHV(LLV(L,StopATRPeriod)+ATR(StopATRPeriod),LkBkPer)) ; //STIL METASTOCK } else { HL = H - L; MAHL = 1.5 * MA( HL, StopATRPeriod ); HiLo = IIf( HL < MAHL, HL, MAHL ); H1 = Ref( H, -1 ); L1 = Ref( L, -1 ); C1 = Ref( C, -1 ); Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 ); Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 ); diff1 = Max( HiLo, HRef ); diff2 = Max( diff1, LRef ); ATRmod = Wilders( diff2, StopATRPeriod ); sup = C - StopATRFactor * ATRmod ; res = C + StopATRFactor * ATRmod ; } // calculate trailing stop line CHtrailARRAY = Null; CHtrailstop = 0; for( i = 1; i < BarCount; i++ ) { if( Started[ i ] == 0 ) continue; if( C[ i ] > CHtrailstop AND C[ i - 1 ] > CHtrailstop ) CHtrailstop = Max( CHtrailstop, sup[ i ] ); else if( C[ i ] < CHtrailstop AND C[ i - 1 ] < CHtrailstop ) CHtrailstop = Min( CHtrailstop, res[ i ] ); else CHtrailstop = IIf( C[ i ] > CHtrailstop, sup[ i ], res[ i ] ); CHtrailARRAY[ i ] = CHtrailstop; } CHtrailcol= IIf(C>=CHtrailARRAY,colorBlue,colorRed) ; Plot( CHtrailARRAY,"\nChandelierMY", CHtrailcol, styleLine+styleThick ); // generate buy/sell signals based on crossover with trail stop line /* Buy = C>CHtrailArray ; Sell = CHtrailArray>C ; Buy= ExRem(Buy,Sell) ; Sell= ExRem(Sell,Buy) ; PlotShapes(Buy*shapeUpArrow,colorBlue,0,trailarray); PlotShapes(Sell*shapeDownArrow,colorRed,0,trailarray); */ //Plot( Close,"Price",colorBlack,styleBar); //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HEIKIN ASHI EXACT FORMULA DERZI BEGIN DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD _SECTION_BEGIN("HA Looping ( no AMA() )"); SetChartOptions(0,chartShowArrows|chartShowDates); /////////////////////////////////////////////////////////// // // Heikin Ashi - Calculated Properly with no use of AMA // // JF Derzi, December 2012 // // HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4; HaOpen[0] = (HaClose[0] + Open[0]) / 2; HaHigh[0] = Max( High[0], Max( HaClose[0], HaOpen[0] ) ); HaLow[0] = Min( Low[0], Min( HaClose[0], HaOpen[0] ) ); for (i=1; i<BarCount; i++) { HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4; Haopen[i] = (HaClose[i-1] + HaOpen[i-1]) / 2; // Here is the problem when using Arrays: Haopen always uses its own previous value HaHigh[i] = Max( High[i], Max( HaClose[i], HaOpen[i] ) ); Halow[i] = Min( Low[i], Min( HaClose[i], HaOpen[i] ) ); } //PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "HA", colorBlack, styleCandle ); barcolorha = IIf(HaClose>=HaOpen,colorGreen,colorRed); SetBarFillColor(IIf(HaClose>=HaOpen,colorBrightGreen,colorOrange)); PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikinAshiDerzi", barcolorha, styleCandle ); //Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+" / HaHigh:"+NumToStr(HaHigh,1.2,True)+ // " / HaLow:"+NumToStr(Halow,1.2,True)+" HaClose:"+NumToStr(Haclose,1.2, True); _SECTION_END(); HAup= HaClose>=HaOpen ; haDelta= HaClose-HaOpen ; MA3haDelta= MA(haDelta,3) ; haDeltaUpMA3= Hadelta>MA(Hadelta,3) ; MyHAup= (Hadelta>MA(Hadelta,3) OR MA(Hadelta,3)>0) ; haDeltaUp0= haDelta>0 ; //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HEIKIN ASHI EXACT FORMULA DERZI END DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD //PRICE _SECTION_BEGIN("Price"); //SetChartOptions(0,chartShowArrows|chartShowDates); _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, "", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); //barcolorc= IIf(C>O AND C>Ref(C,-1), colorBlue, // IIf(C<O AND C<Ref(C,-1), colorRed, colorTan)); //MODEL MODEL MODEL 3 CULORI //SetBarFillColor( IIf(C>O AND C>Ref(C,-1), colorBrightGreen, // IIf(C<O AND C<Ref(C,-1), colorOrange, colorTan))); //MODEL MODEL MODEL 3 CULORI //Plot( C, "", barcolorc, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); //Plot( C, "", barcolorc, styleBar+styleThick ); _SECTION_END(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //SetBarFillColor( colorYellow ); //Plot( trailARRAY,"trailing stop level", colorRed, styleLine ); //Plot( trailARRAY,"trailing stop level", colorRed, 8+16 ); //trailcol= IIf(C>=trailARRAY,colorBlue,colorRed) ; //Plot( trailARRAY,"\nTSL", colorBlue, styleLine+styleThick ); //Plot( trailARRAY,"\nTSL", trailcol, styleLine+styleThick ); //Plot( trailARRAY,"\nChandelier", trailcol, 8+16 ); //Plot( trailARRAY,"\nChandelierHHV(C)&LLV(C)", trailcol, styleLine+styleThick ); //Buy = C>trailArray ; //Sell = trailArray>C ; //Buy= ExRem(Buy,Sell) ; //Sell= ExRem(Sell,Buy) ; //PlotShapes(Buy*shapeUpArrow,colorBlue,0,trailarray); //PlotShapes(Sell*shapeDownArrow,colorRed,0,trailarray); CpCh= C>CHtrailArray ; VdCh= C<CHtrailArray ; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //TRENDING RIBBON // Paste the code below to your price chart somewhere and green ribbon means both // both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX // are both trending down. _SECTION_BEGIN("trending ribbon"); uptrend= (PDI()>MDI() AND MACD()>Signal()) ; downtrend=MDI()>PDI() AND Signal()>MACD(); Plot( 3, /* defines the height of the ribbon in percent of pane width */"", IIf(uptrend ,colorBrightGreen,IIf(downtrend ,colorRed,colorTan)),styleOwnScale|styleArea|styleNoLabel,-0.5,100 ); _SECTION_END(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //GRAPHIC MODIFIED BULL&BEAR VOLUME CHYNTHIA _SECTION_BEGIN("BullBearVolume"); C1 = Ref(C, -1); uc = C > C1; dc = C <= C1; ud = C > O; dd = C <= O; green = 1; blue = 2; yellow = 3; red = 4; white = 5; VType = IIf(ud, IIf(uc, green, yellow), IIf(dd, IIf(dc, red, blue), white)); gv = IIf(VType == green, V, 0); yv = IIf(VType == yellow, V, 0); rv = IIf(VType == red, V, 0); bv = IIf(VType == blue, V, 0); uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */ dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */ /* create moving average period parameters */ VolPer = Param("Adjust Vol. MA per.", 21, 1, 255, 1); ConvPer = Param("Adjust Conv. MA per.", 7, 1, 255, 1); /* create triple exponential moving avearges of separate up and down volume moving averages */ MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1); MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1); MAtv = TEMA(V, VolPer );//total volume /* Switch for Horizontal lines indicating current level of positive and negative volume for ease in comparing to past highs/lows - toggle via parmameter window */ OscillatorOnly = Param("ShowOscillatorOnly", 0, 0, 1, 1); CompareBullVolume = Param("ShowBullLevel", 1, 0, 1, 1); if(CompareBullvolume AND !OscillatorOnly){ //Plot(SelectedValue(MAuv), "", colorGreen, styleLine); } CompareBearVolume = Param("ShowBearLevel", 1, 0, 1, 1); if(CompareBearVolume AND !OscillatorOnly){ //Plot(SelectedValue(MAdv), "", colorRed, styleLine); } /* Volume Segment Switches - toggle via parameter window */ bullvolume = Param("ShowBullVolume", 1, 0, 1, 1); bearvolume = Param("ShowBearVolume", 1, 0, 1, 1); totalvolume = Param("ShowTEMA(TotalVolume)", 1, 0, 1, 1); /* plot volume lines and histograms if toggled on: */ bearToFront = Param("ShowBearVolinFront", 0, 0, 1, 1); if(bearToFront AND !OscillatorOnly){ //Plot(MAdv, "", colorRed, styleNoLabel); } if(bullvolume AND !OscillatorOnly){ //Plot(MAuv, "AverageBullVolume", colorGreen, styleThick+styleNoLabel); } if(bearvolume AND !OscillatorOnly){ //Plot(MAdv, "AverageBearVolume", colorRed, styleThick+styleNoLabel); } if(bearvolume AND !OscillatorOnly){ //Plot(MAdv, "", colorOrange, styleNoLabel); //PlotOHLC( 0 , MAdv , 0 , MAdv , "", colorOrange, styleCloud | styleNoRescale|styleNoLabel); } if(bullvolume AND !OscillatorOnly){ //Plot(MAuv, "", colorLime, styleNoLabel); //PlotOHLC( 0 , MAuv , O ,MAuv , "", colorLime, styleCloud | styleNoRescale|styleNoLabel); } if(totalVolume AND !OscillatorOnly){ //Plot(MAtv, "TEMA(TotalVolume)", colorLightBlue ); //PlotOHLC( 0 , MAtv , 0 , MAtv , "", colorLightBlue, styleCloud | styleNoRescale|styleNoLabel); } /* Buy=Cross(MAuv,MAdv); Sell=Cross(MAdv,MAuv); PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBlue); PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed); Filter=Buy OR Sell; Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); */ //AddColumn(Close,"Close");AddColumn(Volume,"Total Volume");AddColumn(Buy,"Buy"); AddColumn(Sell,"sell"); /* better visibility of zero line: */ //Plot(0, "", colorViolet, 1); /* Rise/Fall Convergence variables: */ Converge = (TEMA(MAuv - MAdv, ConvPer)); Converge1 = Ref(Converge, -1); ConvergeUp = Converge > Converge1; ConvergeOver = Converge > 0; rising = ConvergeUp AND ConvergeOver; falling = !ConvergeUp AND ConvergeOver; /* Rise/Fall Convergence Oscillator Switch - toggle via parameter window - (provides a better view of resulting combination of battling bull/bear volume forces) */ convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1); if(convergenceOscillator OR OscillatorOnly){ //Plot(Converge, "AmimalsWar", colorBrown, 1|styleLeftAxisScale|styleNoLabel|styleThick); //Plot(0,"", colorViolet, 1|styleLeftAxisScale|styleNoLabel); } /******************************************************** Convergence Rise/Fall Shadows: (provides a more easily visible display of rising and falling bull/bear volume convergence) - toggle via parameter window -posiitive Volume exceeding negative Volume: Light shadow -negative volume exceeding positive volume: dark shadow -if you use standard gray background - best shadows are: -my greys: 14 = (216, 216, 216); 15 = (168, 168, 168)); -best substitute? using AB color constants? -light: colorpalegreen; dark: colorRose;? -(depends on your color scheme - customize to your tastes) **********************************************************/ /* uncomment if you use my custom color greys: */ riseFallColor = IIf(rising, colorLime,colorOrange); //my custom shadow greys /* comment out if you use my custom color gray shadows: */ /* riseFallColor = IIf(rising, colorPaleGreen,colorRose); */ /* Rise/Fall Convergence Plot Switch - toggle via parameter window */ riseFallShadows = Param("ShowRiseFallShadows", 0, 0, 1, 1); if(riseFallShadows){ //Plot(IIf(rising OR falling, 1, 0), "", riseFallColor, styleArea|styleOwnScale|styleNoLabel); } GraphXSpace = 0.5; _SECTION_END(); /* _SECTION_BEGIN("Background"); SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack)); tchoice=Param("Title Selection ",2,1,2,1); _SECTION_END(); */ CpBullV= MAuv>MAdv ; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //FORMULE stochup= StochK()>StochD() ; stoch80= StochK()<80 ; MACDup= MACD()>Signal() ; MACDup0= MACD()>0 ; Hist= MACD()-Signal() ; Histup= Hist>Ref(Hist,-1) ; MFIupMA7= MFI()>MA(MFI(),7) ; MFI30= MFI()>30 ; MFI50= MFI()>50 ; MFI80= MFI()<80 ; RSIupMA7= RSI()>MA(RSI(),7) ; RSIup50= RSI()>50 ; Cupo= C>O ; MA10up= MA(C,10)>=Ref(MA(C,10),-1) ; MA20up= MA(C,20)>=Ref(MA(C,20),-1) ; EMA50up= EMA(C,50)>=Ref(EMA(C,50),-1) ; CupEMA50= C>EMA(C,50) ; Cupma20= C>MA(C,20) ; PDIupmdi= PDI()>MDI() ; PDIup20= PDI()>20 ; UpTrend= (MACD()>Signal() AND PDI()>MDI()) ; CCIup0= CCI()>0 ; CCI200= CCI()<200 ; top2up= BBandTop(C,15,2)>=Ref(BBandTop(C,15,2),-1) ; Cuptop1= C>BBandTop(C,20,1) ; HAup= HaClose>=HaOpen ; upbar = H>=Ref(H,-1) AND L>Ref(L,-1); downbar = L<=Ref(L,-1) AND H<Ref(H,-1); ADXup20= ADX()>20 ; Lim= (ADX()>15 AND ADX()<45 AND CCI()<250 AND MFI()<85) ; PriceUp= (C>O AND HaClose>=HaOpen AND Hadelta>MA(haDelta,3) ) ; UpV= (MAuv>MAdv AND MFI()>MA(MFI(),7)) ; DownV= (MAuv<MAdv AND MFI()<MA(MFI(),7)) ; UpORV= (MAuv>MAdv OR MFI()>MA(MFI(),7)) ; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //PARAMTOGGLE // This combines indicators into one timing Signal //function ParamOptimize( description, default, minv, maxv, step ) // { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); } tgl = ParamToggle("Result", "AND logic|Compare"); // switch test calculation and compare the results if(tgl) { myBuy = CpCh AND haup ; myShort = VdCh AND !haup ; } else { myBuy = IIf( C>CHtrailArray AND HaClose>=HaOpen ,1,0); myShort = IIf( C<CHtrailArray AND HaClose<HaOpen ,1,0); } Buy = ExRem(myBuy, myShort); Sell = ExRem(myShort, myBuy); //PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10); //PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10); //PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,trailArray); //PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,trailArray); //PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-10); //PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,High,Offset=-10); StrongBuy = Buy AND Cross(MACD(),Signal()) AND stochup AND priceup AND mfiupma7 OR Buy AND Cross(C,CHtrailArray) AND macdup AND stochup AND priceup AND mfiupma7 ; MediumBuy = Buy AND macdup AND stochup AND priceup AND uporv ; WeakBuy = Buy ; StrongSell = Sell AND Cross(Signal(),MACD()) AND !stochup OR Sell AND Cross(80,StochK()) AND !macdup AND !stochup OR Sell AND Cross(CHtrailArray,C) AND !macdup AND !stochup ; MediumSell = Sell AND !macdup AND !stochup ; WeakSell = Sell ; PlotShapes(IIf(StrongBuy,shapeUpTriangle,shapeNone),colorBlue,0,haLow,Offset=-10); PlotShapes(IIf(MediumBuy,shapeUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10); PlotShapes(IIf(WeakBuy,shapeHollowUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10); PlotShapes(IIf(StrongSell,shapeDownTriangle,shapeNone),colorRed,0,haHigh,Offset=-10); PlotShapes(IIf(MediumSell,shapeDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10); PlotShapes(IIf(WeakSell,shapeHollowDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10); /* PlotShapes(IIf(StrongBuy,shapeUpTriangle,shapeNone),colorBlue,0,Low,Offset=-10); PlotShapes(IIf(MediumBuy,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-10); PlotShapes(IIf(WeakBuy,shapeHollowUpArrow,shapeNone),colorBlue,0,Low,Offset=-10); PlotShapes(IIf(StrongSell,shapeDownTriangle,shapeNone),colorRed,0,High,Offset=-10); PlotShapes(IIf(MediumSell,shapeDownArrow,shapeNone),colorRed,0,High,Offset=-10); PlotShapes(IIf(WeakSell,shapeHollowDownArrow,shapeNone),colorRed,0,High,Offset=-10);
9 comments
Leave Comment
Please login here to leave a comment.
Back
Very nice
COULD U PLEASE EXPLAIN WHAT “THIN SOLID ARROW, HOLLOW THIN ARROW” INDICATES. SOLID ARROW INDICATES BUY/SELL IT IS CLEAR. THS FOR THIS AFL.
See 416-425 lines in the formula.
pl explain me how its works
On my amibroker I can only see the upper signals part. Not the lower MACD signals part. Why is it so. Please reply
morgen the creator of the formula please reply as soon as possible for my problem. As I couldn’t see the MACD diagram signals on my amibroker.
I am using amibroker version 5.90
My formula is not about MACD, is only about TSL&ChandelierExit.
but morgen sir the pic you posted for reference purpose is showing MACD CROSSOVER too which is confirming the buy and sell signal given in candles.
have u additionally added another afl code to it???
Good!