The trend is your friend

justAnotherTrader

Member
VIP
VIP Enthusiast
So a lot of us know the old adage the trend is your friend. Furthermore a lot of us would know an uptrend if we seen one, but very few of us know how to scan for an uptrending stock. For us that go long on stocks, we use several different techniques to help us decide whether or not to take a position. Some of these techniques include candlestick patterns, RSI, MACD, Stochastics, and various momentum indicators. One many of us VIPs have been playing around with great levels of success is the Buy the Dip indicator made by @BenTen

None of these techniques are infallible but they tend to work with the highest probability on uptrending stocks. I am going to share a scan with you guranteed to get you some juicy uptrending charts. You guys can do your own research on how to set this up, im just going to leave the framework here. This site has many tutorials and helps thanks to the site creator. Enjoy =)

Fyi, this is not my original idea, but formulated in large part from this site: https://www.marcellagerwerf.com/mark-minervini-trend-template-thinkorswim-scan/
  • Restrict the scan to the S&P 500
  • Average volume > 1 million
Under custom study copy and paste the following:

Code:
close(“period” = AggregationPeriod.DAY) is greater than SimpleMovingAvg(“length” = 150).”SMA”
and
close(“period” = AggregationPeriod.DAY) is greater than SimpleMovingAvg(“length” = 200).”SMA”

and
SimpleMovingAvg(“length” = 150).”SMA” is greater than SimpleMovingAvg(“length” = 200).”SMA”

and
SimpleMovingAvg(“length” = 50).”SMA” is greater than SimpleMovingAvg(“length” = 150).”SMA”
and
SimpleMovingAvg(“length” = 50).”SMA” is greater than SimpleMovingAvg(“length” = 200).”SMA”

and

close(“period” = AggregationPeriod.DAY) is greater than SimpleMovingAvg(“length” = 50).”SMA”

and

close(“period” = AggregationPeriod.DAY) /
Lowest(“data” = CLOSE, “length” = 250)
is greater than 1.3

and

close(“period” = AggregationPeriod.DAY) /
Highest(“data” = close, “length” = 250) > 0.75
 
Last edited by a moderator:

Art

Member
@justAnotherTrader

Here is one with entry and exits. I set up mine with RSavg crossses above 0. Works really well.

Code:
##########################################################################################################################
## 1. The current stock price is above both the 150-day (30-week) and the 200-day (40-week) moving average price lines.
## 2. The 150-day moving average is above the 200-day moving average.
## 3. The 200-day moving average line is trending up for at least 1 month (preferably 4?5 months minimum in most cases).
## 4. The 50-day (10-week) moving average is above both the 150-day and 200-day moving averages.
## 5. The current stock price is trading above the 50-day moving average.
## 6. The current stock price is at least 30 percent above its 52-week low. (Many of the best selections will be 100 percent, 300 percent,
## or greater above their 52-week low before they emerge from a solid consolidation period and mount a large scale advance.)
## 7. The current stock price is within at least 25 percent of its 52-week high (the closer to a new high the better).
## 8. The relative strength ranking (as reported in Investor?s Business Daily) is no less than 70, and preferably in the 80s or 90s,
## which will generally be the case with the better selections
## NOTE: Point 8, I have not implemented, because TOS doesn'thave IDB rating.
##
## Reference to conditions above
## 3) (Average(close, length) > Average(close, length)[LookBack])
## 2) and SimpleMovingAvg("length" = 150)."SMA" is greater than SimpleMovingAvg("length" = 200)."SMA"
## 4) and SimpleMovingAvg("length" = 50)."SMA" is greater than SimpleMovingAvg("length" = 150)."SMA"
## 4) and SimpleMovingAvg("length" = 50)."SMA" is greater than SimpleMovingAvg("length" = 200)."SMA"
## 1) and close is greater than SimpleMovingAvg("length" = 200)."SMA"
## 1) and close is greater than SimpleMovingAvg("length" = 150)."SMA"
## 5) and close is greater than SimpleMovingAvg("length" = 50)."SMA"
## 6) and price > x
## 7) and price > y
##########################################################################################################################
declare lower;
## Code Start

input range = 252; #Number of Trading days
input price = close; #Current closing price
input length = 200; #hint length: The length of the moving average
input LookBack = 60; #hint LookBack: The agg-bars back moving average being compared to

def lo = lowest(low,range);
def hi = highest(high,range);

#The current stock price is at least 30 percent above its 52-week low.
def x = 1.3 * lo; #30% above its 52-week low
#def x = 2.0 * lo; #100% above its 52-week low

#The current stock price is within at least 25 percent of its 52-week high
def y = 0.75 * hi; #25% of its 52-week high
#def y = 0.80 * hi; #20% of its 52-week high
#def y = 0.90 * hi; #10% of its 52-week high

# The below reads as SimpleMovingAvg("length" = 200) is greater than SimpleMovingAvg("length" = 200) from 60 agg-bars ago.
#(Average(close, length) > Average(close, length)[LookBack])

input cc=63;
#def C63= simpleMovingAvg(Close, cc);
#def C126= simpleMovingAvg(Close, cc*2);
#def C189= simpleMovingAvg(Close, cc*3);
#def C252= simpleMovingAvg(Close, cc*4);

def C63= inertia(price, cc);
def C126= inertia(price, cc*2);
def C189= inertia(price, cc*3);
def C252= inertia(price, cc*4);

def S1 = (Close - c63)/c63*40;
def S2 = (Close - c126)/c126*20;
def S3 = (Close - c189)/c189*20;
def S4 = (Close - c252)/c252*20;

plot RS= s1+s2+s3+s4;
input RS_thr = 10;

#plot scan = if ((Average(close, length) > Average(close, length)[LookBack])
#and SimpleMovingAvg("length" = 150)."SMA" is greater than SimpleMovingAvg("length" = 200)."SMA"
#and SimpleMovingAvg("length" = 50)."SMA" is greater than SimpleMovingAvg("length" = 150)."SMA"
#and SimpleMovingAvg("length" = 50)."SMA" is greater than SimpleMovingAvg("length" = 200)."SMA"
#and close is greater than SimpleMovingAvg("length" = 200)."SMA"
#and close is greater than SimpleMovingAvg("length" = 150)."SMA"
#and close is greater than SimpleMovingAvg("length" = 50)."SMA"
#and price >= x
#and price >= y
#and RS>=RS_thr
#,1,0);

input RSlength = 20;
plot RSavg = simpleMovingAvg(RS,RSlength);

plot enter = if RS - RSavg[1] >0 then 10 else -10;
plot zeroline = 0;

an on top of that I use these two along with the above scanner

Code:
#Must be over 40
#WLC_RS6mo
#RS_Rank - 8/28/2019 Developed by GHorschman  ([email protected])
#######################################################################
# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 7;

#def RS = if IsNan(relativeStrength("SPY")) then 0 else relativeStrength("SPX") ;
def RS = RelativeStrength ("SPY");
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
def RSRank = Round(100 * (RS - RSLow) / (RSHigh - RSLow), 0);




plot line = Average(RSRank);

#plot baseline = 40;

AddLabel(yes, "40Week " + Average(RSRank), if Average(RSRank)> Average(RSRank) from 1 bars ago then Color.GREEN else Color.RED);

#End Code

Code:
#Must be over 20
#WLC_RS6mo
#RS_Rank - 8/28/2019 Developed by GHorschman  ([email protected])
#######################################################################
# This is a custom quote to compute the Relative Strength percentile.
# It is calculated the same way that IV_Percentile is computed.  Just
# change the length to specify the time frame of interest.  The
# background color is tied to the following ranges:
#
#    RS_Rank > 80       -- Green
#    80 <= RS_Rank < 60 -- Light Green
#    60 <= RS_Rank < 40 -- Gray
#    40 <= RS_Rank < 20 -- Light Red
#    RS_Rank <= 20      -- Dark Red
######################################################################

# Set length to period of interest.

#  1 Wk – 5 trading days
#  1 Mos – 21 Days
#  3 Mos – 63 Days
#  6 Mos – 126 Days
#  12 Mos – 252 Days

def length = 21;

#def RS = if IsNan(relativeStrength("SPY")) then 0 else relativeStrength("SPX") ;
def RS = RelativeStrength ("SPY");
def RSLow = Lowest(RS, length);
def RSHigh = Highest(RS, length);
def RSRank = Round(100 * (RS - RSLow) / (RSHigh - RSLow), 0);




plot line = Average(RSRank);

#plot baseline = 20;

AddLabel(yes, "20Month " + Average(RSRank), if Average(RSRank)> Average(RSRank) from 1 bars ago then Color.GREEN else Color.RED);


#End Code
 
Last edited by a moderator:

rad14733

Moderator
Staff member
VIP
has an error saying "exactly one plot expected." Not sure how if I am importing a scan correctly. If someone can advise?
This is a problem that could be eliminated if each script was posted between code tags so it is displayed as individual pieces of code rather than text... 💡
 

Izet99

New member
VIP
Hi @Art
I'm using above scanner and I'm finding it very useful, I'm reviewing your codes and wonder how do I use it...specially last two codes for upper/chart view. Not sure if I'm doing I'm something wrong but I'm not sure what I'm expected to see on charts with these codes? Do I need to use with specific time frame?
Any screenshot of the view for these codes or could you elaborate a bit more how do I use it for entry and exit.
Thank you
Izet
 

Art

Member
Hi @Izet99 , I use 4hr and daily charts. The last two codes I use in my scanner as conditions that must be met. I set one of them above 40 and the other one above 20 as stated in the code on a 4hr chart.
 

Fupaflap

New member
VIP
@Art So I saved your first code as a study and then built the scanner to look for the RSavg crossses above 0 which does find a good number of symbols, but how exactly do I add in the next two codes you put for the conditions? If I try to paste them into a thinkscript for the scan it kicks back an error, so I made a study for them and am now trying to add them as a condition same as the other but do I set it as crosses above? crosses below? Im not sure how to add them in there
 

vro3

Member
also curious. when add them, to say, CCL : the plot is all over the place: is there something im missing about what to set at the criteria for the study in the scan? Thanks!

L33iX0g.png
 

Similar threads

Top