Saturday, 2 November 2013

Aroon Oscillator AFL for Amibroker



Making money with share trading has become an art. The share trader needs to arm himself with a technical analysis software and data. above all he needs to have the right king of methodology in place.To day i am posting an AFL called Aroon Oscillator which is one of the most reliable method of trend finding.

The Aroon Oscillator is essentially the difference between Aroon-Up and Aroon-Down. The Aroon –Up and Aroon –Down along with the difference of these two values are plotted together for a chart reader’s reference. This Oscillator fluctuates between -100 and +100. There is a middle line which is taken as zero. When the oscillator is positive it indicates a positive trend in the market.  When it is negative it should be taken as the market is in bearish mode. In other words, a greater value above zero of Aroon-Up than Aroon-Down indicates the price movement of the share in question to take an upward turn or see new highs in the following trading days. On the contrary, if the Aroon Down is greater than Aroon –Up, which is an indication of weakness of the share in question.
 

The AFL that I am posting today can be customized with changing of colors, plotting of levels etc as shown above.
The Aroon Oscillator is a very simple indicator that clearly suggests the trend of the market. For a beginner of technical analysis, this oscillator could be an excellent tool. I am posting the AFL  of Aroon Oscillator below for the those who are interested.
Best of Luck
///////////////////////////////////////code begins below this line///////////////////////////////
 _SECTION_BEGIN("Aroon/Prices");
if( ParamToggle("Tooltip Shows", "Aroon|Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
Aroonswitch = ParamToggle("Aroon","On,Off");
Periods = Param("Aroon Periods", 14, 1, 100, 1 );
_SECTION_END();

_SECTION_BEGIN("Aroon_UP");
UPcolor = ParamColor( "Aroon_UP Color", colorGreen );
UPstyle = ParamStyle("Aroon_UP Style",styleThick);
_SECTION_END();

_SECTION_BEGIN("Aroon_DN");
DNcolor = ParamColor( "Aroon_DN Color", colorRed );
DNstyle = ParamStyle("Aroon_DN Style",styleThick);
_SECTION_END();

_SECTION_BEGIN("Aroon_Oscillator");
OSswitch = ParamToggle("Aroon_OSc","On,Off");
OScolor = ParamColor( "Aroon_OSc Color", colorBlack );
OSstyle = ParamStyle("Aroon_OSc Style",styleHistogram | styleOwnScale, maskHistogram );
_SECTION_END();

HHVBarsSince = HHVBars(H, Periods+1);
LLVBarsSince = LLVBars(L, Periods+1);

Aroon_Up = ((Periods - HHVBarsSince) / Periods) * 100;
Aroon_Down = ((Periods - LLVBarsSince) / Periods) * 100;
Aroon_Osc = Aroon_Up - Aroon_Down;

Plot(IIf(Aroonswitch,Null,Aroon_Up),"Aroon_Up",UPcolor,UPstyle);
Plot(IIf(Aroonswitch,Null,Aroon_Down),"Aroon_Down",DNcolor,DNstyle);
Plot(IIf(OSswitch,Null,Aroon_Osc),"Aroon_Osc",OScolor,OSstyle);

UPline = Param("Upper Limit",80,50,100,1);
DNline = Param("Down Limit",20,1,50,1);
Plot(UPline,"",ParamColor("Upper Limit Color",4),ParamStyle("Upper Limit Style",styleNoLabel+styleDashed ));
Plot(DNline,"",ParamColor("Down Limit Color",5),ParamStyle("Down Limit Style",styleNoLabel+styleDashed ));
Plot(50,"",6, ParamStyle("Center Line Style",styleNoLabel ));

_SECTION_BEGIN("Fill Color");
Fillswitch = ParamToggle("Fill Color1","On,Off");
r1 = Aroon_down;
r2 = Aroon_Up;
FillColor = IIf( r1 > 50 OR r2 < 50, ParamColor("Up Fill Color1", colorRose),ParamColor("Down Fill Color1", colorPaleGreen));
if (NOT Fillswitch) PlotOHLC( r1,r1,50,r1, "", FillColor, styleNoLabel | styleCloud | styleClipMinMax, DNline, UPline );
if (NOT Fillswitch) PlotOHLC( r2,r2,50,r2, "", FillColor, styleNoLabel | styleCloud | styleClipMinMax, DNline, UPline );
_SECTION_END();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Monday, 28 October 2013

Amibroker AFL with Buy Sell signals for Intraday and Positional trading


Many traders are always on the lookout for new and successful trading ideas and tools. today I am posting an AFL which I came across. This AFL could be used in Intraday on a longer time frame say one hour charts or 15 minutes charts.. On a shorter time frame it tends to develop whipsaw like signals. The signals generated should be confirmed with a simple MACD or T3, before entering a trade. The AFL can be customized for individual preference. 

For Nifty traders the ideal time frame with this AFL seems to be 60 minutes or Hourly charts. For other equities the  AFL works well with a time frame of 15 minutes. There is also a magnified market view for easy viewing.

This AFL gives alert call whenever a buy or sell signal is generated.I hope this afl would be helpful for trading purpose and also students of Technical analysis.

The AFL is not available for free download. Kindly mail me for details citing reference number AFLDT2810

Enjoy and best of luck








Monday, 21 October 2013

Amibroker AFL for Intra-day trading with multitple time frame

 Today I am posting another interesting AFL. This AFL can be successfully used for trading in multiple time frame. I have tested this in Intraday trading with larger time frame like 15 minutes and hourly charts, and on many instances, profitable trading was done. This AFL can suggest price 3 targets which I think can help us to exit the trade at comfortable levels.I request the readers, to copy this code and TEST this by doing paper trading. If you are well versed with the parameters and the functioning of this AFL only then you should use this on a regular basis. Again do not use AFL alone, always use with other indicators.

So, Good Luck and best wishes.

////////////////////////////////////////////////////////////////Code is posted below/////////////////////////////////////////////////////////

_SECTION_BEGIN("Trend Lines");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorGreen), ParamColor("TL Dn Colour", colorRed));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();

_SECTION_BEGIN("Linear Regression Channel");


SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
SetChartBkGradientFill(ParamColor("Top", colorTeal), ParamColor("Bottom", colorLightGrey), ParamColor("Title", colorTeal));
SetChartBkColor(colorTeal);


Plot( C, "Close", colorWhite, styleCandle, Zorder = 1);
SetChartOptions(0,chartShowArrows | chartShowDates);


_SECTION_BEGIN("HH");
Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
if ( HH[i] )
PlotText( "HH", i, H[ i ] + dist[i], colorRed );

if ( LH[i] )
PlotText( "LH", i, H[ i ] + dist[i], colorRed );

if ( HL[i] )
PlotText( "HL", i, L[ i ] - dist[i], colorBrightGreen );

if ( LL[i] )
PlotText( "LL", i, L[ i ] - dist[i], colorBrightGreen );

}

Filter=HH OR HL OR LH OR LL;
AddColumn(RSI(2),"RSI",1.2);
AddColumn(Close,"PRICE",1.2);
AddColumn(HH,"SHORT");
AddColumn(LH,"LH");
AddColumn(HL,"HL");
AddColumn(LL,"COVER");
AddColumn(V,"volume",1.0);
_SECTION_END();

_SECTION_BEGIN("Realtimetips ");
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 | styleCandle | GetPriceStyle() );
//
messageboard = ParamToggle("Message Board","Show|Hide",0);
showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);
no=10;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, C);
PlotShapes(exitlong * shapeDownArrow, colorRed,0,H,-12);
exitshort = Cross(C, s5d);
PlotShapes(exitshort * shapeUpArrow, colorGreen,0,L,-12);

Buy = exitshort;
Sell = exitlong;
Short = Sell;
Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);
AlertIf( Buy, "", "BUY @ " + C, 1 );
AlertIf( Sell, "", "SELL @ " + C, 2 );

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = s5d[i];
tar1 = entry + (entry * .0078);
tar2 = entry + (entry * .0234);
tar3 = entry + (entry * .0356);

bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = s5d[i];
tar1 = entry - (entry * .0078);
tar2 = entry - (entry * .0234);
tar3 = entry - (entry * .0356);

bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorOrange);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorCustom14, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorTurquoise, styleLine|styleDots, Null, Null, Offset);

for (i=bars; i <BarCount;i++)
{
PlotText("" + sig + " @ " + entry, BarCount+3, entry, Null, colorTurquoise);
PlotText("Target 1 : " + tar1, BarCount+3, tar1, Null, Clr);
PlotText("Target 2 : @ " + tar2, BarCount+3, tar2, Null, Clr);
PlotText("Target 3 : @ " + tar3, BarCount+3, tar3, Null, Clr);

PlotText("Trailing SL @ " + sl, BarCount+3, sl, Null, colorCustom14);
}
//Plot(sl, "", colorCustom14, styleLine);
printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago");
printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3);
printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2));

if (messageboard == 0 )
{
GfxSelectFont( "Tahoma", 11, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );

if ( sig =="BUY")
{
GfxSelectSolidBrush( colorGreen ); // this is the box background color
}
else
{
GfxSelectSolidBrush( colorRed ); // this is the box background color
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 2;
x2 = 180;

y = pxHeight;

GfxSelectPen( colorLightBlue, 1); // broader color
GfxRoundRect( x, y - 163, x2, y , 7, 7 ) ;

GfxTextOut( ("" + sig + " Signal came " + (BarCount-bars-1) * Interval()/60 + " mins ago"), 13, y-160) ; // The text format location
GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-120);
GfxTextOut( ("Trailing SL : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"), 13, y-140);
GfxTextOut( ("Target:1 : " + tar1), 13,y -100);
GfxTextOut( ("Target:2 : " + tar2), 13,y-80);
GfxTextOut( ("Target:3 : " + tar3), 13,y-60);
//GfxTextOut( ("Target:4 : " + tar4), 13,y-40);
GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-20);;

//x = 290;
//x2 = 570;
//GfxSelectSolidBrush( colorTurquoise );
//GfxSetTextColor( colorBlack);
//GfxSelectFont( "Tahoma", 14, 100 );
//GfxSetBkMode( 1 );
//GfxSelectPen( colorLightBlue, 1); // broader color
//GfxRoundRect( x, y - 43, x2, y , 7, 7 ) ;

//GfxSelectFont( "Tahoma", 10, 400 );

}
//

function PlotDT()
{
displacement = Param("Displacement Value", 12, 1, 100, 1);
slmode = ParamToggle("Stop Loss", "Auto|Manual", 1);
width = ParamToggle("Width", "HL|OC", 1);
Count = Param("No. of DTL", 4, 4, 20, 1);
NewDay = Day()!= Ref(Day(), -1);

for (i=BarCount-1;i > 1; i--)
{
if(NewDay[i] == 1)
{
printf("High : " + i);
if(width == 1)
{
DL = IIf(O[i] < C[i], O[i], C[i]);
DH = IIf(O[i] > C[i], O[i], C[i]);
}
else
{
DL = L[i];
DH = H[i];
}
Bars = i;
i = -1;
}
}

if(slmode==1)
{
distance = displacement;
}
else
{
distance = ((DH+DL)/2) * .01;
}

Plot(LineArray(BarCount - (BarCount-Bars+20), DH, BarCount+35, DH, 1), "", colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Buy Above " + DH + "; Stop Loss = " + DL, BarCount + 0, DH, colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DH+ distance), BarCount+35, (DH+ distance), 1), "", colorLime, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DH+ distance), BarCount + 0, (DH+ distance), colorBlack, colorLime);
Plot(LineArray(BarCount - (BarCount-Bars+20), DL, BarCount+35, DL, 1), "", colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Sell Below " + DL + "; Stop Loss = " + DH, BarCount + 0, DL, colorBlack, colorOrange);
Plot(LineArray(BarCount - (BarCount-Bars+20), (DL-distance), BarCount+35, (DL-distance), 1), "", colorOrange, styleLine|styleThick|styleDots, Null, Null, 20);
PlotText("Target = " + (DL-distance), BarCount + 0, (DL-distance), colorBlack, colorOrange);
}
function PlotIndicators()
{

SetChartOptions(0,chartShowArrows|chartShowDates);
/* Standard Error Bands */
Periods = Param("Standard Error", 80, 3, 200, 1);
Smooth = Param("Smooth",14,2,100,1);


LRCurve = LinearReg( C, periods );
MALRCurve = MA(LRCurve, Smooth);
SEValue = StdErr( C, periods );
SErrorAvg = MA(SEValue, Smooth);

LowerBand = MALRCurve - SErrorAvg ;
UpperBand = MALRCurve + SErrorAvg ;

Plot( MALRCurve , "MidBand", ParamColor("ColorMB",colorIndigo) , styleDashed|styleNoTitle);
Plot( LowerBand , "LowerBand", ParamColor("ColorLo",colorOrange) , styleLine|styleThick|styleNoTitle);
Plot( UpperBand , "UpperBand", ParamColor("ColorUp",colorGreen) , styleLine|styleThick|styleNoTitle);

Ch = TimeFrameGetPrice("C", in1Minute/60);
clr = IIf(Ch[BarCount-2] > Ch[BarCount-1],colorRed,colorLime);

Plot(LineArray(0,C[BarCount-1],BarCount-1,C[BarCount-1],15), "", Clr, styleLine|styleNoLabel, Null, Null, 30);
PlotText("CMP:" + C[BarCount-1], BarCount+5, C[BarCount-1],colorBlack,Clr);

LRPeriods = Param("Length", 40, 3, 200, 1);
LRCurve = LinearReg( C, LRPeriods );

PlotLR = IIf(LRCurve < LowerBand, (LRCurve + LowerBand)/2, IIf(LRCurve > UpperBand, (LRCurve + UpperBand)/2, LRCurve));
PlotLR = (PlotLR + SwingLine)/2;
Plot( PlotLR , "Stop Loss |", ParamColor("SLColor",colorBlue), 4+8+32+2048);
Plot( SwingLine, "SwingLine", ParamColor( "SWColor", colorBlue ), ParamStyle("StyleSW",style=styleThick|styleNoLabel , mask=maskDefault) );

bc1 = (Cross(C, MALRCurve) OR Cross(C, UpperBand) OR Cross(C, LowerBand)) AND (C > SwingLine);
bc2 = Cross(C, SwingLine) AND (C > MALRCurve OR C > UpperBand OR C > LowerBand);

sc1 = (Cross(MALRCurve, C) OR Cross(UpperBand, C) OR Cross(LowerBand, C)) AND (C < SwingLine);
sc2 = Cross(SwingLine, C) AND (C < MALRCurve OR C < UpperBand OR C < LowerBand);
Buy = bc1 OR bc2;
Sell = sc1 OR sc2;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
//PlotShapes(shapeCircle*Buy + shapeCircle *Sell, IIf(Buy, colorBlue, colorRed), 0, IIf(Buy, L, H), IIf(Buy, -12, 12));

}
//PlotDT();
_SECTION_END();

////////////////////////////////////////////////////////////////End of code//////////////////////////////////////////