AmiBroker formula Language

#91
Hi,

To add to Subratabera's code, the below AFL is the generalized one. You can give any EMA periods to both short and long periods.

You can use it for Explore also in Automatic Analysis.
......
Praveen.
Hi,

A small mistake in the AFL. Change the MyColor line to
MYcolor = IIf( EMA(C,ShortPeriod) > EMA(C,LongPeriod), colorBrightGreen, IIf(EMA(C,LongPeriod) > EMA(C,ShortPeriod), colorRed, colorBlue));

Praveen.
 
#92
Hi all,

I'm providing here with the skeleton code to write AFLs. This will help any AFL writers and should prove much useful to the beginners.

AFL skeleton code:
In simpler terms, an AFL can be broadly divided into:

1. Trading signal variables and its associates.
2. Common code in every AFL.


Trading signal variables and its associates:
This refers to the variables, which actually makes different trading systems. They are Buy and Sell variables. Whatever may be ones system, only the condition assigned changes.

Their corresponding associates are the ones, which are needed to further set the required settings, like MA period, Colour of bars/lines, sensitivity, etc.

Buy/Sell and at times their associates are the ONLY codes that changes for each and every AFL.


Common code in every AFL:
Every AFL will have some common repeated code like -
* Displaying title, OHLC prices, ticket name
* BUY and SELL arrows
* OHLC bars/lines/candlestics, etc
* Explore codes for filtering in Automatic Analysis.

Since the above are common to every AFL, their corresponding code can be reused in every AFL. This point is the focus of this post. Below you can find the skeleton AFL code, which contains all the necessary code for plotting the default "common requirements".


Steps to use this skeleton code:
When you want to write an AFL, just follow this simple procedure:
1. Copy the skeleton code.
2. Write your BUY and SELL signal conditions, and their associates(if needed).
ie change the red and bolded letters in the skeleton.


Thats it! Your AFL is ready. So you can write AFL's without depending on others.


Code:
_SECTION_BEGIN("[COLOR="Red"][B]YOUR_SYSTEM_NAME_COMES_HERE[/B][/COLOR]");
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 )) ));

Buy = [B][COLOR="Red"]YOUR_BUY_CONDITIONS_COMES_HERE[/COLOR][/B];
Sell = [COLOR="Red"][B]YOUR_SELL_CONDITIONS_COMES_HERE[/B][/COLOR];

MyColor = IIf(Buy, colorBrightGreen, colorRed);
// The above line is very generalized. You can use your own conditions to
// get exact colour combinatins.
// Example :
// MYcolor = IIf( EMA(C,ShortPeriod) > EMA(C,LongPeriod), colorBrightGreen, 
// IIf(EMA(C,LongPeriod) > EMA(C,ShortPeriod) AND C < Peak(C,5,1), colorRed, 
// colorBlue));

PlotOHLC( Open,  High,  Low,  Close, "", Mycolor, styleBar   ); 

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

Filter=Buy OR Sell;

SetOption("NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );
AddTextColumn( FullName(), "Full name", 77 , colorDefault, IIf( Buy, colorGreen, colorRed ) );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorDefault, bkcolor =IIf (Buy,colorGreen, colorRed ));
_SECTION_END();

For a sample AFL with the above skeleton used, please refer this link:
http://www.traderji.com/82702-post90.html


Please let me know, if I'm wrong anywhere.
Praveen.


P.S: This is given to aid the AFL writers, especially beginners, for writing simpel to medium complex AFLs. More code has to be written if the system being developed is complex.
 
Last edited:

rkgoyal_98

Well-Known Member
#93
Dear Seniors,

I need help to write an AFL to find out the following
1. List out all the scrips selected for analysis
2. Moving Average
EMA 7 Above EMA 100
1. EMA 7 above EMA 35 UP
2. EMA 7 Below EMA 35 UP-B35
EMA 7 Below EMA 100
3. EMA 7 Below EMA 35 - DOWN
4. EMA 7 Above EMA 35 Down A35
MACD Above Zero line and MACD Above Signal UP, MACD above Zero line but Below Signal Line UP-Watch, below Zero line and MACD below Signal Down, MACD below Zero line but above Signal Line Down-Watch,
4. ADX
Slop UP/Down/Flat
Value of ADX ( showing Value if DI is more than +DI & + Value if +DI is more than DI
5. Value of RSI
Output columns should have Scrip Name (Ticker), Moving average Position, MACD, ADX slope, ADX Value, RSI
I will like to use Default Amibroker values for MACD, RSI, ADX, +DI, -DI
Kindly guide me to wrte above fornulla
Thanks
Rajeev
 
#94
Dear Seniors,

I need help to write an AFL to find out the following
....
....
Kindly guide me to wrte above fornulla
....
Hi,

1. Read some sample AFLs, and try to look for how BUY and SELL conditions are written.
2. Refer Amibroker User Guide to look out for usage of different functions for your requirement, like MA, MACD, etc
3. You can use the AFL skeleton code posted before.

Praveen.
 

rkgoyal_98

Well-Known Member
#95
Dear Praveen,

I have tried to look at the Formulla and also tried a few AFLs from different sources. As i understand there may be 2 kinds of AFLs.
1. In which we may want to plot the charts with our desired results i.e. we may want to put indications on the chart for Buy/Sell or another Indication. The Best example i saw here was the default formulla that plots the default chart it self
On further examination of this formulla i found following Parts
1. For displaying title and tool tip.
2. For plotting Moving Averages , BBANDS, and Volume
3. For displaying the price interpretation

Now i want a confirmation from you regarding my observations of the above
If this is correct then my Next query is that since in explorations/scans we need not to plot anything but only want some output from the data can we go about without such parts of the secion

i was also trying one simple test scan to find out just cross of one EMA over the other and found that it is fine
Small = 7;
Medium = 35;
Large = 100;
Buy = Cross(EMA(C,Small),EMA(C,Large));
Sell = Cross(EMA(C,Medium),EMA(C,Small)) AND EMA(C,Medium) > EMA (C,Large);
Short = Cross(EMA(C,Large),EMA(C,Small));
Cover = Cross(EMA(C,Small),EMA(C,Medium)) AND EMA(C,Large) > EMA (C,Small);
This was giving me Results in the scan window however the result are not perfact as there may come up a short condition before sell condition exist (may be because Medium MA was higher than large MA and the stock turns back southwards). In this case Shorting indication has to be used to exit the position (Sell). after sometime stock may just make small up/down moves and there may be again a penetration southwards.
all the indications are being given ok
but i want the formulla to test that if there was a buy condtion satisfied and if there is shorting condition before Sell Condition then it should be acutually a sell conotion and not a shorting condition

I also need further help in generating output as i mentioned in my previous post but since no proper guidelines exist even in help file, i have asked u about it

I have some knowledge of Visual Basic and ASP programming

Thanks

Rajeev
 
#96
I have tried to look at the Formulla and also tried a few AFLs from different sources.
Glad to hear that you are trying to learn AFLs, and trying your best to write your own AFLs.

...
since in explorations/scans we need not to plot anything but only want some output from the data can we go about without such parts of the secion
Yes you are correct. For scan/explore you dont need any other details, except for defining a variable called "Filter". The filter variable controls and filters the the results according to your requirement.

If you had defined BUY/SELL signals, you can view them with arrows in the chart, if you click the results fetched by Explore. That will be more visually appealing and very simpler to understand the results. Hope you got my point here.

I also need further help in generating output as i mentioned in my previous post but since no proper guidelines exist even in help file, i have asked u about it
What kind of help you need in this case? We can give the required AFL in a matter of time. But our intention is to make you learn AFL, so that you can benefit immensely from it. You needn't depend upon others. Let me know the precise help which you need in this matter.

I have some knowledge of Visual Basic and ASP programming
I don't have any idea about these languages, and I don't know whether it will be helpful in learning AFL. But since they are programming languages, I assume that it will make you understand and learn AFL faster.

Praveen.
 
Dear Praveen,
A full range up day means a day which opens at its low and closes at its high. Is it possible to write and afl which tells that the next day will be a full range up day.

Regards:)
 

Similar threads