StockFetcher Forums · General Discussion · "and" in count function<< >>Post Follow-up
jfue611-wlzz973kg-wqu558v
20 posts
msg #83330
Ignore jfue611-wlzz973kg-wqu558v
11/21/2009 8:02:14 PM

Hello,
Has anyone been able to write a count function that counts if 2 criteria are filled?

I have searched and cannot find any references as to how to do this.
I know that it was a limitation but I would like to know if anyone can get around it.

Any suggestions or examples would be much appreciated.

Thanks
Mike

chetron
2,817 posts
msg #83331
Ignore chetron
modified
11/21/2009 8:22:49 PM

no and function here.

do 2 and then multiply, countless examples in forum

hth


Kevin_in_GA
4,599 posts
msg #83332
Ignore Kevin_in_GA
11/21/2009 10:06:26 PM

There are a lot of different ways to do this. Lots of examples here, you just need to dig a bit.

This is how I do it:

You are looking for two conditions to be met in order to signal a trade. Let's say it is the price closing above a certain limit, AND an indicator also reaching or crossing a threshold (either the same day or in the recent past). Here is where you use the count function in setting a new variable (so you also use the set function as well to achieve this).

set{criterion1, count(RSI(2) crossed 20 from below,1)}

this line says "if the RSI(2) crossed above my threshold of 20, then this variable will have a value of 1. Otherwise it has a value of zero."

set{criterion2, count(close is above close 1 day ago,1)}

this line says "if my second criterion also occurs today, it is assigned a value of 1 as well. Otherwise, it is assigned a value of 0."

set{aggregate, criterion1 + criterion2}
set{trigger, count(aggregate >1.9,1)}


this last line says "if both of these criteria are met today, then the variable called aggregate will have a value of 2. Otherwise it will have a value of 1 or 0.

Only if it has a value of 2 will the variable called trigger have a value of 1. Otherwise it will have a value of 0."

THAT'S HOW YOU INCORPORATE AN "AND" FUNCTION INTO SF CODE.

I'll leave it up to you to figure out OR and NOR - its pretty obvious.

Chet likes to use multiplication instead of addition, but it's clear that the key is to use user-defined variables and the count function.

Kevin



chetron
2,817 posts
msg #83333
Ignore chetron
11/21/2009 10:30:09 PM

FYI, KEV, USING MULTIPLICATION IS CONSIDERED AN AND FUNCTION, ADDITION ON THE OTHER HAND IS CONSIDERED AN OR FUNCTION.


HTH

Kevin_in_GA
4,599 posts
msg #83337
Ignore Kevin_in_GA
11/22/2009 10:56:25 AM

I see that if one uses multiplication and one of the conditions is 0, the result is zero. Very clean. But requiring the sum to exceed a threshold does acomplish the same goal.

mktmole
325 posts
msg #83367
Ignore mktmole
11/23/2009 10:00:34 AM

Mike.. you might find this golden-oldie from 2003 helpful,

http://forums.stockfetcher.com/sfforums/?q=view&tid=28017&start=0&isiframe=

mm

sync
15 posts
msg #83370
Ignore sync
11/23/2009 11:23:25 AM

I created a filter that has multiple conditions for both long and short. By adding I was unable to come up with a way to determine if I had either a long or a short signal. But now I can see how to make it work by multiplying to get the long and short signals.

jfue611-wlzz973kg-wqu558v
20 posts
msg #83462
Ignore jfue611-wlzz973kg-wqu558v
11/25/2009 10:40:40 AM

Thank you very much. Very helpful and answers the question.
Mike

chetron
2,817 posts
msg #83463
Ignore chetron
11/25/2009 10:44:48 AM

YOU ARE VERY WELCOME, sync

StockFetcher Forums · General Discussion · "and" in count function<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2022 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.