StockFetcher Forums · General Discussion · if condition in SF?<< >>Post Follow-up
njjstocks
8 posts
msg #161210
Ignore njjstocks
7/11/2024 11:28:38 AM

Any pointers on how to implement an if function in SF?

Here's the psudo logic :
set{bear_fvg_sum, sum(if(bearish_fvg > 0, high, 0), 30)}

Essentially, if this condition bearish_fvg > 0 is met I want to return High else 0 and I want the sum of it over 30 days so that i can average it.

Thanks a lot.

nibor100
1,045 posts
msg #161232
Ignore nibor100
7/13/2024 1:12:55 PM

This old Cegis post might help. or you search for old TRO posts on logic. Ed S.

Fetcher[
/*I have noticed that many of you write two filters of the same condition. For example, one filter is written for stocks that crosses above its 20-day moving average and another filter is written for stocks that crosses below its 20-day moving average. Why not just write one filter that would allow both conditions to be met but also informs you which is which. Here's how you write it.

code

set{condition 1, count(indicator 1, indicator 2,1) * 1}
set{condition 2, count(indicator 1, indicator 2,1) * -1}
set{both, condition 1 + condition 2}
set{result, 1 - count(both equals 0,1)}
result above 0
add column both{result}

Hence, taking the above example of 20-day moving average crossover:*/


set{up, count(price crossed above MA(20),1) * 1}
set{down, count(price crossed below MA(20),1) * -1}
set{both, up + down}
set{Xover, 1 - count(both equals 0,1)}
Xover above 0
add column both{Xover}
]



xarlor
587 posts
msg #161233
Ignore xarlor
7/13/2024 6:20:02 PM

https://www.stockfetcher.com/forums/General-Discussion/A-COMPLETE-LOGIC-SYSTEM-ANOTHER-GIFT-FROM-AVERY/28017/-1/28017

njjstocks
8 posts
msg #161241
Ignore njjstocks
7/16/2024 4:39:24 AM

Thanks both for the pointers. Here's the implementation for the psudo logic above

set {if, count(bear_fvg_check > 0 ,1)}
set {then, bear_fvg_check * high}
set {bear_fvg_sum, sum(then, 30)}

nibor100
1,045 posts
msg #161243
Ignore nibor100
7/16/2024 11:07:28 AM

You may want your 2nd line to use the "if" instead of " bear_fvg_check".
Ed S.

njjstocks
8 posts
msg #161245
Ignore njjstocks
7/16/2024 6:15:38 PM

My bad. Thank you @nibor100

StockFetcher Forums · General Discussion · if condition in SF?<< >>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.