_SECTION_BEGIN("MACDPrediction");
//The probable Cross between MACD AND its Signal, by D. Tsokakis, Feb2005
SetBarsRequired(10000,0);
function EMAn ( Cnext , r3)
{
return ( 2 * Cnext + ( r3 - 1 ) * EMA ( C , r3 ) ) / ( r3 + 1 ) ;
}
function MACDn ( Cnext , r1 , r2 )
{
return EMAn ( Cnext ,r1 ) - EMAn ( Cnext , r2 ) ;
}
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
det = 500 ;
perc = 25/100 ;
Clast = SelectedValue ( C ) ;
Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1,r2), ParamColor("MACD color", colorTeal ), ParamStyle("MACD style") );
Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorRed ), ParamStyle("Signal style") );
Plot( ml-sl, "MACD Histogram", IIf(ml-sl > 0,colorBrightGreen,colorRed ), styleNoTitle | ParamStyle("Histogram style",styleHistogram | styleNoLabel, maskHistogram ));
det = 500 ;
perc = 25/100 ;
Clast = SelectedValue ( C ) ;
Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1,
r2), ParamColor("MACD color", colorRed ), ParamStyle("MACD style") );
//Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorRed ), ParamStyle("Signal style") );
Plot( ml-sl, "MACD Histogram", IIf(ml-sl > 0,colorBrightGreen,colorRed ), styleNoTitle | ParamStyle("Histogram style",styleHistogram | styleNoLabel, maskHistogram ));
MACDlast = SelectedValue(MACD());
Buy= Cross(MACD(12,26),Signal(12,26,9));
Sell = Cross( Signal(12, 26, 9), MACD(12,26) );
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
SIGNALlast = SelectedValue ( Signal ( ) );
Title = Name ( ) + ", " + Date ( ) + ", MACD=" + WriteVal ( MACDlast )+ " ,SIGNAL=" + WriteVal ( SignalLAST );
Cnextmin = ( 1 - perc ) * Clast ;Cnextmax = ( 1 + perc ) * Clast ;
step = ( Cnextmax - Cnextmin ) / det ;
nextROC1 = -100 * perc ;
nextROC2 = -100 * perc ;
for ( Cnext = Cnextmin ; Cnext <= Cnextmax ; Cnext = Cnext + step )
{
X = MACDn ( Cnext , 12 , 26 ) ;
Y = EMA ( X , 9 ) ;
MACDnext = SelectedValue ( X );
SIGNALnext = SelectedValue ( Y );
NextROC = 100 * ( -1 + Cnext / Clast ) ;
NextROC0 = 100 * ( -1 + Cnext / Clast ) ;
if ( macdnext < SignalLAST )
{
NextROC1 = NextROC ;
}
if ( MACDnext < MACDlast )
{
nextROC2 = nextROC0;
}
}
Title = Title;
Plot ( 0 ,"", colorBlack ,styleDashed ) ;
_SECTION_END();