| Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
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
|
|
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.
|
|
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.
....
....
.
|
|
|
Guest-1 |