Simple Coding Help - No Promise.

bunti_k23

Well-Known Member
anyone know how this rsi divergence afl works,kindly explain the construction and working .

thank you
amit.:)


_SECTION_BEGIN("RSI Divergence");
//------------------------------------------------------------------------------
//
// Formula Name: RSI divergence
// Author: Rajandran R
// Url: www.marketcalls.in
// Formula URL:
// Details URL:
//
//------------------------------------------------------------------------------
//
// + scanner
//
//------------------------------------------------------------------------------

/*---------------------------------------------------
RSI Divergence
--------------------------------------------------------*/

GraphXSpace=7;
//n=Param("% Reverse ",12,0,100,1);
n=Optimize("ZIG",20,5,50,1);
per=Optimize("rsi",100,5,50,1);
Buy=Sell=0;
Var = Zig(RSI(per), n);
t= Trough(RSI(per), n, 1);
p= Peak(RSI(per), n, 1);
x[0] =Var[0];
price[0] = C[0];
j=0;

// bearish divergence
for ( i=0; i<BarCount; i++)
{
if(Var == p)
{

j++;
x[j] =Var;
price[j] =C;
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell =1;
}
}

// bullish divergence
for ( i=0; i<BarCount; i++)
{
if(Var == t)
{
j++;
x[j] =Var;
price[j] =C;
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy =1;
}
}
Short=Sell;
Cover=Buy;

Plot(Var, "", 6);
PlotShapes ( IIf(Sell, shapeSmallSquare, shapeNone), colorRed, 0 , Var,0);
PlotShapes( IIf(Buy, shapeSmallSquare, shapeNone), colorBrightGreen, 0, Var,0);

Title ="RSI Divergence" ;
_SECTION_END();

_SECTION_BEGIN("TEMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( TEMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
 

Try This


Code:
_SECTION_BEGIN("MA Percentage Band");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
P = ParamField("Price field",-1);
Periods = Param("Periods", 200, 2, 300, 1, 10 );
Percent = Param("Percentage %", 25, 1,100, 1, 10 );
SelectedIndicator = ParamList( "Show", "SMA,EMA,WMA,DEMA,TEMA", 1 );
 
if ( SelectedIndicator == "SMA" )
{
Positive_Percent_Band = MA( P, Periods )+ (MA( P, Periods )*percent/100);
Negative_Percent_Band = MA( P, Periods )- (MA( P, Periods )*percent/100);
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Positive_Percent_Band, "Positive %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Negative_Percent_Band, " Negative %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
}
else
if ( SelectedIndicator == "EMA" )
{
Positive_Percent_Band = EMA( P, Periods )+ (EMA( P, Periods )*percent/100);
Negative_Percent_Band = EMA( P, Periods )- (EMA( P, Periods )*percent/100);
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Positive_Percent_Band, "Positive %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Negative_Percent_Band, " Negative %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
}
else
if ( SelectedIndicator == "WMA" )
{
Positive_Percent_Band = WMA( P, Periods )+ (WMA( P, Periods )*percent/100);
Negative_Percent_Band = WMA( P, Periods )- (WMA( P, Periods )*percent/100);
Plot( WMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Positive_Percent_Band, "Positive %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Negative_Percent_Band, " Negative %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
}
else
if ( SelectedIndicator == "DEMA" )
{
Positive_Percent_Band = DEMA( P, Periods )+ (DEMA( P, Periods )*percent/100);
Negative_Percent_Band = DEMA( P, Periods )- (DEMA( P, Periods )*percent/100);
Plot( DEMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Positive_Percent_Band, "Positive %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Negative_Percent_Band, " Negative %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
}
else
if ( SelectedIndicator == "TEMA" )
{
Positive_Percent_Band = TEMA( P, Periods )+ (TEMA( P, Periods )*percent/100);
Negative_Percent_Band = TEMA( P, Periods )- (TEMA( P, Periods )*percent/100);
Plot( TEMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Positive_Percent_Band, "Positive %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
Plot( Negative_Percent_Band, " Negative %", ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
}
_SECTION_END();



thanks a TON amitrandive,i tried it today and the code is so accurate that even the 2 decimal points matched when compared with nest indicator :clapping:
 
amibroker has a max limit of 300 periods for ema,sma etc:confused:.....is it possible to bypass it using some simple modification to the afl
i mean there should be some small snippet of code that can be put into any afl at the right place i.e. at the place where the ema and its parameters are defined
(my requirement is 500 period ema and sometimes even the 1030 ema. tf=1 min)

i cud plot the (500/5=100)100 ema on 5min tf but the signal wud be late and several other such problems. wat to do?
 
Last edited:

amitrandive

Well-Known Member
amibroker has a max limit of 300 periods for ema,sma etc:confused:.....is it possible to bypass it using some simple modification to the afl
i mean there should be some small snippet of code that can be put into any afl at the right place i.e. at the place where the ema and its parameters are defined
(my requirement is 500 period ema and sometimes even the 1030 ema. tf=1 min)

i cud plot the (500/5=100)100 ema on 5min tf but the signal wud be late. wat to do
The limitation is on the parameters

Code:
Periods = Param("Periods", 200, 2, 300, 1, 10 );
Change to

Code:
Periods = Param("Periods", 200, 2, 500, 1, 10 );
 

bunti_k23

Well-Known Member
what are the important factors we shd look upto in a backtesting report generated by amibroker...
 

amitrandive

Well-Known Member
Guys any AFL for getting nifty future premium?

I have data for both spot nifty and future obviously

Must be there I think :)
Try this
:thumb:

Code:
_SECTION_BEGIN("Spread");
_N( Symbol2= ParamStr("Symbol2", "MSFT") );
Mode = ParamToggle("Mode", "Difference (Symbol1-Symbol2)|Ratio (Symbol1/Symbol2)");

SetForeign( Symbol2 );
C2 = C;
H2 = H;
L2 = L;
O2 = O;
V2 = V;
RestorePriceArrays();

Color = ParamColor( "Color", colorDefault );
Style = ParamStyle( "Style", styleLine, maskPrice );

if( Mode == 0 )
 PlotOHLC( O-O2, H-H2, L-L2, C-C2, "(" + Name()+" - "+Symbol2 + ") spread", Color, style );
else
 PlotOHLC( O/O2, H/H2, L/L2, C/C2, "(" + Name()+" / "+Symbol2 + ") spread", Color, style );

_SECTION_END();
 

Similar threads