How to write exploration AFL

hmsanil

Active Member
#1
Hello all,

How to write exploration for RSI(14)

Cross 30 from below =BUY
Above 70=OVERBOUGHT
Below 30= OVERSOLD
Cross 70 from above =SELL

Thank you

Sudha
 

KelvinHand

Well-Known Member
#4
Hello kelvin sir,

Can you please help me out

Thanks in Advance
Why don't try out first before asking help?

** Do a concept research, anything wrong never mind
** Check available command in AFL Lib.

give you example :
1. Cross 30 from below =BUY
buy = cross(rsi(), 30);

2. Above 70=OVERBOUGHT
OVERBOUGHT = rsi() >70;

3. Below 30= OVERSOLD
OVERSOLD = rsi() < 30;

4. Cross 70 from above =SELL
SELL = cross(70, rsi());

I am done !!!
 
Last edited:

KelvinHand

Well-Known Member
#5
Next Lesson is how to setup filter.
I got only one way;

**Create a new formula file. Put these in amibroker include folder renamed it as filter.afl
See image


** edit filter.afl

procedure StdDisplay()
{
SetOption("NoDefaultColumns", True );
AddTextColumn( Name(), "Ticker",1, colorDefault,colorDefault, 50);
AddTextColumn( FullName(), "Fullname",1, colorDefault,colorDefault,250);
AddColumn( DateTime(), "Date", formatDateTime, colorDefault,colorDefault, 80 );
SetSortColumns( 4, -5) ;
}

// 2nd function
procedure Exec_Filter()
{
global Buy;


StdDisplay();

AddTextColumn( writeIf( Buy, "Buy", "Sell" ), "Signal", 1.0, colorDefault,colorDefault,50 );
AddColumn(V/1000000, "Vol(M)", 1.3, colorDefault,colorDefault, 70);
AddColumn(C, "Close", 1.3, colorDefault, colorDefault, 60);

}
 
Last edited:

KelvinHand

Well-Known Member
#6
Lesson 3 is run Filter:

- Create New Formula, rename to your like named !Scan_RSI.afl
- Edit !scan_RSI.afl, put below statement top of the page
Include <Filter.afl>

put your concept research below the filter.afl, put your remark using // or /* ...*/

/*
Make mistake never mind
No people will laugh at me
Once i master, i will never depend on anybody.
*/
// 1. Cross 30 from below =BUY
buy1 = cross(rsi(), 30);

// 2. Above 70=OVERBOUGHT
OVERBOUGHT = rsi() >70;

//3. Below 30= OVERSOLD
OVERSOLD = rsi() < 30;

//4. Cross 70 from above =SELL
SELL1 = cross(70, rsi());


//-- Here I do main buy & sell ;

BUY = Buy1 OR OVERSOLD;
SELL= Sell1 OR OVERBOUGHT;


//My filter also in this format, i don't follow other people, so that i keep practice until perfect.
Filter = (BUY OR SELL) AND V>10000 /*Your choice*/ AND C>10; /*YOUR CHOICE*/

// Follow by
Exec_Filter();


>> Run "Verify Syntax" Check for Error.
>> No Error. Save it in a folder named !Exploration. Got Error also saved it.
>> No Error, Run the Analysis


// You try out yourself.
// Later you formalised the code here for inspection using tag php ... /php
 
Last edited:

hmsanil

Active Member
#7
Helllo kelvin sir,

as you told i had tried writing the rules earlier as well. I made a mistake in the sell rule as Sell = Cross(aa, 70); but it should have been Sell = Cross(70, aa);

Now as you told i created a filter in include folder

HTML:
Include <Filter.afl>


aa=RSI(14);

// 1. Cross 30 from below =BUY

Buy = Cross(aa, 30);

// 2. Above 70=OVERBOUGHT
OVERBOUGHT = aa >70;

//3. Below 30= OVERSOLD
OVERSOLD = aa < 30;

//4. Cross 70 from above =SELL
Sell = Cross(70, aa);
But i am getting the error

Error 29. Variable 'Include' used without having been initialized.

Please explain sir


Thank you
 

KelvinHand

Well-Known Member
#8
Here the sample Template

PHP:
#include <Filter.afl>

Opt = ParamList("Options","All|Buy|Sell");
Vx = Param("Min Vol(K)", 50, 1, 9999);
Vx *=1000;

Px = Param("Min Price", 1, 1, 9999);


/**************************************
   Write your conditions here
***************************************/

/*OVERBOUGHT*/ OB = 70;
/*OVERSOLD*/ OS= 30;

//-- Indicators used
iRSI = RSI();

//iMacd = macd();
 

//-- RSI below OS and cross up OS
Buy1 = Cross( iRSI, OS);

//Buy2 = .....
//Buy3 = .....

//-- RSI above OB and cross down OB

Sell1 = Cross( OB, iRSI );
//Sell2 = .....
//Sell3 = .....


Buy = Buy1 /*OR Buy2 OR Buy3 */;
Sell = Sell1 /* OR Sell2 OR Sell3 */;


switch(Opt)
{
  case "Buy":  Sell=False; break;
  case "Sell": Buy=False; break;

}

Filter = (Buy OR Sell)AND V>=Vx AND C>=Px;
Exec_Filter();


// -- Add the neccessary AddColumn/AddTextColumn
After you had created your 1st scan afl. Then every time you want create new exploration for other eg. macd, copy and paste to new formula file.

Keep do this to reuse the same formula.

* * * * T H E ..... E N D * * * *
 

KelvinHand

Well-Known Member
#9
Helllo kelvin sir,

as you told i had tried writing the rules earlier as well. I made a mistake in the sell rule as Sell = Cross(aa, 70); but it should have been Sell = Cross(70, aa);

Now as you told i created a filter in include folder

HTML:
Include <Filter.afl>


aa=RSI(14);

// 1. Cross 30 from below =BUY

Buy = Cross(aa, 30);

// 2. Above 70=OVERBOUGHT
OVERBOUGHT = aa >70;

//3. Below 30= OVERSOLD
OVERSOLD = aa < 30;

//4. Cross 70 from above =SELL
Sell = Cross(70, aa);
But i am getting the error

Error 29. Variable 'Include' used without having been initialized.

Please explain sir


Thank you
It my mistake. see my template in post #8