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 ....
Reversing MACD Indicator Panel 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 | // This is all-in-one formula for the indicator panel. // To use it, enter the formula in the AFL Editor, then press "Insert indicator." // To change indicator, select parameters and select the value from the parameter option // "Plot Indicator" // _SECTION_BEGIN ( "Indicator selection" ); SetChartOptions ( 0, chartWrapTitle ); GraphXSpace = Param ( "Chart whitespace" , 10, 2, 15, 1 ); p_plot_indicator = ParamList ( "Plot indicator" , "MACD|MACD_HLC|MACD_BB|MACD_MTF" , 0 ); _SECTION_END (); _SECTION_BEGIN ( "PMACD functions" ); // General MACD function function MACDa( price, fast, slow ) { return EMA ( price, fast ) - EMA ( price, slow ); } // returns price where MACD is equal to previous bar MACD // note that PMACDeq() computes the next bar value, so // - it should be plotted by shifting 1 bar forward // - or reference 1 bar back when comparing to price function PMACDeq( price, period_X, period_Y ) { alphaX = 2. / ( 1. + period_X ); alphaY = 2. / ( 1. + period_Y ); return ( EMA (price,period_X)*alphaX - EMA (price,period_Y)*alphaY)/(alphaX - alphaY); } // returns price where MACD is equal to level value // e.g. PMACDlevel(0, C, 12, 16) would return the series // where next price would make MACD=0 // // note that PMACDLevel() computes the next bar value, so // - it should be plotted by shifting 1 bar forward // - or reference 1 bar back when comparing to price function PMACDlevel( level, price, period_X, period_Y ) { alphaX = 2. / ( 1. + period_X ); alphaY = 2. / ( 1. + period_Y ); One_alphaX = 1 - alphaX; One_alphaY = 1 - alphaY; return ( Level + EMA ( price, period_Y ) * One_alphaY - EMA ( price, period_X ) * One_alphaX ) / ( alphaX - alphaY ); } // for simplicity, case where level=0 in PMACDlevel() function PMACDzero( price, period_X, period_Y ) { return PMACDlevel( 0, price, period_X, period_Y ); } _SECTION_END (); _SECTION_BEGIN ( "MACD" ); // Plot MACD p_px = ParamField ( "Price field" , 3 ) ; p_fast = Param ( "Period fast" , 12, 1, 24, 1 ); p_slow = Param ( "Period slow" , 26, 2, 52, 1 ); p_signal = Param ( "Period signal" , 9, 1, 18, 1 ); if ( p_plot_indicator == "MACD" ) { Plot ( md = MACDa( p_px, p_fast, p_slow ), _DEFAULT_NAME (), colorBlue , styleDots | styleLine | styleThick ); PlotShapes ( shapeSmallCircle , colorBlue , 0, md, 0 ); Plot ( sl = EMA ( md, p_signal ), StrFormat ( "Signal(%g)" , p_signal ), colorRed , styleLine | styleThick ); Plot ( md - sl, "MACD Histogram" , colorBlack , styleNoTitle | styleHistogram | styleNoLabel ); // Use for title only - the next price required for MACD to be the same Plot ( PMACDeq( p_px, p_fast, p_slow ), "Next_PMACDeq" + _PARAM_VALUES () + " from " + SelectedValue ( p_px ), colorBlue , styleNoDraw | styleOwnScale ); // Use for title only - the next price required for MACD to across zero Plot ( PMACDzero( p_px, p_fast, p_slow ), "Next_PMACDzero" + _PARAM_VALUES (), colorBlack , styleNoDraw | styleOwnScale ); } _SECTION_END (); _SECTION_BEGIN ( "MACD_HLC" ); // Plot MACD of the High, Low and Close p_fast = Param ( "period fast" , 12, 1, 24, 1 ); p_slow = Param ( "period slow" , 26, 2, 52, 1 ); if ( p_plot_indicator == "MACD_HLC" ) { Plot ( 0, "" , colorBlack , styleLine | styleNoLabel ); Plot ( md = MACDa( H , p_fast, p_slow ), StrFormat ( "MACD(H,%g,%g)" , p_fast, p_slow ), colorGreen , styleDots | styleLine | styleThick ); // mark each point with a PlotShapes() circle that is larger than default Plot() styleDots PlotShapes ( shapeSmallCircle , colorGreen , 0, md, 0 ); Plot ( md = MACDa( C , p_fast, p_slow ), StrFormat ( "MACD(C,%g,%g)" , p_fast, p_slow ), colorBlue , styleDots | styleLine | styleThick ); PlotShapes ( shapeSmallCircle , colorBlue , 0, md, 0 ); Plot ( md = MACDa( L , p_fast, p_slow ), StrFormat ( "MACD(L,%g,%g)" , p_fast, p_slow ), colorRed , styleDots | styleLine | styleThick ); PlotShapes ( shapeSmallCircle , colorRed , 0, md, 0 ); } _SECTION_END (); _SECTION_BEGIN ( "MACD_BB" ); // Plot MACD with BB p_px = ParamField ( "Price field" , 3 ); p_fast = Param ( "period fast" , 12, 1, 24, 1 ); p_slow = Param ( "period slow" , 26, 2, 52, 1 ); p_signal = Param ( "period signal" , 9, 1, 18, 1 ); p_bbperiod = Param ( "period bb" , 10, 2, 20, 1 ); p_bbwidth = 1; if ( p_plot_indicator == "MACD_BB" ) { md = MACDa( p_px, p_fast, p_slow ); md1 = Ref ( md, -1 ); mdsig = EMA ( md, p_signal ); BBtop = BBandTop ( md, p_bbperiod, p_bbwidth ); BBbot = BBandBot ( md, p_bbperiod, p_bbwidth ); Hist = md - mdsig; Color = IIf ( md<0 AND md>md1, colorLime , IIf ( md > 0 AND md > md1, colorBrightGreen , IIf ( md > 0 AND md < md1, colorOrange , colorRed ) ) ); Plot ( md, _DEFAULT_NAME (), color, styleDots | styleLine ); PlotShapes ( shapeSmallCircle , color, 0, md, 0 ); // show the MACD zero line Plot ( 0, "" , IIf ( md > 0, colorIndigo , colorRed ), styleLine | styleThick | styleNoLabel ); // show the MACD histo as a ribbon on the bottom of the panel Plot ( 3, "" , IIf ( Hist > 0, colorIndigo , colorRed ), styleArea | styleOwnScale | styleNoLabel , 0, 100, 0, -2 ); // Plot the BB Plot ( BBtop, "BBtop" , colorGreen , styleDashed | styleNoRescale ); Plot ( BBbot, "BBbot" , colorRed , styleDashed | styleNoRescale ); PlotOHLC ( BBtop, BBtop, BBbot, BBbot, "BB" , colorLightGrey , styleCloud | styleNoLabel | styleNoTitle | styleNoRescale , Null , Null , 0, -3 ); Plot ( (BBtop + BBBot)/2, "" , colorBlack , styleLine | styleNoRescale , styleNoLabel ); } _SECTION_END (); _SECTION_BEGIN ( "MACD_MTF" ); // Plot MACD_MTF p_px = ParamField ( "Price field" , 3 ); p_fast = Param ( "period fast" , 12, 1, 24, 1 ); p_slow = Param ( "period slow" , 26, 2, 52, 1 ); p_signal = Param ( "period signal" , 9, 1, 18, 1 ); if ( p_plot_indicator == "MACD_MTF" ) { Plot ( md = MACDa( p_px, p_fast, p_slow ), _DEFAULT_NAME (), colorBlue , styleDots | styleLine | styleThick ); PlotShapes ( shapeSmallCircle , colorBlue , 0, md, 0 ); Plot ( 0, "" , colorBlack , styleLine ); // Use for title only - the next price required for MACD to be the same Plot ( PMACDeq( p_px, p_fast, p_slow ), "Next_PMACDeq" + _PARAM_VALUES () + " from " + SelectedValue ( p_px ), colorBlue , styleNoDraw | styleOwnScale ); // Use for title only - the next price required for MACD to across zero Plot ( PMACDzero( p_px, p_fast, p_slow ), "Next_PMACDzero" + _PARAM_VALUES (), colorBlack , styleNoDraw | styleOwnScale ); // plot higher period MACD lines X = 5; Plot ( MACDa( p_px, X * p_fast, X * p_slow ), NumToStr ( X, 0 ) + "*" + _DEFAULT_NAME (), colorGreen , styleDots | styleLine | styleThick ); X = 21; Plot ( MACDa( p_px, X * p_fast, X * p_slow ), NumToStr ( X, 0 ) + "*" + _DEFAULT_NAME (), colorRed , styleDots | styleLine | styleThick ); } _SECTION_END (); |