Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Trying to code an upsloping 50 DMA Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
CProvost
Posted : Thursday, January 27, 2011 9:55:56 AM
Registered User
Joined: 8/25/2007
Posts: 22
I'm trying to create a condition in RealCode with a 50 day moving average moving up quickly.

I have tried this - but it's not working too well - some of the stocks that pass actually have a flat 50 DMA. 

If price.avg(50, 0) > price.avg(50,1) then
  Pass
End If

Thanks in advance for your help.
Bruce_L
Posted : Thursday, January 27, 2011 10:05:52 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
If you want to use the "Moving Up: Quickly" that can be created by right-clicking on the Moving Average and selecting Create Condition | Moving Up and adjusting the Rangefinder to Quickly, then you should probably do just that as the algorithm used to define Quickly is not public.

Otherwise, you will have to define quickly. I'm actually relatively confident that 50-Period Simple Moving Average is in fact always moving up when your RealCode Condition returns True as it exactly matches the results of the following Condition in all of my tests.

If Price.Last > Price.Last(50) Then Pass

And does not return True when the following Condition returns True:

If Price.Last = Price.Last(50) Then Pass

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
CProvost
Posted : Thursday, January 27, 2011 7:24:59 PM
Registered User
Joined: 8/25/2007
Posts: 22
Hi Bruce - thanks for the reply. 
I'm not having much luck with right-clicking on the Moving Average and selecting Create Condition | Moving Up and adjusting the Rangefinder to Quickly.  The scan produces a quite a few of stocks where the moving average is not moving up quickly.  Some are actually moving down.  For example, right now if you created one of these conditions and ran it against the Nasdaq 100 Component Stocks, you would see that AKAM's 50 day moving average is actually sloping down a little since the beginning of January.  Some are slightly sloping up and others are moving up quickly.

I tried dragging the 50 DMA into the code window to program against that and it created a variable called MA, but there is no intellesense when I type MA. (dot) - so I'm not sure if we can program against it to find an upsloping MA.

I tried Price.Last > Price.Last(50) and there are plenty of hits, but quite a few are higher than Price.Last(50) but they have retraced so much that the MA looks like an upside down horseshoe (exagerating a little here) and they don't really reflect an upsloping 50 DMA.  If you have any other thoughts, I'd love to hear them.
Bruce_L
Posted : Friday, January 28, 2011 8:17:15 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
What Move Period are you using when creating a Moving Up Quickly Condition? It defaults to one and my initial response was based upon this and your original RealCode which also only compared the current Bar to the previous Bar.

How do you want to unambiguously and objectively define "upsloping" and over what Period? Is it just a positive Linear Regression Slope over the Period? A positive Net Change over the Period? Some combination of the above? Something else entirely?

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
CProvost
Posted : Friday, January 28, 2011 5:52:26 PM
Registered User
Joined: 8/25/2007
Posts: 22
I'm using the default of 1 Move Period.

How I'm trying to define "upsloping"
The best way to answer that is to explain what I'm trying to accomplish.

I'm trying to find stocks that have been in an uptrend and have recently pulled back.  My logic was this;  If the stock has been in a strong uptrend over the last 50 days, then I consider it to be trending higher, so if it pulls back and has a correction, then the pullback "may" be temporary and the stock could continue higher again (in the direction of the trend).   Creating the 50 dma was my initial thought for defining the uptrend.  However, you mentioned a couple of other things...  positive Net Change, positive Linear Regression.  Maybe that's the way I should go?
CProvost
Posted : Friday, January 28, 2011 6:25:26 PM
Registered User
Joined: 8/25/2007
Posts: 22
I just tried something that seems like it should work and it doesn't.  Either I'm doing something wrong, or I have a problem with my Stockfinder. 

Could you please try this to see if it works on your machine?

1. Create a new "default" layout.
2. Add a Linear Regression Trendline to price and accept the 30 day default.
3. Right click and choose "Create Condition"
4. Select "Moving Up" from the drop down list.
5. Leave all properties at their default settings and click OK.

The new condition is added to the chart.
Now right click on the newly added condition and choose "Scan"
On my machine none of the symbols light up (no hits) but right now on my machine DIS is the first stock listed and the LinReg Trendline is clearly in a strong uptrend.  MS is another that's in a strong uptrend. 

Shouldn't this have lit up?  Am I doing something wrong?
Bruce_L
Posted : Monday, January 31, 2011 1:41:55 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
The Linear Regression Trendline only has two points. The starting point and the ending point. It also only Plots for the most recent data and does not have any historical values.

You will normally want to use either a Linear Regression Indicator or a Linear Regression Slope Indicator when making Linear Regression based Conditions.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.