Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 5/18/2009 Posts: 7
|
Bruce you are awesome I have learned a lot reading here. But I'm lost and need your help.
What I want is incredibly simple to explain but hard for me, a newbie, to code.
I want to Scan for stocks that Closed above the 5 day simple moving average, when that moving average is "pointing up"; and stocks that Closed below the 5 sma, when that moving average is "pointing down".
I am having difficulty figuring out how to write the code to explain that "pointing up" or "pointing down".
I tried to use variants of AVGC5 > AVGC5.2 but it didn't work. It gave me all kinds of results that didn't fit the trend pattern I was looking for.
Also, I am not sure whether to use xUp and xDn or C > AVGC5 AND C < AVGC5. Whether I used >< or xUp/xDn it seems to return all stocks that are > or < AVGC5. That is probably because I haven't found how to limit the date. What I want are stocks that have crossed the 5sma today only, or maybe only within the last couple of days (presumably this date variable can be changed easily), and then only when the 5sma is trending in the same direction (up if the stock is above, or down if the stock is below).
I read this http://forums.worden.com/default.aspx?g=posts&t=39459 and others but it just made me more confused (But I think somethig is there that helped).
Just in case I am not explaining it properly I'll try another way. I want to weed the scan down to only find stocks which closed below the 5dma when the 5dma is trending down, or if the stock closed above the 5dma when the 5dma is trending up. And I want to limit that search to stocks that crossed the 5sma today, yesterday, or within the last 3 days (I haven't decided which date range I want but I hope it is easy to play with that number). I prefer to use closing data, and not intraday data.
Thanks for any help. Love the program! Can't wait to learn more.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Welcome to the forums. A very good foundation for learning how to use TeleChart can be gained by reviewing the following:
If you are new to TeleChart READ THIS FIRST!
The crossup and crossdown parts are fairly straightforward. You can check for just crossing up using the following Personal Criteria Formula:
C > AVGC5 AND C1 <= AVGC5.1
You can check for just crossing down using the following PCF:
C < AVGC5 AND C1 >= AVGC5.1
And you can check for crossing either up or down using the following PCF:
SGN(C - AVGC5) <> SGN(C1 - AVGC5.1)
The SMA5 "pointing up" or "pointing down" is more problematic. Not because it is probably difficult to do given an unambiguous objective definition but because we don't have an unambiguous objective definition. The simplest definition of "pointing up" would probably be that it had a positive Net Change. If this Net Change is over one Period, the formula for Price crossing up through an SMA5 that is "pointing up" would be:
C > AVGC5 AND C1 <= AVGC5.1 AND AVGC5 > AVGC5.1
The formula for Price crossing down through an SMA5 that is "pointing down" would be:
C < AVGC5 AND C1 >= AVGC5.1 AND AVGC5 < AVGC5.1
And the formula for doing either would be:
(C > AVGC5 AND C1 <= AVGC5.1 AND AVGC5 > AVGC5.1) OR (C < AVGC5 AND C1 >= AVGC5.1 AND AVGC5 < AVGC5.1)
If "pointing up" or "pointing down" represents a longer trend, we would both need to define trend and know the period of the trend. How do we determine the direction of the trend? Is it just the Net Change over the trend period? Is it the Linear Regression Slope over the trend period? Both? Something else entirely like needing to have increase 3 out of the last 5 bars or all of the last 4 bars? Without knowing the answers to these types of questions we can't create a formula.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/18/2009 Posts: 7
|
Ok thanks! This is great.
Is there some date function so we can look for the crossover from 1 day ago? 2 days ago? <= 3 days ago?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The formula for Price crossing up through its 5-Period Simple Moving Average uses the Bars Ago parameter:
C > AVGC5 AND C1 <= AVGC5.1
The second portion use C1 as the 1-Bar Ago version of C and AVGC5.1 as the 1-Bar Ago version of AVGC5. If we add 1 to the Days Ago paremeters all around we would get a crossover from 1-Bar Ago:
C1 > AVGC5.1 AND C2 <= AVGC5.2
The 2-Bars Ago version would be:
C2 > AVGC5.2 AND C3 <= AVGC5.3
You may wish to review the following:
PCF Formula Descriptions
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/18/2009 Posts: 7
|
Oh yes, I knew that. doh!
Thank you again for your answer, and for your patience.
I really like this software.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You're welcome.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |