Help to AFL

#1
Hello,
I want to overlay two indicators, MACD and RSI.
The MACD oscillates around 0, while the RSI ranges between 0 and 100.
As might superimpose for the MACD 0 coincide with 50 of the RSI.
Someone can write the AFL. Thank you very much.

regards,
 

asnavale

Well-Known Member
#2
Hello,
I want to overlay two indicators, MACD and RSI.
The MACD oscillates around 0, while the RSI ranges between 0 and 100.
As might superimpose for the MACD 0 coincide with 50 of the RSI.
Someone can write the AFL. Thank you very much.

regards,
Hi Mary,

Use styleOwnScale or styleLeftAxisScale for either MACD or RSI.

-Anant
 
#3
Rsi + macd.

_section_begin("rsia + macd");
p = paramfield( "price field" );
periods = param("periods", 15, 1, 200, 1 );
plot( rsia( p, periods),"rsi",coloryellow,styleownscale);
_section_end();

_section_begin("macdprediction12-26-9");
/*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(r1, r2),signal(r1,r2,r3));
sell = cross( signal(r1,r2,r3), macd(r1,r2) );
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();
 
#5
Hello,

ASNAVALE, As previously used "styleownscale" to superimpose the two indicators. This does not guarantee that the line "0" of the MACD line matches "50" of RSI.
"styleleftaxisscale", neither is guaranteed. Thank you very much.

regards,
 

Similar threads