AFL writing guide for new user

asnavale

Well-Known Member
#21
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 Deb,

Good effort and initiative. I will help whenever I feel it is needed. Please Continue your work.


In the Buy/Sell conditions in your AFL above, there is no need to write BUY == 1 or SELL == 1. It is sufficient to write .... IIf(BUY, .....) and .... IIf(SELL, .....). This will make the code a bit shorter and run a bit faster.

In the image you attached, there are two consecutive SELL arrows at the right end. There should be a BUY arrow between them. In a cross-over system, the BUY and SELL signals always alternate.

-Anant
 
Last edited:
#23
I want combine two afl.

One afl is candalstick chart with Buy Sell Signal.

Afl is belowe.

_SECTION_BEGIN("Ensign Volatility Stop");

// Ensign Volatility Stop
// get the multiple of 9 period EMA of ATR_Ensign

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
k=Param("multiplication factor", 1,0.5,5,0.1);

period=k*5;
VS_raw = 2.2 * EMA(ATR(1), period);

// for longs, VS line is below price
loline = VS_below_price = HHV(Close, period) - VS_raw;

// for shorts, VS line is above price
hiline = VS_above_price = LLV(Close, period) + VS_raw;
between = IIf (C < hiline AND C > loline, 1, 0);
up = IIf(C > hiline OR (H > Ref(H, -1) AND H > hiline), 1, 0);
dn = IIf(C < loline OR (L < Ref(L, -1) AND L < loline), 1, 0);
upcond = IIf(between AND BarsSince(up) < BarsSince(dn) , 1, 0);
dncond = IIf(between AND BarsSince(dn) < BarsSince(up) , 1, 0);
upline = IIf(up OR upcond, loline, Null);
dnline = IIf(dn OR dncond, hiline, Null);

Buy=upline;
Sell=dnline;

Col = IIf(Buy,colorGreen,IIf(Sell,colorRed,colorBlack));

Plot(C, "", col, styleBar | styleThick );

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy, Low, High ) );


Second afl is SUPPORT AND RESISTANCE These afl is show All support and Resistance.

The afl is below

//|-----------------------------------------------------------------------------------------
//|PatternExplorer.com - Support & Resistance
//|Copyright 2007, PatternExplorer.com
//|http://www.PatternExplorer.com
//|e-mail: [email protected]
//|-----------------------------------------------------------------------------------------
FormulaName = "PE - S & R";

SetChartOptions( 0, chartShowDates | chartLogarithmic | chartWrapTitle );
#pragma nocache
#include_once <\PEInc\PatternExplorer_f0.afl>
#include_once "Formulas\PatternExplorer\#Defaults & Mods\PE - Defaults.afl"
#include_once "Formulas\PatternExplorer\#Defaults & Mods\PE - Mods.afl"
/*******************************************************************************************/
AddCustomCodeBeforePE();
/*******************************************************************************************/

_SECTION_BEGIN( "Main Parameters" );
AddparamUsefromChart( def_UseFromChart );
Sensitivity = Param( "Sensitivity", 10, 0, 100, 1 );

if ( InChart )
StaticVarSet( "FYIOKU", Sensitivity );

if ( inAA AND Usefromchart )
Sensitivity = StaticVarGet( "FYIOKU" );

DisRange = Param( "Plot 'far away' Lines Trigger", 3, 0, 10, 0.5 );

Color_SL = ParamColor( "Support", def_Color1 );

Color_RL = ParamColor( "Resistance", colorRed );

_SECTION_END();

/*******************************************************************************************/
#include_once <\PEInc\PatternExplorer_1.afl>
#include_once <\PEInc\Lib\PatternExplorer_f15.afl>
/*******************************************************************************************/
BS = break_G1_val == 1 OR break_G2_val == 1;

SS = break_G1_val == -1 OR break_G2_val == -1;

Buy = def_Buy AND BS;

Sell = SS;

/*******************************************************************************************/
Filter = def_Filter AND BarIndex() == LastValue( BarIndex() ) AND NOT GroupID() == 253;

Filter = Filter AND ( Buy OR Sell );

/*******************************************************************************************/
Addefaultcolumns();

Adddefaultcolumns( 2, 1 );

AddTextColumn(
WriteIf( break_G1_val == -1, "Break",
WriteIf( break_G1_val == 1, "Break", "" ) ), "Minor Levels", 1.2,
IIf( break_G1_val == 1, colorGreen, IIf( break_G1_val == -1, colorRed, colorBlue ) ) );

AddTextColumn(
WriteIf( break_G2_val == -1, "Break",
WriteIf( break_G2_val == 1, "Break", "" ) ), "Major Levels", 1.2,
IIf( break_G2_val == 1, colorGreen, IIf( break_G2_val == -1, colorRed, colorBlue ) ) );

AddTextColumn( FullName(), "Full name" );

/*******************************************************************************************/
Plot( IIf( x >= XT1 & RT1 &NOT T1 == 0, T1, -1e10 ), "T1", IIf( LastValue( C ) < T1, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XT2 & RT2 &NOT T2 == 0, T2, -1e10 ), "T2", IIf( LastValue( C ) < T2, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XT3 & RT3 &NOT T3 == 0, T3, -1e10 ), "T3", IIf( LastValue( C ) < T3, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XT4 & RT4 &NOT T4 == 0, T4, -1e10 ), "T4", IIf( LastValue( C ) < T4, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XT5 & RT5 &NOT T5 == 0, T5, -1e10 ), "T5", IIf( LastValue( C ) < T5, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XP1 & RP1 &NOT P1 == 0, P1, -1e10 ), "P1", IIf( LastValue( C ) < P1, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XP2 & RP2 &NOT P2 == 0, P2, -1e10 ), "P2", IIf( LastValue( C ) < P2, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XP3 & RP3 &NOT P3 == 0, P3, -1e10 ), "P3", IIf( LastValue( C ) < P3, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XP4 & RP4 &NOT P4 == 0, P4, -1e10 ), "P4", IIf( LastValue( C ) < P4, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XP5 & RP5 &NOT P5 == 0, P5, -1e10 ), "P5", IIf( LastValue( C ) < P5, Color_RL, Color_SL ), 1 + 2048 + styleNoTitle );

Plot( IIf( x >= XT6 & RT6 &NOT T6 == 0, T6, -1e10 ), "T6", IIf( LastValue( C ) < T6, Color_RL, Color_SL ), 8 + 2048 + styleNoTitle );

Plot( IIf( x >= XT7 & RT7 &NOT T7 == 0, T7, -1e10 ), "T7", IIf( LastValue( C ) < T7, Color_RL, Color_SL ), 8 + 2048 + styleNoTitle );

Plot( IIf( x >= XP6 & RP6 &NOT P6 == 0, P6, -1e10 ), "P6", IIf( LastValue( C ) < P6, Color_RL, Color_SL ), 8 + 2048 + styleNoTitle );

Plot( IIf( x >= XP7 & RP7 &NOT P7 == 0, P7, -1e10 ), "P7", IIf( LastValue( C ) < P7, Color_RL, Color_SL ), 8 + 2048 + styleNoTitle );

/*******************************************************************************************/
ToolTip = def_ToolTip;

/*******************************************************************************************/
AddCustomCodeAfterPE();

/*******************************************************************************************/
Title = "PatternExplorer.com - Support & Resistance" + default_priceTitle + EncodeColor( IIf( NOT AnZ, def_Text2, colorRed ) ) + ",Sensitivity = " + WriteVal( Sensitivity, 1 ) + " " + EncodeColor( colorRed ) + WriteIf( NOT AnZ, "", " NO POINTS AVAILABLE -> REDUCE SENSITIVITY " );


Any one can combine these two afl.
If price is 5200 on bar chart.
Support is 5100 and resitance is 5400.
i want support resistance price on bar chart.
Support means stop loss and resitance means target.
Means current nifty trade 5200 stop loss is 5100 and target is 5400.
these information is show on bar chart without support and resitance chart.

If any one can do these pls try.

Thanks
 
#24
Be a Guru and start again

Just I started learning and Mr.Mukherjee stopped posting !
Sir ! why are you worrying about the crowd ? It will be always like this.
But teach for those who have real intention to learn .Previously I too was part of the crowd.
Then I started to write my AFL (only one) collecting bits from our AFL gurus.
( actually afraid to touch any AFL since having no programming knowledge)
Be positive and start posting ! Thanks for the inputs so far and forthcoming !
Happy Trading!
 
Last edited:
#25
Re: Be a Guru and start again

Thank you for your nice comment here.
Writting AFL is not a big Credit. All you need a trading plan. Once you have your trading strategy then write it in language of AFL.

AFL has some basic syntax that draws lines, curves and few extra things like arrow, box etc for better understanding of trading signals.

I do not have gets lots of traffic here. May be I am not a good article writter. So I stopped posting here. And People are more interested in ready made AFL written by somebody else with 200 lines of code not by understanding the logic. :D

Sorry I am not going to post here hefty 1000 lines codes AFL and wil claim "Here is the Holy grail of NIFTY" :D All I want to do is that I want to guide new traders to understand AFL and trading logic. :)

It is night here. May be I will post some new easy techniques soon. :p
Good night and have great Sunday

Just I started learning and Mr.Mukherjee stopped posting !
Sir ! why are you worrying about the crowd ? It will be always like this.
But teach for those who have real intention to learn .Previously I too was part of the crowd.
Then I started to write my AFL (only one) collecting bits from our AFL gurus.
( actually afraid to touch any AFL since having no programming knowledge)
Be positive and start posting ! Thanks for the inputs so far and forthcoming !
Happy Trading!
 
#26
Simplicity remains forever . The Pompous rich men vanished into thin air.
Simple Gandhiji and Mother Teresa remain in our hearts.
Perhaps learning AFL may take some time.But I believe slow and steady will win the race.
Learning something is better than nothing.
Awaiting the posts.
Thanks.
 
#28
Dear sir i wants to add price value with signal in bollinger band afl it is good for trend direction example when give buy signal is also plot price value
 
#29
Writting AFL means implementing your logic in AFL language, that is the core language of Amiborker. It ir near to C or C++.
You can try my posted AFL for early try.
Best of Luck
Debarghya Mukherjee


is writing AFL a programming?

(newbie)
 
#30

Similar threads