li

Amibroker AFL for 14 Oversold & Overbought indicators with Support & Resistances

To get IEOD Data into Amibroker visit the link below:

http://tinyurl.com/ctzqcsy

We come across several indicators that show Oversold and Overbought zone for the stocks. Every time we need to navigate between various tabs in Amibroker to monitor all these indicators for a given stock or Index. So, is it possible to combine and customize these indicators in a single AFL? Yes, this AFL will answer exactly the same query. It comforts the user navigation and presents these Oversold and Overbought indicators at one place.

 

List of 14 Indicators supported with this AFL

MACD RSI CCI MoneyFlowIndex Ultimate
StochK StochD Projection Oscillator Tom DeMark range expansion ARSI
DMI Stdeviation Oscillator ROC DeMarker

AFL Code:

/*
MACD,RSI,CCI,StochK,StochD,Money Flow Index,Ultimate,ROC(Close),Tom DeMark,ARSI,ProjOsc,DMI,StdevOsc,DeMarker

mostly in range of 0-100 that we use along with price charts n that execute our trade n along with these indicators i also put support n resistace zones for comfort of a trader namely trendlines, Fibonacc lines n standard deviation line
plus overbought n oversold zone(custom) in clouded area
plotted by – ankit dargan
*/

_SECTION_BEGIN(“14 Oversold n Overbought indicators with Support n Resistance”);
SetChartBkColor( colorGrey40 ) ;
SetChartOptions(0,0,ChartGrid30 | ChartGrid70 );

Pds=Param(“Period”,14,7,33,1);
Ob=Param(“overbought”,70,-200,200,5);
Os=Param(“oversold”,30,-200,200,5);

/****Dimitri Code***********/
/*14-Day RSI of MACD()*/
//t=14; Replaced with pds= statement
Var=MACD();
Up=IIf(Var>Ref(Var,-1),abs(Var-Ref(Var,-1)),0);
Dn=IIf(Var<Ref(Var,-1),abs(Var-Ref(Var,-1)),0);
Ut=Wilders(Up,Pds);
Dt=Wilders(Dn,Pds);
RSIt=100*(Ut/(Ut+Dt));
/************End Code*************************/

/****Tom DeMark’s Range Expansion Index***********/
HighMom = H – Ref( H, -2 );
LowMom = L – Ref( L, -2 );
Cond1 = ( H >= Ref( L,-5) OR H >= Ref( L, -6 ) );
Cond2 = ( Ref( H, -2 ) >= Ref( C, -7 ) OR Ref( H, -2 ) >= Ref( C, -8 ) );
Cond3 = ( L Cond4 = ( Ref( L, -2 ) Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 );
Num = IIf( Cond, HighMom + LowMom, 0 );
Den = abs( HighMom ) + abs( LowMom );
TDREI = 100 * Sum( Num, 5 )/Sum( Den, 5 ) ;
/************End Code*************************/

/****Tom DeMark’s DeMarker***********/

highm = IIf( H > Ref( H, -1 ), H – Ref( H, – 1), 0 );
lowm = IIf( L < Ref( L, -1 ), Ref( L, – 1 ) – L, 0 );

DeMarker = 100 * Sum( highm, 13 )/( Sum( lowm, 13 ) + Sum( highm, 13 ) );

/****ARSI formula***********/
// variable period version (backtest-safe)
Chg = C – Ref( C, -1 );
UpCount = Sum( Chg >= 0, Pds );
DnCount = Pds – UpCount;
UpMove = AMA( Max( Chg, 0 ), 1/UpCount );
DnMove = AMA( Max( -Chg, 0 ), 1/DnCount );
RS = UpMove/DnMove;
ARSI = 100-(100/(1+RS));
/************End Code*************************/

/****Projection Oscillator***********/

function ProjOsc(Pds) {

// Slope of High {n period regression line of High)}
SlopeHigh = ((Pds * (Sum( Cum(1) * High, Pds))) – (Sum( Cum(1),Pds) * (
Sum(High, Pds)))) / ((Pds * Sum( Cum(1) ^ 2 , Pds)) – (Sum(Cum(1),Pds) ^
2));

//Slope of Low {n period regression line of Low}
SlopeLow = ((Pds * (Sum( Cum(1) * Low, Pds))) – (Sum( Cum(1), Pds) * (
Sum(Low, Pds)))) / ((Pds * Sum( Cum(1)^ 2, Pds)) – ( Sum(Cum(1),Pds) ^
2));

//Upper Projection Band
UpProjBand = 0;
for (i=0; i {
UpProjBand =
Max(Max(Ref(High,-i)+i*slopehigh,Ref(High,-i-1)+(i+1)*slopehigh),UpProjBand);
}

//Lower Projection Band
LoProjBand = 10000;
for (i=0; i {
LoProjBand =
Min(Min(Ref(Low,-i)+i*slopelow,Ref(Low,-i-1)+(i+1)*slopelow),LoProjBand);
}

//Projection Oscillator
ProOsc = 100 * (Close – LoProjBand) / (UpProjBand – LoProjBand);

return ProOsc;

}
aa= ProjOsc(Pds);
//bb= MA(ProjOsc(Pds),av);

//Plot(aa,”Projection Osc”,colorBrightGreen,styleLine);
//Plot(bb,”MA ProjOsc”,colorRed,styleLine);

/************End Code*************************/

/****Dynamic Momentum Index***********/

//period = Param( “RSI Period”, 13, 1, 100, 1 );
//MAperiod = Param( “MA Period”, 5, 1, 100, 1 );
//StDevperiod = Param( “StDev Period”, 8, 1, 100, 1 );

upday=IIf(C>Ref(C,-1),C-Ref(C,-1),0);
downday=IIf(Ref(C,-1)> C,Ref(C,-1)-C,0);

Stda=MA(StDev(C,8),5);//by default 5 is maperiod n 8 is stdevperiod
V1=StDev(C,8)/Stda;
TD=int(Pds/V1);

Su=Sum(upday,TD);
Sd=Sum(downday,TD);
M1=(Su-Sd);
M2=abs(Su+Sd);
DMI=50*(M1+M2)/M2;
//xs=Param(“Smoothing”,3,1,10,1);
//xs1=Param(“Trigger Line”,5,1,10,1);
//Plot(EMA(DMI,xs),”Dynamic Momentum Index “,colorRed,1);
//Plot(MA(DMI,xs1),”trigger”,colorBlue,1);

/************End Code*************************/

/****Stddev Oscillator***********/

StdevOsc=( ( C+2 * StDev( C,pds ) – MA( C,pds ) ) / ( 4 * StDev( C,pds ) ) ) * 100;

/************End Code*************************/

/*******Variables******************/

A1=RSIt; B2=RSI(pds); C3=CCI(pds); D4=StochK(pds); E5=StochD(pds);
F6=MFI(pds); G7=Ultimate(pds); H8=ROC(C,pds); I9=TDREI; J10=ARSI; K11=ProjOsc(Pds); L12= DMI; M13=StdevOsc ; N14 =DeMarker;//DO HERE

oc=ParamList(“Oscillator choice”,”RSI of MACD|RSI|CCI|StochK|StochD|Money Flow Index|Ultimate|ROC(Close)|Tom DeMark|ARSI|ProjOsc|DMI|StdevOsc|DeMarker”,1);
Osc=
IIf(oc==”RSI of MACD”,A1,
IIf(oc==”RSI”,B2,
IIf(oc==”CCI”,C3,
IIf(oc==”StochK”,D4,
IIf(oc==”StochD”,E5,
IIf(oc==”Money Flow Index”,F6,
IIf(oc==”Ultimate”,G7,
IIf(oc==”ROC(Close)”,H8,
IIf(oc==”Tom DeMark”,I9,
IIf(oc==”ARSI”,J10,
IIf(oc==”ProjOsc”,K11,
IIf(oc==”DMI”,L12,
IIf(oc==”StdevOsc”,M13,N14))))))))))))); // /*insert variable by Identifier*/
/*Value of Osc*/
Value1 = Osc;

Header=WriteIf(Osc==A1,” RSI Of MACD”,WriteIf(Osc==b2,” RSI”,WriteIf(Osc==C3,” CCI”,WriteIf(Osc==D4,”STOCHK”,WriteIf(Osc==E5,”STOCHD”,WriteIf(Osc==F6,” MONEY FLOW INDEX”,WriteIf(Osc==G7,” ULTIMATE”,WriteIf(Osc==H8,” ROC(CLOSE)”,WriteIf(Osc==I9,” Tom DeMark”,WriteIf(Osc==J10,” ARSI”,WriteIf(Osc==K11,” ProjOsc”,WriteIf(Osc==L12,” DMI”,WriteIf(Osc==M13,” StdevOsc”,WriteIf(Osc==N14,” DeMarker”,”"))))))))))))));//DO HERE

Plot(Value1, Header,6,1+4); /*BLUE*/

//Plot( Osc, “+Osc+”, colorBlack );
PlotOHLC( Osc,Osc,50,Osc, “”, IIf( Osc > 50, colorRed, colorGreen ), styleCloud | styleClipMinMax|styleNoLabel, Os, Ob );
Buy = Cross (Osc, Os);
Sell = Cross (Ob, Osc);
PlotShapes(Buy*shapeUpArrow,colorGreen);
PlotShapes(Sell*shapeDownArrow,colorRed);
Plot(Os,”",colorAqua,1+4);
Plot(Ob,”",colorPink,1+4);
_SECTION_END();
_SECTION_BEGIN(“SUPPORT/RESISTANCE”);

SelectedIndicator = ParamList( “SUPPORT/RESISTANCE”, “Trendlines_Wedge,fibo,STDDEVLNES”, 0);

_SECTION_BEGIN(“STDDEVLNES”);
Daysback = Param(“Period for Liner Regression Line”,21,1,44000,1);
shift = Param(“Look back period”,0,0,240,1);
LRColor = ParamColor(“LR Color”, colorRed );
SDP = Param(“Standard Deviation”, 1.3, 0, 13, 0.1);
SDColor = ParamColor(“SD Color”, colorYellow );
SDP2 = Param(“2d Standard Deviation”, 2.1, 0, 13, 0.1);
SDColor2 = ParamColor(“2 SD Color”, colorBrightGreen );
SDP3 = Param(“3d Standard Deviation”, 3.4, 0, 13, 0.1);
SDColor3 = ParamColor(“3 SD Color”, colorRed );
_SECTION_END();

switch ( SelectedIndicator )
{

case “STDDEVLNES”:
_SECTION_BEGIN(“STDDEVLNES”);

P = Value1;

// =============================== Math Formula =============================================================

x = BarIndex();
lastx = LastValue( x ) – shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x – (Lastx – DaysBack +1 ) );

// ==================Plot the Linear Regression Line ==========================================================

LRLine = IIf( x > (lastx – Daysback) AND x < Lastx, y, Null );
Plot( LRLine , “LinReg”, LRCOLOR, styleLine+4 ); // styleDots );

// ========================== Plot 1st SD Channel ===============================================================

SD = SDP/2;

width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU = IIf( x > (lastx – Daysback) AND x < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx – Daysback) AND x < Lastx, y-width , Null ) ;

Plot( SDU , “Upper Lin Reg”, SDColor,styleLine );
Plot( SDL , “Lower Lin Reg”, SDColor,styleLine );

// ========================== Plot 2d SD Channel ===============================================================

SD2 = SDP2/2;

width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU2 = IIf( x > (lastx – Daysback) AND x < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx – Daysback) AND x < Lastx, y-width2 , Null ) ;

Plot( SDU2 , “Upper Lin Reg”, SDColor2,styleLine );
Plot( SDL2 , “Lower Lin Reg”, SDColor2,styleLine );

// ========================== Plot 3d SD Channel ===============================================================

SD3 = SDP3/2;

width3 = LastValue( Ref(SD3*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
SDU3 = IIf( x > (lastx – Daysback) AND x < Lastx, y+width3 , Null ) ;
SDL3 = IIf( x > (lastx – Daysback) AND x < Lastx, y-width3 , Null ) ;

Plot( SDU3 , “Upper Lin Reg”, SDColor3,styleDashed+4 );
Plot( SDL3 , “Lower Lin Reg”, SDColor3,styleDashed+4 );

_SECTION_END();

break;

case “Trendlines_Wedge”:
_SECTION_BEGIN(“Trendlines_Wedge”);
G=0;// set G=1, 2, 3, … to see previous Resistance trendlines
GG=0;// set G=1, 2, 3, … to see previous Support trendlines
x = Cum(1);
per = 1;// sensitivity calibration
s1=Value1;s11=Value1;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1+GG ));
startt=LastValue(ValueWhen( pS, x, 2+GG ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1+GG ) );
startS = LastValue( ValueWhen( pS, s1, 2+GG ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;// the Support trendline equation
Plot(IIf(x>startt-6 AND TRENDLINES>0 AND TRENDLINES0,5,4),8);
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1+G ));
startt1=LastValue(ValueWhen( pR, x, 2+G ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1+G ) );
startR = LastValue( ValueWhen( pR, s11, 2 +G ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;// the Resistance trendline equation
Plot(IIf(x>startT1-6 AND TRENDLINER>0 AND TRENDLINER0,5,4),8);
Ascwedge=Ar>0.5 AND As>sqrt(2)*Ar AND trendlineR>trendlineS;
Descwedge= AsAr/sqrt(2) AND trendlineR>trendlineS;
_SECTION_END();
break;

case “fibo”:
_SECTION_BEGIN(“fibo”);
barvisible = Status(“barvisible”);
r = Value1;
maxr = LastValue( Highest( IIf( barvisible, r, 0 ) ) );
minr = LastValue( Lowest( IIf( barvisible, r, 100 ) ) );
ranr = maxr – minr;
Plot( maxr , “0%”, colorGrey50,styleDashed );
Plot( maxr – 0.236 * ranr, “-23.6%”, colorViolet,styleDashed+4 );
Plot( maxr – 0.382 * ranr, “-38.2%”, colorYellow,styleDashed );
Plot( maxr – 0.50 * ranr, “-50.0%”, colorOrange,styleDashed,styleDashed );
Plot( maxr – 0.618 * ranr, “-61.8%”, colorViolet,styleDashed+4 );
Plot( minr , “-100%”, colorGrey50,styleDashed );
GraphXSpace = 3;
_SECTION_END();

break;
}

_SECTION_END();

 

Screenshot of the 14 Indicators AFL Parameters after it is configured

Amibroker AFL
Thanks to my friend, Ankit Dargan for creating this AFL and presenting to us.

13 Comments

  1. prithviraj says:

    mam can u please provide a simple procedure on how to add this please…

  2. prithviraj says:

    procedure i followed…..
    1. copied entire (grey coloured )codes above,
    2. amibroker—>formula editor—>paste—>save as—>ovbt ovsd suppand rest,
    3. tried backtesting, scan & exploring but gives an error……..

    s i also put support n resistance zones for comfort of a trader namely trendlines, Fibonacci lines and standard deviation line plus overbought n oversold zone(custom) in clouded area.

    plotted by – Ankit Dargan for http://www.analystcalls.in

    */

    _SECTION_BEGIN(“
    —————^

    Error 31.
    Syntax error, unexpected $end, expecting ‘)’ or ‘,’
    4. well im stuck here,
    5. Thanks for replying so fast
    6. happy trading week!

  3. Priya says:

    now paste the code once again by copying from this article. there might be small error in syntax somewhere. I replaced it. do check once again with the new code in the article and let me know the result.

  4. prithviraj says:

    still an error….
    plus overbought n oversold zone(custom) in clouded area

    plotted by – ankit dargan

    */

    _SECTION_BEGIN(“
    —————^

    Error 31.
    Syntax error, unexpected $end, expecting ‘)’ or ‘,’

  5. prithviraj says:

    Thank you, I am greatfull to you!

  6. Pooja says:

    hi mam,

    even i’m getting this errror… kindly advise..thanks
    */
    _SECTION_BEGIN(“
    —————^
    Error 31.
    Syntax error, unexpected $end, expecting ‘)’ or ‘,’

  7. muksh kumar says:

    Priya plz describe here as how we include our afl got from here in our amibroker.Plz describe step by step.
    Reply

  8. Amit Choksi says:

    Following Error in Amibroker AFL for 14 Oversold and 14 Overbought Indicators:
    File: ‘Formulas\Drag-drop MULTI INDICATOR 1.afl’ , Ln:9, Col: 16,
    Error 3.1
    Syntax erro,r unexpected $end, expecting ‘)’ or ‘,’
    Use ‘edit formula’ to correct error”

    Could you please look into it.

  9. boopa says:

    Hi
    I am getting error after downloading your 14oversold and overbought indicators in AFL like
    Ln:9,col:16:Error31,Syntaxerror,unexpected$end, expecting’)'or’,’ can u kindly help me to download please. I have tried in Onibalusi Bamide page also but nothing available.

  10. chinmay555 says:

    Mam
    i have an error

    _SECTION_BEGIN(“14 Oversold n Overbought indicators with Support n Resistance”);

    how to upload this afl

0 Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

7075 k