MACD-ROC Perdiction formula

#1
I dug this old Dimitris formula out of my archives and found it most
interesting. I would like to have the "Buy" and "Sell" statements incorporate
the ROC anticipated projection for the cross so I can develop an Exploration You help will be most appreciated.

Dick H.

_SECTION_BEGIN("MACDPrediction");
/*An MACD, Signal Cross is, in general, a bullish Signal.
Since it comes with a significant delay, it would be important to anticipate
this Cross.
Some days before the Cross, we often see an MACD turning point.
It is interesting to investigate the related conditions AND use them before the
end of the session.
The following AFL code will give the necessary next ROC for a higher MACD
value.*/

//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", colorRed ), ParamStyle("MACD style") );
Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal
color", colorBlue ), 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", colorBlue ), 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 ) +"\nThe nextMACD will be higher if the next
ROC will be > ";
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 + WriteIf ( NextRoc2 >= 0.1 , "+" , "" ) + WriteVal ( NextROC2 ,
1.2 ) + "%" + "\nThe nextMACD will be above the lastSIGNAL if the next ROC will
be > " + WriteIf ( NextRoc1 >= 0.1 , "+" , "" ) + WriteVal ( nextROC1 , 1.2
)+"%" ;
Plot ( 0 ,"", colorBlack ,styleDashed ) ;
_SECTION_END();

/*The principle of the code is simple : We suppose that the next ROC changes
from -25% to +25% AND we calculate the necessary ROC for a higher MACD.
Example1 : On Oct29 [point P1] AMZN would have a higher MACD if the next ROC
would be more than +1.30%. The next Day, Nov1, AMZN closed at +2.80% AND the
MACD was higher indeed. It was known [AND almost safe] before the end of the
Nov1 session, that AMZN was gaining more than +1.30%.
Example2 : On Jan4 [point P2] the ^NDX needed a +2.70% to change the MACD
downtrend. The most probable was to see lower MACD values...*/
 

Similar threads