[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] MACD-ROC Prediction formula help



PureBytes Links

Trading Reference Links

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.  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...*/




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/