AFL writing guide for new user

#41
ANIMATED AFL BACKGROUND CHART​

Here is the code that will make an animated background of your chart. I made this only for fun purpose.
Here is the code. Try this.


_SECTION_BEGIN("Debarghya: AFL Coding");

for( i = 1; i < BarCount; i++ )
z = (GetPerformanceCounter()/100)%256;
anim=ColorHSB( ( i + z ) % 256, 255, 100 );
SetChartBkColor(anim);
RequestTimedRefresh(1);



SetBarFillColor( IIf( Close > Open, colorWhite, colorBlack ) );
Plot(C,"Price", colorBlack, styleCandle );
Plot(EMA(C,3),"SMA(3)", colorRed );
Plot(EMA(C,13),"SMA(13)", colorGreen );

_SECTION_END();
 
#42
HOW TO SET TITLE in AFL​

Let set the title in the AFl code.

here is the Syntax:

Title = " {{NAME}} {{DATE}} {{INTERVAL}} "+"Your Text"+" Chart values :{{VALUES}} ";


  • {{NAME}}: Script Name
  • {{DATE}}: date
  • {{INTERVAL}}: Time interval, 5/10/15/30 min
  • "Your Text" : Any text you want to use. This text you can use as your signature of the code.
  • {{VALUES}}: Other options, like EMA, MA etc settings values will be there.
 
#43
HOW TO MAKE VISUAL BAND IN AFL



here is the code

_SECTION_BEGIN("Debarghya: AFL Coding");

Title = " {{NAME}} {{DATE}} {{INTERVAL}} "+"Debarghya: AFL Coding";

Plot(EMA(H,3),"EMA(3)",colorRed,styleLine);
Plot(EMA(L,13),"EMA(13)",colorBlack,styleLine);

PlotOHLC( Open,High,Low,Close, "MA", colorRed, styleCandle);
PlotOHLC( EMA(H,3),EMA(H,3),EMA(L,13),EMA(L,13), "EMA BAND", colorDarkBlue, styleCloud);
_SECTION_END();



Looking like we have done something great this time. Many popular AFL has this type of bands. Great Debarghya. But what the heck is that?
Well this a humble band of EMA(3) and EMA(13) along with the price. Entire band is easy to visualize. PlotOHLC() function is making this band.
PlotOHLC( open, high, low, close, name, color/barcolor, style = styleCandle | styleOwnScale, minvalue = {empty}, maxvalue = {empty}, XShift = 0, ZOrder = 0 )
 
Last edited:
#44
3/13 EMA CLOUD SYSTEM

Here is the code

_SECTION_BEGIN("Debarghya: AFL Coding");
SetChartOptions(0,0,ChartGrid30 | ChartGrid70 );
em3=EMA(C,3);
em13=EMA(C,13);
Plot( em3, "EMA(3)", colorRed );
Plot( em13, "EMA(13)", colorGreen );

PlotOHLC( Open,High,Low,Close, "Price", colorRed, styleCandle);
PlotOHLC( em3,em3,em13,em13, "", IIf( em3 > em13, colorGreen, colorRed ), styleCloud | styleClipMinMax );

_SECTION_END();
 
#45
PLOT PRICE LEVEL AT EVERY SELL AND BUY SIGNAL


Here is the Code:

_SECTION_BEGIN("Debarghya: AFL Coding");
SetChartOptions(0,0,ChartGrid30 | ChartGrid70 );
em3=EMA(C,3);
em13=EMA(C,13);
Plot( em3, "EMA(3)", colorRed );
Plot( em13, "EMA(13)", colorGreen );

PlotOHLC( Open,High,Low,Close, "Price", colorRed, styleCandle);
PlotOHLC( em3,em3,em13,em13, "", IIf( em3 > em13, colorGreen, colorRed ), styleCloud | styleClipMinMax );

Buy=Cross( em3, em13 );
Sell= Cross( em13,em3 );
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, colorGreen,colorYellow );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorRed, colorYellow );
}
_SECTION_END();


I am using
PlotText( ''text'', x, y, color, bkcolor = colorDefault )
to display entry and exit level.
 
#46
PLOT TEXT IN ANY WHERE IN CHART​


Code:

_SECTION_BEGIN("Debarghya: AFL Coding");

SetChartOptions(2, chartWrapTitle );
SetBarFillColor( IIf( Close > Open, colorWhite, colorBlack ) );
Plot(C,"Price", colorBlack, styleCandle );
Plot(EMA(C,3),"SMA(3)", colorRed );
Plot(EMA(C,13),"SMA(13)", colorGreen );

GfxRectangle( 100, 20,430, 100);
GfxSetTextColor( ColorRGB( 120, 100, 140 ));
GfxTextOut( "This AFl is MADE BY Debarghya Mukherjee",110, 25 );
_SECTION_END();


I am using GfxTextOut( "This AFl is MADE BY Debarghya Mukherjee",110, 25 ); function to plot text at 110,25 position in the chart. User can change this position to plot his text.
 
#47
Ok friends good night to all of you. If you get time then make some comments.
I guess this updated AFLs will be useful to all of you.
 
#48
MACD WITH COLORFUL HISTOGRAM AFL

Normal MACD with Histogram code,
_SECTION_BEGIN("Debarghya: AFL Coding");

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
Plot( m1 = MACD(r1, r2), "MACD color", colorRed );
Plot( s1 = Signal(r1,r2,r3), "Signal", colorBlue );
Plot( m1-s1, "MACD Histogram", colorBlue , styleHistogram );


GfxRectangle( 100, 20,500, 70);
GfxSetTextColor( ColorRGB( 120, 100, 140 ));
GfxTextOut( "MACD with Histogram is \n MADE BY Debarghya Mukherjee",110, 25 );
_SECTION_END();


Now we can make our histogram more visually helpful( like the picture given) by making them colorful or MACD and Signal cross.
Here is the Code:

_SECTION_BEGIN("Debarghya: AFL Coding");

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
Plot( m1 = MACD(r1, r2), "MACD color", colorRed );
Plot( s1 = Signal(r1,r2,r3), "Signal", colorBlue );
Plot( m1-s1, "MACD Histogram", IIf(m1 > s1, colorGreen, colorRed) , styleHistogram );


GfxRectangle( 100, 20,500, 70);
GfxSetTextColor( ColorRGB( 120, 100, 140 ));
GfxTextOut( "MACD with Histogram is \n MADE BY Debarghya Mukherjee",110, 25 );
_SECTION_END();
 
#49
MACD WITH COLORFUL HISTOGRAM AFL

Normal MACD with Histogram code,
_SECTION_BEGIN("Debarghya: AFL Coding");

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
Plot( m1 = MACD(r1, r2), "MACD color", colorRed );
Plot( s1 = Signal(r1,r2,r3), "Signal", colorBlue );
Plot( m1-s1, "MACD Histogram", colorBlue , styleHistogram );


GfxRectangle( 100, 20,500, 70);
GfxSetTextColor( ColorRGB( 120, 100, 140 ));
GfxTextOut( "MACD with Histogram is \n MADE BY Debarghya Mukherjee",110, 25 );
_SECTION_END();


Now we can make our histogram more visually helpful( like the picture given) by making them colorful or MACD and Signal cross.
Here is the Code:

_SECTION_BEGIN("Debarghya: AFL Coding");

r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
m1 = MACD(r1, r2);
s1 = Signal(r1,r2,r3);
Plot( m1 = MACD(r1, r2), "MACD color", colorRed );
Plot( s1 = Signal(r1,r2,r3), "Signal", colorBlue );
Plot( m1-s1, "MACD Histogram", IIf(m1 > s1, colorGreen, colorRed) , styleHistogram );


GfxRectangle( 100, 20,500, 70);
GfxSetTextColor( ColorRGB( 120, 100, 140 ));
GfxTextOut( "MACD with Histogram is \n MADE BY Debarghya Mukherjee",110, 25 );
_SECTION_END();
 
#50
CUSTOMIZED AFL FOR NEW USERS SAMPLE 1​

Here I am showing you a new afl. Our signal is, every time price crosess 50 ema we will buy. and once it closes below 20 ema we sell. Lets see how we can write the AFL for it.

_SECTION_BEGIN("visual arrow ema cross over");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( Close, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

Buy= Cross(Close, EMA( C, 50 ));
Sell= Cross(EMA( C, 20 ),Close);


PlotShapes(IIf(Sell==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Buy==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);

Plot( EMA( C,20), "20 EMA Close",ParamColor("EMA 20 Color", colorGreen ),styleNoRescale);
Plot( EMA( C,50), "50 EMA Close",ParamColor("EMA 50 Color", colorRed ),styleNoRescale);
_SECTION_END();


Here is the output
Hi, I would be grateful if you could add two lines, as shown in the image below, right after the crossover occurs, please code it in such a way that emas can be modified, and the lines comes into view only after the buy signal occurs.. The lines should represent High & Low points of the bar on which the crossover occured..


Regards
 

Similar threads