Skip to main content

Trend Indicator for Amibroker (AFL)

Divyesh over 13 years ago Amibroker (AFL)

  • Rating:
    3 / 5 (Votes 6)
  • Tags:
    amibroker, trend, timeframe

This Trend Indicator based on EMA and Donchian Channel.
Buy Sell Signals given for signals to signal tread.
One can tread intraday on Bar color….! as Buy when Green Bar and Exit on Blue Bar, if Green Bar again comes after Blue Bar re enter in buy till next Blue Bar…..!
Vise Varsa,
Sell on Red Bar exit on Blue Bar re enter if Red Bar appears after Blue Bar….!
Theam and Idea Taken from :- http://www.wisestocktrader.com/indicators/3526-expert-trend-locator ( Thnx pipstock )

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Price");
pds = 20; 
MAFAST = EMA( Close, 20 ); 
MASLOW = EMA( Close, 40 ); 
  
DonchianUpper = HHV( Ref( H, -1 ), pds ); // Highest high value of highs in last 20 periods 
DonchianLower = LLV( Ref( L, -1 ), pds ); // Lowest low value of low in last 20 periods 
DonchianMiddle = ( DonchianUpper + DonchianLower ) / 2; 
  
UpTrend = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close, 40 ); 
DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close, 40 ); 
Color = IIf( UpTrend, colorGreen, IIf( DnTrend, colorRed, colorBlue) ); 
UpTrend=ExRem(UpTrend,DnTrend);
Dntrend=ExRem(DnTrend,UpTrend);
// Plots a 20 period Donchian channel 
Plot( C, "Price", Color, styleBar | styleThick ); 
NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0); 
Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1); 
_SECTION_END();
PlotShapes(IIf(UpTrend, shapeUpArrow, shapeNone),colorBrightGreen, 0,L, Offset=-45); 
PlotShapes(IIf(DnTrend, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-45);


_SECTION_BEGIN("L.T.P.");
cx = Param( "cxposn", 1000, 0, 1250, 1 );
cy = Param( "cyposn", 25, 0, 500, 1 );
GfxSelectFont( "Candara", 18, 98, False );
gfxcup	= SelectedValue(C > Ref(C,-1));
gfxpcolor = IIf(gfxcup,colorBrightGreen,colorRed);
GfxSetTextColor(gfxpcolor);
//GfxSetTextColor( colorWhite );
GfxTextOut( "L.T.P.  " + C + " ", cx, cy );
_SECTION_END();

_SECTION_BEGIN("Background text");
SetChartBkColor(colorBlack);
strWeekday = StrMid("---sunday---Monday--TuesdayWednesday-Thursday--Friday--Saturday", SelectedValue(DayOfWeek())*9,9);
GraphXSpace=Param("GraphXSpace",0,-55,200,1);
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Candara", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Candara", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "Sai Stock Broking 09825340778", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
_SECTION_END();

_SECTION_BEGIN("Title");

DODay = TimeFrameGetPrice("O", inDaily);
DHiDay = TimeFrameGetPrice("H", inDaily); 
DLoDay = TimeFrameGetPrice("L", inDaily); 
Title = EncodeColor(colorWhite)+"* SAI STOCK BROKING 09825340778 *  "+EncodeColor(colorWhite)+ Name() + ", " + Interval(2) + ", " + Date() + "   -  "+strWeekday + "  - " +
EncodeColor(colorWhite)   +  "\nO " + EncodeColor(colorWhite) + O + 

 ",   H :  "   + H + 
 ",   L  :  " + L + 
 ",   C  :  "  + C +
"\n"+EncodeColor(colorWhite)+ "  Day-Open : " +DODay + "  Day-High : " +DHiDay + "  Day-Low : " + DLoDay 


;
_SECTION_BEGIN("Time Left");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;

x=Param("xposn",430,0,1000,1);
y=Param("yposn",40,0,1000,1);

GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New period" );
}

cx = Param( "cxposn", 1080, 0, 1250, 1 );
cy = Param( "cyposn", 5, 0, 500, 1 );
GfxSelectFont( "Candara", 14, 98, False );
//gfxcup	= SelectedValue(C > Ref(C,-1));
//gfxpcolor = IIf(gfxcup,colorBrightGreen,colorRed);
GfxSetTextColor(colorBlue);
//GfxSetTextColor( colorWhite );
GfxTextOut( "T i m e L e f t   " + SecsToGo + " ", cx, cy );
_SECTION_END();

1 comments

Leave Comment

Please login here to leave a comment.