Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Reversing MACD for Amibroker (AFL)
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
Indicator / Formula
_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
Leave Comment
Please login here to leave a comment.
Back
nice afl
Thanks and good for the sharing