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 |

question on MA conditional filter (3 lines of code) Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
smpat04
Posted : Saturday, December 11, 2010 11:39:12 AM
Registered User
Joined: 11/7/2010
Posts: 6
Thanks for taking the time to read my post.  For some reason, this code is showing 0 results (I'm checking it against industry watch lists... most have 30-40 stocks and I can visually see several stocks that meet the criteria I'm looking for but are being discounted.)

The goal is to find stocks that have 1. a positive 30 week MA, and 2. are currently trading below their 30 week MA.  My code follow is between, but not including, the "=" sign border:

=============================================================

Dim MAchange As Integer = (price.avg(30) - price.avg(30, 1))
If MAchange > 0 Then pass
If price.Close < price.avg(30) Then pass

==============================================================
for the life of me, this darn code is 3 lines long and has taken 3 days with still no results heh; could really use assistance.  Thanks in advance!

--Patrick
jas0501
Posted : Saturday, December 11, 2010 2:51:01 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
Tou want to and the 2 condition. In general when problems arise try test each condition. For example test

If price.Close < price.avg(30) Then 
   pass
end if

Then just try the other

if (price.avg(30) >  price.avg(30, 1)) then
   pass
end if

The try them both

If price.Close < price.avg(30)  andalso _
 (price.avg(30) >  price.avg(30, 1))  then
   pass
end if



By the way, the MA condition seems a bit arbitrary. It is really just a test to see if the gain today was bigger than the gain 30 days ago, as the MA30 is the average 30 bars and there is an overlap of price.close(1) thru price.close(29).

In other words

if  (price.avg(30) >  price.avg(30, 1)) then

could really just be

if price.close > price.close(30) then

This second approach is more efficient. Note the same can't be said for Xavgs.
jas0501
Posted : Saturday, December 11, 2010 2:55:59 PM
Registered User
Joined: 12/31/2005
Posts: 2,499
QUOTE (jas0501)
....
....
....
I misspoke

By the way, the MA condition seems a bit arbitrary. It is really just a test to see if the gain today was bigger than the gain 30 days ago, 


Should be

By the way, the MA condition really just a test to see if the Price today was greater than the price 30 days ago, 

Not so arbitrary as a gain comparison.

....
....

.
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.