MarketCap Filter for Small Caps

Hi everyone.

Just a beginner question this is driving me nuts.

I'm trying to create a filter for MarkeCap exploration for stocks $300 Million to $2 Billion. What am I doing wrong here?

Any help appreciated.

MarketCap = ("mktcap");
MarketCap = NorgateFundamentals("mktcap");
Filter = MarketCap > 300 AND < 2000;
AddColumn(MarketCap,"MarketCap",1.2);

Screen

stock_price = Close;
market_cap = stock_price * GetFnData("SharesOut");

https://www.amibroker.com/guide/h_fundamental.html

https://www.amibroker.com/guide/afl/getfndata.html

http://www.amibroker.com/guide/w_information.html

25

I'm real lost here. Problem is I'm trying to add this market cap filter to an existing code. How would I write it?

No sure how to add that..

Thank you for response by the way..
-Frank

Hi Frankie,

This line won't work because it's incorrect syntax. Delete it.

MarketCap = ("mktcap");

See what is available and how to access using GetFNData():
https://www.amibroker.com/guide/afl/getfndata.html

Also, this line is coded wrong:

Filter = MarketCap > 300 AND < 2000;

It should be like this:

Filter = MarketCap > 300 AND MarketCap < 2000;

See this page for how the AFL language works:
https://www.amibroker.com/guide/a_language.html

I hope this helps.

Peter

1 Like

NorgateFundamentals is 3rd party function.

You don't need Norgate to get market cap.
Please read the links I have posted.
You haven't even clicked on them.

Only supported functions and functionalities are AmiBroker ones.
For the rest you have to got to 3rd party forum or support.
This is not Norgate support forum.

Do like this and you do not need 3rd party for such simple things.

stock_price = Close;
market_cap = stock_price * GetFnData("SharesOut");

Filter = market_cap > 300 AND market_cap < 2000;
AddColumn(market_cap,"MarketCap",1.2);

It's ridiculous to use a DLL function for that.

Ah Cool.. Thanks Peter,

Ok so like this?

MarketCap = NorgateFundamentals("mktcap");
Filter = MarketCap > 300 AND MarketCap < 2000;
AddColumn(MarketCap,"MarketCap",1.2);

_SECTION_END();

type or paste code here

OK thank you.

Well explained.. I'll try that now..

Thanks for your help.

Ok I'm not getting any AFL errors anymore however the results don't seem to be working on my backtest.. I am still getting stocks show up in backtest with cap size much larger than $2billion.

The location of the cap site formula in the code shouldn't matter right? I have it towards the top anyway.

I used this as you suggested

stock_price = Close;
market_cap = stock_price * GetFnData("SharesOut");

Filter = market_cap > 300 AND market_cap < 2000;
AddColumn(market_cap,"MarketCap",1.2);

How to use AND / OR operators and combining comparisons is explained here with example

https://www.amibroker.com/guide/a_language.html

If a formula requires multiple conditions, you can combine the conditions with AND and OR operators. For example, maybe you'd like to plot a +1 when the MACD is greater than zero and the RSI is greater than 70:

Condition = MACD() > 0 AND RSI(14) > 70; 

You can add as many conditions within a formula as you like.

So writing AND > (so combining logical operator with other operators) clearly makes not any sense.
AND can not be greater than, smaller than, equal to something else. AND is an operator to connect two boolean conditions (which return true/false).

So only lines similar to below one or the ones of the manual make sense

x = RSI();

condition = x > 30 AND x < 70;

Or

x = RSI();

condition = x < 30 OR x > 70;

or...

x = Close;
y = MA(x, 20);
condition = x > 5 AND x >= y;

etc.

In upper examples on left and right side of comparison operators such as < > == etc. there have to be numeric variables (such as x array variable in upper example) or values/scalars. Then you can connect multiple comparisions with logical operator such as AND OR but do not combine operators with operators ( AND < 70 -> incorrect).


Please take the time to read the given links of 2nd post and how to fill fundamental data to AB database.

Check return value of Shares Outstanding.

// output in interpretation window if line being applied to chart
printf("shares oustanding: %g", GetFNdata("SharesOut"));

Or use explorer

stock_price = Close;
shares_outstanding = GetFnData("SharesOut");
market_cap = stock_price * shares_outstanding;

//Filter = market_cap > 300 AND market_cap < 2000;

// disable upper filter for testing Price and SharesOut:
Filter = 1;

AddColumn(market_cap,"MarketCap",1.2);
AddColumn(stock_price,"stock_price",1.2);
AddColumn(shares_outstanding,"shares_outstanding",1.2);

You apparently have no shares outstanding data yet.

Again read the fundamentals pages of AmiBroker.

1 Like

HI again,

I've been trying everything and studying for the last few hours. I've gone through your links, It seems I need to use the 'Country' with this because I am in Australia and trading ASX.

However last code I tried is still not working. :frowning:

Trying to run it as an exploration

Any suggestions?

Last one was this

stock_price = Close;
shares_outstanding = GetFnData("SharesOut");
market_cap = stock_price * shares_outstanding;
country = GetFnData("country");
Filter = market_cap > 300 AND market_cap < 2000;

Filter = 1;

AddColumn(country,"country",1.2);
AddColumn(market_cap,"MarketCap",1.2);
AddColumn(stock_price,"stock_price",1.2);
AddColumn(shares_outstanding,"shares_outstanding",1.2);

No.

Have you read any of the three links provided in post #2?

AFL Function Reference - GETFNDATA

GetFnData

  • get fundamental data Information / Categories
    (AFL 2.90)
SYNTAX GetFnData( ''field'' )
RETURNS NUMBER or STRING
FUNCTION GetFnData allows accessing fundamental data from Information window (Window->Symbol Information) "field" parameter can be one of the following:

It just calls the fundamental data of Information window (per symbol).
So the data can be any country's data.

How to fill in data there is described in first link of post #2.
Simply download fundamental data via AmiQuote.

No one knows your information window content and no one knows your result list output of explorer.
No one knows what you have done so far.

No.


Since I do not want to waste more time on this.
Go on using that NG function of your first post.
If you have any problems with that function then call their support.
They get paid for that.

Your major mistake was incorrect use of operators.

Ok.

I'm sorry to frustrate you I'm not a programmer. I'm Just trying to get this one thing working so I can use an existing AFL file to filter via market cap and then thats all i want to ever program.

I've read all the links you've sent me plus countless other things on the net. Trying to educate myself to try to get this one off task done :frowning:

Just too hard.

I understand you are trying to help but, its all too hard it's like I'm trying to learn a whole foreign language such as Chinese just to read instructions on how to bake a cake :frowning:

Anyway thank you for trying to help its much appreciated again sorry for the frustration.

-Frank

@frankieplus,
Market capitalization is simply the number of outstanding shares multiplied by the share price , i.e.:
sharesOutstanding x C

You can use the links which @fxshrat listed to write some simple code to download the Shares Outstanding data from Yahoo Finance using AmiQuote. It's really easy, however, you need to obtain this data and put it into your AmiBroker database (again, follow the examples in the links).

If Norgate is providing the Market Cap data then just reach out to their support team for assistance to write the necessary code.

Better yet, do both and begin your journey to become a programmer. (It will be worth it.)

P.S. AB can be hard, but it's not too hard. Hang in there.

2 Likes

Yep. Thank you for that explanation of the shares outstanding .

The journey to get this resolved has led me down a path where I feel it would actually be helpful to understand AFI somewhat. That way I can add things to this major code I have here (the one I am trying to add MarketCap to)

I studied the Norgate site and came up with adding PE and PS ratios to my code as well.

So now everything works fine except ONLY as an exploration. This will NOT work when I try it as a backtest :frowning:

I can't understand why won't work as a backtest..

MarketCap = NorgateFundamentals("mktcap");
PE = NorgateFundamentals("peexclxor");
PS = NorgateFundamentals("ttmpr2rev");
MarketCap > 300 AND MarketCap < 4000 PE > 0 AND PE < 10 AND PS > 0 AND PS < 5;

AddColumn(MarketCap,"MarketCap",1.2);
AddColumn(PE, "PE",1.2);
AddColumn(PS, "PS",1.2);

You are making the same mistake!

MarketCap > 300 AND MarketCap < 4000 PE > 0 AND PE < 10 AND PS > 0 AND PS < 5; // Wrong!

Should be:

Filter = MarketCap > 300 AND MarketCap < 4000 AND PE > 0 AND PE < 10 AND PS > 0 AND PS < 5;

In regards to backtesting see Backtesting Guide.

2 Likes

Thanks for that Backtesting Guide. I have gone through it all..

There doesn't seem to be any reason why my code works as required as an exploration but not as a backtest.

As an exploration the results are as per the market cap in the code, however as a backtest the market cap is ignored.

My completed code is like this

#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"
SetFormulaName("Simple Screen");
MarketCap = NorgateFundamentals("mktcap");
PE = NorgateFundamentals("peexclxor");
PS = NorgateFundamentals("ttmpr2rev");
Filter = MarketCap > 300 AND < 4000 PE > 0 AND PE < 10 AND PS > 0 AND PS < 5;

AddColumn(MarketCap,"MarketCap",1.2);
AddColumn(PE, "PE",1.2);
AddColumn(PS, "PS",1.2);

Buy = Cross( Close, MA( Close, 50 )); 
Sell = Cross( MA( Close, 50 ), Close ) ; 

Why are you deleting multiple posts when your edit window is still open???

Once again this line of code is wrong (in more ways than one)!

You are not respecting the help you are receiving...

You need to go through it again!

Also see,

Your Buy variable is missing your Market conditions (Market Cap, PE, PS).

3 Likes

One more thing to read:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.