Need modified AFL on MACD with 5,10,9 values

#1
Hello,
I am trying to modify one AFL on MACD, which I`ve found in Amibroker Library. This code is pretty old. I need to change the values of MACD from 12,26,9 to 5,10,9.
I tried to make changes but not succeed, still signal is coming for 12,26,9 values only :( I request seniors to kindly modify this AFL to use it with the above mentioned values.


Please find below mentioned AFL:-


/* Project: AmiBroker
** File: macd.afl
** Title: MACD Guru Commentary Example (English)
** Requirements: AFL 1.1 (AmiBroker 3.0) or above
** Date: Feb 9th, 1999
** Written by: Tomasz Janeczko
*/

Buy=Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );

"Review of " + FullName() + " (" + Name() + ")" + "\nas of " + Date();


"\nCurrent Statistics\n";
"Close: " + WriteVal(Close);
"Change: " + WriteVal(Close - Ref( Close, -1 ) ) ;
"MACD Value: " + WriteVal(MACD());
"Signal Line: " + WriteVal(Signal());

"\nThe MACD can provide buy/sell indications in three ways, signal line
crossovers, overbought/oversold conditions, AND divergences.\n";

"Crossovers:\n";
"Currently the MACD is "+
WriteIf(MACD() > Signal(),"bullish","bearish")+
" since it is trading "+
WriteIf(MACD() > Signal(),"above","below")+
" its signal line.";


"The MACD crossed "+
WriteIf(MACD() > Signal(),"above","below")+
" its signal line "+
WriteVal( Min( BarsSince( Cross( MACD(), Signal() )), BarsSince( Cross(
Signal(), MACD()))), 0.0)+
" period(s) ago.";

bars=LastValue(Min( BarsSince( Cross( MACD(), Signal() )), BarsSince( Cross(
Signal(), MACD())) ));

prevclose=Ref(Close,-bars);

"Since the MACD crossed its moving average, "+
Name()+"'s price has "+
WriteIf(Close>prevclose,"increased ","decreased ")+
WriteVal(100*(Close-prevclose)/prevclose) + "%";

"And has ranged from a high of "+
WriteVal(HHV(High,bars+1),6.3)+
" to a low of "+
WriteVal(LLV(Low,bars+1),6.3);

"\nOverbought/Oversold\n";
Osc = OscP( 12, 26 );
Osc1 = Ref( Osc, -1 );
Osc5 = Ref( Osc, -5 );

WriteIf( Osc <= -3 AND ( Osc - Osc5 ) == -Sum( abs( Osc - Osc1 ), 5 ),
"The MACD is in an oversold range. Prices may continue to move lower for some
time. Wait for prices to move higher before considering any long positions.",
WriteIf( Osc >= 3 AND ( Osc - Osc5 ) == Sum( abs( Osc - Osc1 ), 5 ),
"The MACD is in an overbought range. Prices may continue to move higher for
some time. Wait for prices to move lower before considering any Short
positions.",
"The MACD is not in an Overbought/Oversold range."));

"\nDivergence\n";
temp = Trough(Low, 2, 1) < 0.96 * Ref( Trough(Low, 2, 1), -1) AND ValueWhen(
Trough(Low, 2, 1) != Ref( Trough(Low, 2, 1), -1 ), MACD(), 1 ) >= 0.90 *
ValueWhen( Trough( Low, 2, 1) != Ref( Trough( Low, 2, 1), -1 ), MACD(), 2 ) AND
MACD() < 0;

temp2= Peak( High,2, 1) > 1.04 * Ref( Peak( High, 2, 1), -1) AND ValueWhen(
Peak( High, 2, 1) != Ref( Peak( High, 2, 1), -1 ), MACD(), 1 ) <= 0.90 *
ValueWhen( Peak( High, 2, 1) != Ref( Peak( High, 2, 1), -1 ), MACD(), 2 ) AND
MACD() > 0;

WriteIf( HHV( temp, 5 ) == 1,"A bullish divergence occurred " + WriteVal(
BarsSince( temp ), 1.0 ) +
" period(s) ago. Wait for upward price movement for confirmation before
considering any long positions.",
WriteIf( HHV( temp2,5) == 1,
"A bearish divergence occurred " +
WriteVal( BarsSince( temp2 ), 1.0 ) +
" period(s) ago. Wait for downward price movement for confirmation before
considering any Short positions.",
"There have been no divergence signals within the last 5 periods." ) );

"\n\nThis commentary is not a recommendation to buy or sell, but rather a
guideline to interpreting the specified indicators. This information should
only be used by investors who are aware of the risk inherent in securities
trading. The author accepts no liability whatsoever for any loss arising from
any use of this expert OR its contents.";

Regards,
TT
 

hsb

New Member
#2
Hi tangotaurian,

You need to set the required values in MACD() and SIgnal() functions.

I havent gone through the whole formula but, replacing MACD() with MACD(5, 10) and Signal() with Signal(5,10,9) must work.

-HSB
 
#3
For MACD crossover with 5,10,9 values, I am using below mentioned AFL, but Buy/Sell signals are coming after 2, 3 candles after crossover happens. I want a Buy/Sell signal immediately after crossover happens. I need to modify this, but not getting through. Can someone kindly look into this...


_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 5, 2, 200, 1 );
r2 = Param( "Slow avg", 10, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml=MACD(r1,r2);
sl=Signal(r1,r2,r3);
Buy=Cross( MACD(), Signal() );
PlotShapes(shapeUpArrow*Buy,colorGreen);
Sell = Cross( Signal(), MACD() );
PlotShapes(shapeDownArrow*Sell,colorRed);
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", ParamColor("Histogram color", colorPaleGreen ), styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleNoLabel, maskHistogram ) );
_SECTION_END();


Regards,
TT
 
#4
Here you are:

_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 5, 2, 200, 1 );
r2 = Param( "Slow avg", 10, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml=MACD(r1,r2);
sl=Signal(r1,r2,r3);
Buy=Cross( ml, sl );
PlotShapes(shapeUpArrow*Buy,colorGreen);
Sell = Cross( sl,ml);
PlotShapes(shapeDownArrow*Sell,colorRed);
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", ParamColor("Histogram color", colorPaleGreen ), styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleNoLabel, maskHistogram ) );
_SECTION_END();
 

Similar threads