Count number of stocks

I found this formula to count the number of stocks above the sp500 ma but it gives me error on Fcount.

I looked around but there doesn’t seem to be a function to count the number of stocks:

Fcount(“close(0) > SMA(200,0)”)/500) * 100

Adding the missing opening parenthesis and this works;

(Fcount(“close(0) > SMA(200,0)”)/500) * 100

or

(Fcount(“close(0) > SMA(200,0)”)/FCount(“True”)) * 100

That yields the number of stocks above their own 200D MA.

Sorry it was a typo on my behalf when I copied on the post, the formula does have the correct brackets.

This is the error I get:

Error in Hedging Buy Rule ‘Entry1’: Error near ‘Fcount’: Invalid command ‘Fcount’

Where are you using this ? Within the series tools you need to use UnivCnt. Rule/function references always display what’s available for the particular context you are in like: buy rule, sell rule, screen rule, etc.

I think FCount works in the buy rules but not for the hedging rules. I do use FCount in the buy rules for one of my active ports and it does seem to work. In the hedging rules you will probably have to use the new series creation tool with UnivCnt().

Edt: Marco beat me to it

I’ve used it in formula and then called the variable in hedge.

The idea was to have a hedge rule that says, stay out when this percentage of stocks are below the 100ma of the sp500 and vice versa.

So fcount works in buy sell rules only and not in hedge rules?