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 ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Reversing MACD for Amibroker (AFL)

Rating:
3 / 5 (Votes 12)
Tags:
oscillator, macd, amibroker

Reversing MACD is a MACD plotted on Price chart.

Based upon Article from:
http://www.traders.com/index.php/sac-magazine/current-contents/48-feature-articles/indicators/876

Using the scripts given in Metastock:
http://www.traders.com/Documentation/FEEDbk_docs/2012/01/TradersTips.html
(Amibroker version need Subscriber’s)

I coached forum member in TJ:
http://www.traderji.com/amibroker/77416-reverse-macd-amibroker.html
to translate into the following AFL script:

== AFL Formula ======

_SECTION_BEGIN("MS RevMACD on Price");
t1 = Param("fast periods", 12,5, 24, 12);
t2 = Param("slow periods", 26,10, 52, 26);
t3 = Param("signal periods", 9,3, 18, 9);
pick = Param("plot: <1=MACDeq 2=MACDeq0 3=HLC 4=BBands>",1,1,4,1);
a1 = 2/(t1+1);
a2 = 2/(t2+1);
CMACDeq = (Ref(EMA(C,t1)*a1,-1)-Ref(EMA(C,t2)*a2,-1))/(a1-a2);
HMACDeq = (Ref(EMA(H,t1)*a1,-1)-Ref(EMA(H,t2)*a2,-1))/(a1-a2);
LMACDeq = (Ref(EMA(L,t1)*a1,-1)-Ref(EMA(L,t2)*a2,-1))/(a1-a2);
MACDeq0 = Ref(EMA(C,t2)*(1-a2) - EMA(C,t1)*(1-a1),-1)/(a1-a2);
z = LastValue(IIf(pick > 2, 0, Cum(1)+1));
plot1 = IIf(pick==3, HMACDeq, BBandTop(CMACDeq,10,1));
plot2 = IIf(pick==2, MACDeq0, CMACDeq);
plot3 = IIf(pick==3, LMACDeq, BBandBot(CMACDeq,10,1));
Plot(plot1+ Ref(0,z),"HMACDeq",colorGreen,styleThick);
Plot(plot3+ Ref(0,z),"LMACDeq",colorRed,styleThick);
Rmacdcolor=IIf(MACDeq0<= C, ParamColor("Rmacdup", colorGreen),ParamColor("Rmacddn", colorRed));
Plot(plot2,"MACDeq0",Rmacdcolor,styleLine);
Colmacdeq=IIf(C>HMACDeq,colorLime,IIf(C<LMACDeq,colorOrange,colorDarkYellow));
Plot(CMACDeq,"CMACDeq ",colmacdeq,8);
_SECTION_END();

However i prefer tradestation version and is better than mestock. Hereby share with public.

Similar Indicators / Formulas

%MACD
Submitted by mavirk almost 15 years ago
Coloured MACD
Submitted by sandiip123 over 14 years ago
MACD Bullish
Submitted by zillur over 14 years ago
Bline MACD
Submitted by thegame.t2 about 15 years ago
MACD Dema Indicator
Submitted by Peixoto about 15 years ago
MACD Candles
Submitted by stanwell about 15 years ago

Indicator / Formula

Copy & Paste Friendly
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
_SECTION_BEGIN("TS RevMACD on Price");
_MACD_     = 1;
_MACD_HLC  = 2;
_MACD_BB   = 3;
_MACD_MTF  = 4;
 
//-------------------------
//-- Created by KelvinHand
//-------------------------
ColorDeepSkyBlue = ColorRGB(65,105,225);
 
function _PMACDeq (Price, period_X,period_Y)
/*
{ TASC January 2012 }
{ Reversing MACD by Johnny Dough }
{ returns price where MACD is equal to previous bar
  MACD }
     
inputs:
    Price( numericseries ),
    period_X( numericsimple ),
    period_Y( numericsimple ) ;
 
variables:
*/
{
    alphaX = 2 / ( 1 + period_X ) ;
    alphaY = 2 / ( 1 + period_Y ) ;
     
  return (( EMA( Price, period_X ) * alphaX -  EMA( Price, period_Y ) * alphaY ) /( alphaX - alphaY )) ;
}
 
function _PMACDlevel (level,Price,period_X, period_Y)
/*
{ TASC January 2012 }
{ Reversing MACD by Johnny Dough }
 
inputs:
    level( numericsimple ),
    Price( numericseries ),
    period_X( numericsimple ),
    period_Y( numericsimple ) ;
*/
{
//variables:
 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 )) ;
 
}
 
function _PMACDzero(Price, period_X, period_Y)
{
/*{ TASC January 2012 }
{ Reversing MACD by Johnny Dough }
 
inputs:
    Price( numericseries ),
    period_X( numericsimple ),
    period_Y( numericsimple ) ;
*/ 
 return _PMACDlevel( 0, Price, period_X, period_Y ) ;
}
 
/*
_PMACD_Ind1 (Indicator for Price Sub-Graph)
{ TASC January 2012 }
{ Reversing MACD by Johnny Dough }
 
inputs:
*/
switch ( ParamList("PlotTemplate", "MACD|MACD_HLC|MACD_BB|MACD_MTF") )
{
 case "MACD_HLC": PlotTemplate=_MACD_HLC; break;
 case "MACD_BB":  PlotTemplate=_MACD_BB; break;
 case "MACD_MTF": PlotTemplate=_MACD_MTF; break;
 
 default: PlotTemplate=_MACD_; break;
  
}
 
 
switch(ParamList("Price used", "Close|Open|High|Low|MP(HL/2)|TP(HLC/3)|WP(HLCC/4)"))
{
 
  case "Open": iPrice = Open; break;
  case "High": iPrice = High; break;
  case "Low":  iPrice = Low; break;
 
  case "MP(HL/2)":  iPrice = (H+L)/2; break;
  case "TP(HLC/3)": iPrice = (H+L+C)/2; break;
  case "WP(HLCC/4)": iPrice = (H+L+C+C)/2; break;
  default: iPrice = Close; break;
      
}
 
P_Fast= Param("Fast periods", 12, 2,  200);
P_Slow= Param("Slow periods", 26, 2,  200);
P_Signal= Param("Signal periods", 9, 2,  200); //{ PMACDeq EMA Signal length }
 
PMACD_TF_Mult1 = Param("Multiplier for Higher TF1", 5,  1,  100); 
PMACD_TF_Mult2 = Param("Multiplier for Higher TF2", 21, 1,  100); 
 
p_bbperiod = Param("BB average length", 10, 2,  200);
p_bbwidth  = Param("BB # of StdDev", 1, 1,  200);
Displace   = Param("displacement", 1, 0,  200);
     
//variables:
PMACDeq = Null;
PMACDeqSignal= Null;
PMACDeq_TF1 = Null;
PMACDeq_TF2 = Null;
UpperBand = Null;
LowerBand = Null;
 
PMACDzero = _PMACDzero( iPrice, P_Fast, P_Slow ) ;
 
//{ Plots }
 if (PlotTemplate != _MACD_HLC)
 
    PMACDeq = _PMACDeq( iPrice, P_Fast, P_Slow ) ;
    //Plot1[Displace]( PMACDeq, "PMACDeq" ) ;
   Plot(PMACDeq, "PMACDeq",
                ParamColor("PMACDeq Color",ColorDeepSkyBlue),
          ParamStyle("PMACDeq Style",styleLine|styleNoLabel),
                    0, 0, Displace); 
 }
 
 //Plot2[Displace]( PMACDzero, "PMACDzero" ) ;
 Plot(PMACDzero, "PMACDzero",
            ParamColor("PMACDzero Color",colorWhite),
            ParamStyle("PMACDzero Style",styleLine|styleNoLabel),
                0, 0, Displace); 
 
 if (PlotTemplate == _MACD_HLC)
 {
  Plot(_PMACDeq( Close, P_Fast, P_Slow ), "PMACD_C",
     ParamColor("PMACD_C Color",colorTeal),
        ParamStyle("PMACD_C Style",styleLine|styleNoLabel)
    );
 
 
  Plot(_PMACDeq( High,  P_Fast, P_Slow ), "PMACD_H",
     ParamColor("PMACD_H Color",colorDarkYellow),
        ParamStyle("PMACD_H Style",styleLine|styleNoLabel)
    );
 
  Plot(_PMACDeq( Low,   P_Fast, P_Slow ), "PMACD L",
     ParamColor("PMACD_L Color",colorDarkYellow),
        ParamStyle("PMACD_L Style",styleLine|styleNoLabel)
    );
 
     
 if (PlotTemplate == _MACD_)
 {
  PMACDeqSignal = EMA( PMACDeq, P_Signal ) ;
  Plot(PMACDeqSignal, "PMACDeqSig",
            ParamColor("PMACDeqSig Color",colorAqua),
       ParamStyle("PMACDeqSig Style",styleLine|styleNoLabel),
            0, 0, Displace); 
 }
       
 if (PlotTemplate == _MACD_BB)
 {
    UpperBand = BBandTop(PMACDeq, p_bbperiod, p_bbwidth ); 
    LowerBand = BBandBot(PMACDeq, p_bbperiod, p_bbwidth );
  Plot(UpperBand, "UpperBand",
            ParamColor("UpperBand Color",colorTeal),
       ParamStyle("UpperBand Style",styleLine|styleNoLabel),
            0, 0, Displace); 
  Plot(LowerBand, "LowerBand",
            ParamColor("LowerBand Color",colorTeal),
       ParamStyle("LowerBand Style",styleLine|styleNoLabel),
            0, 0, Displace); 
 
 
 if (PlotTemplate == _MACD_MTF)
 {
    PMACDeq_TF1 = _PMACDeq( iPrice, P_Fast *  PMACD_TF_Mult1, P_Slow * PMACD_TF_Mult1 ) ;
    PMACDeq_TF2 = _PMACDeq( iPrice, P_Fast *  PMACD_TF_Mult2, P_Slow * PMACD_TF_Mult2 ) ;
  Plot(PMACDeq_TF1, "PMACDeqTF1",
            ParamColor("PMACDeqTF1 Color",colorDarkYellow),
       ParamStyle("PMACDeqTF1 Style",styleLine|styleNoLabel),
            0, 0, Displace); 
  Plot(PMACDeq_TF2, "PMACDeqTF2",
            ParamColor("PMACDeqTF2 Color",colorDarkYellow),
  
       ParamStyle("PMACDeqTF2 Style",styleLine|styleNoLabel),
            0, 0, Displace); 
 
 
_SECTION_END();

2 comments

1. sureshsellappan

nice afl

2. SADAI

Thanks and good for the sharing

Leave Comment

Please login here to leave a comment.

Back