StockFetcher Forums · General Discussion · Counting moving average crosses<< >>Post Follow-up
spauken
47 posts
msg #127154
Ignore spauken
2/4/2016 8:42:23 PM

Can anyone help me with an indicator? I want to count how many times a fast MA crossed (above and below) a slow moving average for the last two years and display the cumulative count at the bottom of the chart.

Mactheriverrat
3,153 posts
msg #127157
Ignore Mactheriverrat
2/5/2016 1:30:13 AM

Here's some code on how many days a EMA(5) is above EMA(5). You can change this to MA(5) above MA(5) or EMA(10) above EMA(30). If you get the picture.



BxB is number of consecutive days ema(5) above (+)/below(-) previous EMA(5) and set{BBb,days( ema(5) is above EMA(5)1 day ago,100)}
set{BBa,days( ema(5) is below EMA(5) 1 day ago,100)} set{BxB, BBa - BBb} and add column BxB {B_x_B}

do not draw BxB

mahkoh
1,065 posts
msg #127233
Ignore mahkoh
2/8/2016 4:05:55 PM

Fetcher[
set{x, count(ma(20) crossed above ma(200),200)}
set{y, count(ma(20) crossed below ma(200),200)}
set{z, x + y}
add column z
s&p 500
draw ma(20)
draw ma(200)
chartlength 52 weeks
]



This should do it. However,when examining the charts it doesn't always seem correct. This could be related to accounting for dividends.



spauken
47 posts
msg #127265
Ignore spauken
2/10/2016 1:28:24 PM

Thanks mahkoh. This does work, although the count is limited to the only the last 100 days per the SF user guide. Not sure why, but it is.

Kevin_in_GA
4,599 posts
msg #127266
Ignore Kevin_in_GA
2/10/2016 1:42:15 PM

I believe that SF has upgraded many of their functions (including count()) to go back up to 252 days.

StockFetcher Forums · General Discussion · Counting moving average crosses<< >>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.