Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Ichimoku Cloud with Trendline for Amibroker (AFL)
It is an Ichimoku cloud indicator plus trendlines for better signals to buy or sell.
Similar Indicators / Formulas
Indicator / Formula
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 | // E.M.Pottasch, 9/20/2010 // using fractals for trendlines // Version 6a: // each trendline has 3 segments, see explanations // between code. Segments are not combined because // some trendlines partially overlap SetBarsRequired ( sbrAll , sbrAll ); xx = Cum (1); nbar = Param ( "nbar" ,5,2,50,1); // define fractals PHigh = H > Ref ( HHV ( H ,nbar),-1) AND Ref ( HHV ( H ,nbar),nbar) <= H ; PHighPrice = ValueWhen (PHigh, H ); PLow = L < Ref ( LLV ( L ,nbar),-1) AND Ref ( LLV ( L ,nbar),nbar) >= L ; PLowPrice = ValueWhen (PLow, L ); // lower trendline, segment 1: between fractal points startval_L = ValueWhen (PLow, L ,1); endval_L = ValueWhen (PLow, L ,0); startbar_L = ValueWhen (PLow,xx,1); endbar_L = ValueWhen (PLow,xx,0); aa_L = (endval_L-startval_L)/(endbar_L-startbar_L); bb_L = startval_L; trendline_L = aa_L * (xx - startbar_L) + bb_L; // slope calculations for display purpose only dtrendline_L = trendline_L - Ref (trendline_L,-1); // lower extended trendline, segment 2: extend segment 1 to next fractals pivot startval_L_extend = ValueWhen (PLow, L ,2); endval_L_extend = ValueWhen (PLow, L ,1); startbar_L_extend = ValueWhen (PLow,xx,2); endbar_L_extend = ValueWhen (PLow,xx,1); aa_L_extend = (endval_L_extend-startval_L_extend)/(endbar_L_extend-startbar_L_extend); bb_L_extend = startval_L; trendline_L_extend = aa_L_extend * (xx - startbar_L) + endval_L_extend; // slope calculations for display purpose only dtrendline_L_extend = trendline_L_extend - Ref (trendline_L_extend,-1); dtrendline_L_extend = IIf (PLow, Ref (dtrendline_L,-1),dtrendline_L_extend); // lower extended trendline, segment 3: extend segment 2 nbars past the fractal pivot startval_L_extend2 = ValueWhen (PLow, L ,3); endval_L_extend2 = ValueWhen (PLow, L ,2); startbar_L_extend2 = ValueWhen (PLow,xx,3); endbar_L_extend2 = ValueWhen (PLow,xx,2); aa_L_extend2 = (endval_L_extend2-startval_L_extend2)/(endbar_L_extend2-startbar_L_extend2); bb_L_extend2 = endval_L_extend2; trendline_L_extend2 = aa_L_extend2 * (xx - endbar_L_extend2) + endval_L_extend2; // slope calculations for display purpose only dtrendline_L_extend2 = trendline_L_extend2 - Ref (trendline_L_extend2,-1); dtrendline_L_extend2 = IIf (PLow, Ref (dtrendline_L_extend,-1),dtrendline_L_extend2); // upper trendline, segment 1: between fractal points startval_H = ValueWhen (PHigh, H ,1); endval_H = ValueWhen (PHigh, H ,0); startbar_H = ValueWhen (PHigh,xx,1); endbar_H = ValueWhen (PHigh,xx,0); aa_H = (endval_H-startval_H)/(endbar_H-startbar_H); bb_H = startval_H; trendline_H = aa_H * (xx - startbar_H) + bb_H; // slope calculations for display purpose only dtrendline_H = trendline_H - Ref (trendline_H,-1); // upper extended trendline, segment 2: extend segment 1 to next fractals pivot startval_H_extend = ValueWhen (PHigh, H ,2); endval_H_extend = ValueWhen (PHigh, H ,1); startbar_H_extend = ValueWhen (PHigh,xx,2); endbar_H_extend = ValueWhen (PHigh,xx,1); aa_H_extend = (endval_H_extend-startval_H_extend)/(endbar_H_extend-startbar_H_extend); bb_H_extend = startval_H; trendline_H_extend = aa_H_extend * (xx - startbar_H) + endval_H_extend; // slope calculations for display purpose only dtrendline_H_extend = trendline_H_extend - Ref (trendline_H_extend,-1); dtrendline_H_extend = IIf (PHigh, Ref (dtrendline_H,-1),dtrendline_H_extend); // upper extended trendline, segment 3: extend segment 2 nbars past the fractal pivot startval_H_extend2 = ValueWhen (PHigh, H ,3); endval_H_extend2 = ValueWhen (PHigh, H ,2); startbar_H_extend2 = ValueWhen (PHigh,xx,3); endbar_H_extend2 = ValueWhen (PHigh,xx,2); aa_H_extend2 = (endval_H_extend2-startval_H_extend2)/(endbar_H_extend2-startbar_H_extend2); bb_H_extend2 = endval_H_extend2; trendline_H_extend2 = aa_H_extend2 * (xx - endbar_H_extend2) + endval_H_extend2; // slope calculations for display purpose only dtrendline_H_extend2 = trendline_H_extend2 - Ref (trendline_H_extend2,-1); dtrendline_H_extend2 = IIf (PHigh, Ref (dtrendline_H_extend,-1),dtrendline_H_extend2); tld = ParamToggle ( "All trendlines" , "show|hide" ,1); if (tld) { // omit uptrending upper trendlines and downtrending lower trendlines trendline_L = IIf (dtrendline_L > 0,trendline_L, Null ); trendline_L_extend = IIf (dtrendline_L_extend > 0,trendline_L_extend, Null ); trendline_L_extend2 = IIf (dtrendline_L_extend2 > 0,trendline_L_extend2, Null ); trendline_H = IIf (dtrendline_H < 0,trendline_H, Null ); trendline_H_extend = IIf (dtrendline_H_extend < 0,trendline_H_extend, Null ); trendline_H_extend2 = IIf (dtrendline_H_extend2 < 0,trendline_H_extend2, Null ); } trendline_L_extend2 = IIf ( BarsSince (Plow) <= nbar,trendline_L_extend2, Null ); trendline_H_extend2 = IIf ( BarsSince (PHigh) <= nbar,trendline_H_extend2, Null ); // chart GraphXSpace = 5; SetChartOptions (0, chartShowDates ); chartflag = ParamToggle ( "Heikin Ashi" , "show|hide" ,1); if (chartFlag) { Plot ( C , "\nPrice" , colorWhite , styleCandle ); } else { HaClose = ( O + H + L + C )/4; HaOpen = AMA ( Ref ( HaClose, -1 ), 0.5 ); HaHigh = Max ( H , Max ( HaClose, HaOpen ) ); HaLow = Min ( L , Min ( HaClose, HaOpen ) ); PlotOHLC ( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name (), colorWhite , styleCandle ); } PlotShapes ( shapeSmallCircle *PLow, colorGreen ,0, L ,-10); PlotShapes ( shapeSmallCircle *PHigh, colorRed ,0, H ,10); // segment 1 Plot (trendline_L, "\nLower Trendline" , colorBrightGreen , styleLine ); // segment 2, grey dots unconfirmed trend, green confirmed trend Plot ( IIf ( BarsSince (Plow) <= nbar,trendline_L_extend, Null ), "" , colorLightGrey , styleNoLine | styleDots | styleThick ); Plot ( IIf ( BarsSince (Plow) > nbar,trendline_L_extend, Null ), "" , colorDarkGreen , styleNoLine | styleDots | styleThick ); // segment 3 Plot ( IIf ( BarsSince (Plow) <= nbar,trendline_L_extend2, Null ), "" , colorDarkGreen , styleNoLine | styleDots | styleThick ); // segment 1 Plot (trendline_H, "\nUpper Trendline" , colorRed , styleLine ); // segment 2, grey dots unconfirmed trend, green confirmed trend Plot ( IIf ( BarsSince (PHigh) <= nbar,trendline_H_extend, Null ), "" , colorLightGrey , styleNoLine | styleDots | styleThick ); Plot ( IIf ( BarsSince (PHigh) > nbar,trendline_H_extend, Null ), "" , colorOrange , styleNoLine | styleDots | styleThick ); // segment 3 Plot ( IIf ( BarsSince (PHigh) <= nbar,trendline_H_extend2, Null ), "" , colorOrange , styleNoLine | styleDots | styleThick ); Title = Name () + " | " + EncodeColor ( colorYellow ) + "nbar: " + nbar + EncodeColor ( colorWhite ) + " | " + EncodeColor ( colorBrightGreen ) + "Lower Trendline: " + trendline_L + EncodeColor ( colorWhite ) + " | " + EncodeColor ( colorRed ) + "Upper Trendline: " + trendline_H + EncodeColor ( colorWhite ); signalFlag = ParamToggle ( "Possible Signals" , "show|hide" ,1); if (signalFlag) { // ***** possible buy and short signal ***** Buy = (! IsEmpty (trendline_H_extend) AND Cross ( C ,trendline_H_extend) AND BarsSince (PHigh) > nbar) OR (! IsEmpty (trendline_H_extend2) AND Cross ( C ,trendline_H_extend2) AND !PHigh) OR (PHigh AND C > trendline_H_extend2 AND Ref ( C ,-1) < Ref (trendline_H_extend,-1) AND ! IsEmpty (trendline_H_extend) AND ! IsEmpty (trendline_H_extend2) ); BuyPrice = C ; Short = (! IsEmpty (trendline_L_extend) AND Cross (trendline_L_extend, C ) AND BarsSince (PLow) > nbar) OR (! IsEmpty (trendline_L_extend2) AND Cross (trendline_L_extend2, C ) AND !PLow) OR (PLow AND C < trendline_L_extend2 AND Ref ( C ,-1) > Ref (trendline_L_extend,-1) AND ! IsEmpty (trendline_L_extend) AND ! IsEmpty (trendline_L_extend2)); ShortPrice = C ; Sell = 0; Cover = 0; PlotShapes ( IIf ( Buy , shapeUpArrow , shapeNone ), colorGreen ,0, L ,-15); PlotShapes ( IIf ( Buy , shapeHollowUpArrow , shapeNone ), colorWhite ,0, L ,-15); PlotShapes ( IIf ( Buy , shapeHollowSmallCircle , shapeNone ), colorWhite ,0, BuyPrice ,0); PlotShapes ( IIf ( Short , shapeDownTriangle , shapeNone ), colorYellow ,0, H , IIf ( Short AND Sell ,-30,-15)); PlotShapes ( IIf ( Short ,shapeHollowDownTriangle, shapeNone ), colorWhite ,0, H , IIf ( Short AND Sell ,-30,-15)); PlotShapes ( IIf ( Short , shapeHollowCircle , shapeNone ), colorWhite ,0, ShortPrice ,0); } _SECTION_BEGIN ( "Price" ); SetChartOptions (0, chartShowArrows | chartShowDates ); _N (Title = StrFormat ( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}" , O , H , L , C , SelectedValue ( ROC ( C , 1 ) ) )); Plot ( C , "Close" , ParamColor ( "Color" , colorBlack ), styleNoTitle | ParamStyle ( "Style" ) | GetPriceStyle () ); _SECTION_END (); _SECTION_BEGIN ( "Ichimoku Hayo Kinko" ); GraphXSpace =1; prds = Param ( "Standard Line Periods?" , 12,5,26,1); prds1 = Param ( "Turning Line Periods?" , 3,3,10,1); prds2 = Param ( "Delayed Line Periods?" , 11,4,25,1); prds3 = Param ( "Spans Periods?" , 18,10,52,1); TL = ( HHV ( H , prds1) + LLV ( L , prds1) )/2; SL = ( HHV ( H , prds) + LLV ( L , prds) )/2; DL = Ref ( C , prds2); Sp1 = Ref ( ( SL + TL )/2, -prds2)-( C *0.003); Sp2 = Ref ( ( HHV ( H , prds3) + LLV ( L , prds3))/2, -prds2)+( C *0.003); STPL=( C +sp1+sp2)/3; Plot (STPL, "STPL" , ParamColor ( "STPL" , colorBlack ), styleThick ); SetChartOptions ( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle ); _N ( Title = StrFormat ( "{{NAME}} - " + SectorID ( 1 ) + " - {{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 , "Close" , colorBlack , styleCandle | styleNoTitle | ParamStyle ( "Style" ) | GetPriceStyle () ); if ( ParamToggle ( "Tooltip shows" , "All Values|Only Prices" ) ) { ToolTip = StrFormat ( "Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: " + NumToStr ( V , 1 ), O , H , L , C , SelectedValue ( ROC ( C , 1 ) ) ); } Buy = Cross ( Close , IIf (sp1>sp2,sp1,sp2)); Sell = Cross ( IIf (sp1<sp2,sp1,sp2), Close ); /* exrem is one method to remove surplus strade signals*/ Buy = ExRem ( Buy , Sell ); Sell = ExRem ( Sell , Buy ); Filter = Buy OR Sell ; AddTextColumn ( FullName (), "Company Name" ); AddColumn ( Buy , "Buy" , 1 ); AddColumn ( Sell , "Sell" , 1 ); AddColumn ( C , "Close" , 1.3 ); AddColumn ( H , "High" , 1.3 ); PlotOHLC (Sp1,Sp1,Sp2,Sp2, "Cloud" , IIf (Sp1>Sp2, ParamColor ( "Span1 Color" , ColorRGB (0,255,0)), ParamColor ( "Span2 Color" , ColorRGB (255,104,32))), styleCloud ); PlotShapes ( IIf ( Buy , shapeSquare , shapeNone ), colorGreen , 0, L , Offset=-40); PlotShapes ( IIf ( Buy , shapeSquare , shapeNone ), colorLime , 0, L , Offset=-50); PlotShapes ( IIf ( Buy , shapeUpArrow , shapeNone ), colorWhite , 0, L , Offset=-45); PlotShapes ( IIf ( Sell , shapeSquare , shapeNone ), colorRed , 0, H , Offset=40); PlotShapes ( IIf ( Sell , shapeSquare , shapeNone ), colorOrange , 0, H , Offset=50); PlotShapes ( IIf ( Sell , shapeDownArrow , shapeNone ), colorWhite , 0, H , Offset=-45); if ( Status ( "action" ) == actionIndicator ) ( Title = EncodeColor ( colorWhite )+ "NICK MA Swing System" + " - " + Name () + " - " + EncodeColor ( colorRed )+ Interval (2) + EncodeColor ( colorWhite ) + " - " + Date () + " - " + "\n" + EncodeColor ( colorRed ) + "Op-" + O + " " + "Hi-" + H + " " + "Lo-" + L + " " + "Cl-" + C + " " + "Vol= " + WriteVal ( V )+ "\n" + EncodeColor ( colorLime )+ WriteIf ( Buy , " GO LONG / Reverse Signal at " + C + " " , "" )+ WriteIf ( Sell , " EXIT LONG / Reverse Signal at " + C + " " , "" )+ "\n" ); _SECTION_END (); |
2 comments
Leave Comment
Please login here to leave a comment.
Back
Error in Line 8: Variable sbrall is used without having been initialized :(
Dear Ravi
There is no problem with the formula. It’s working fine.