Scan for uptrend

@majidg What is your interpretation of upTrend...??? A very common method would be:

Ruby:
close > close[1]

# OR #

close > close[1] and close[1] > close[2]

# OR #

ExpAverage(close, 9) > ExpAverage(close, 9)[1]

There are any number of ways to determine trend and those a just a few...
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@majidg What is your interpretation of upTrend...??? A very common method would be:

Ruby:
close > close[1]

# OR #

close > close[1] and close[1] > close[2]

# OR #

ExpAverage(close, 9) > ExpAverage(close, 9)[1]

There are any number of ways to determine trend and those a just a few...
Thanks, in uptrend and downtrend I want to find the consolidation area, is it possible?
 
Hey @majidg, I have found the Trend Painter Indicator very useful (screenshot below). You can search and add it to your charts. Below is the code I use to scan uptrend stocks. The code will give you a "Buy", "Strong Buy", and "Neutral" state of the stock. Add the code as a filter study for scans. Good luck! @cabe1332

# Trend Painter Indicator With Buy & Sell Signals
# Credit to then usethinkscript.com team for this script and share. It's an awesome indicator.
#
# Candle definitions/legends
# DARK_GREEN = Buy
# GREEN = Strong Buy
# DARK_RED = Sell
# RED = Strong Sell
# BLUE = Neutral or Otherwise

#Think of the BLUE as amber color at a traffic light signal, it is warning you that something is about to change.
#By changing the color scheme to a two COLOR green/red in my opinion would not give you the underlying sentiment of the momentum.

#start code
input ThermoLookBackBars = 50;
input PlotType = {default AdaptiveMovingAverages, Standard};

def HighLowScore = 1000 * ((high - high[1]) / (high[1]) +
(low - low[1]) / low[1]);

#ATR TrailingStop Code
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
loss = ATRFactor * ATRMod;
case unmodified:
loss = ATRFactor * Average(TrueRange(high, close, low), ATRPeriod);
}

rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
}
else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
}
else {
state = state.long;
trail = close - loss;
}
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def TrailingStop = trail;
#TrailingStop.Hide();
#End ATR Trailing Stop Code

def A = Highest(high[1], ThermoLookBackBars);
def B = Lowest(low[1], ThermoLookBackBars);

def FiftyTwoWeekHigh = A;

def FiftyTwoWeekLow = B;

def FiftyTwoWeekScore = 10 * (((high
- FiftyTwoWeekHigh) / FiftyTwoWeekHigh) +
((low - FiftyTwoWeekLow) / FiftyTwoWeekLow));

def ThermoScore = ExpAverage(HighLowScore + FiftyTwoWeekScore, ThermoLookBackBars);

input FastLengthShort = 5;
input SlowLengthShort = 15;
input EffRatioShort = 10;
#input FastLengthLong = 10;
#input SlowLengthLong = 25;
input FastLengthLong = 9;
input SlowLengthLong = 26;
input EffRatioLong = 5;

def AMA = MovAvgAdaptive(ThermoScore, FastLengthShort, SlowLengthShort, EffRatioShort);
def AMA2 = MovAvgAdaptive(ThermoScore, FastLengthLong, SlowLengthLong, EffRatioLong);

def Line1;
#Line1.Hide();
def Line2;
#Line2.Hide();

switch (PlotType) {
case AdaptiveMovingAverages:
Line1 = AMA;
Line2 = AMA2;
case Standard:
Line1 = ThermoScore;
Line2 = ThermoScore;
}

def InvisibleLine = close * 0;
#plot Line3 = InvisibleLine;
#Line3.Hide();

def Buy = Line1 > 0 and Line2 < 0 and state == state.long;
def StrongBuy = Line1 > 0 and Line2 >= 0 and state == state.long;
def Sell = Line1 < 0 and Line2 > 0 and state == state.short;
def StrongSell = Line1 < 0 and Line2 <= 0 and state == state.short;
def neutral = if !buy and !strongBuy and !sell and !strongSell then 1 else 0;

#def GU = BuySignal;
#GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#GU.SetDefaultColor(GetColor(8));
#GU.SetLineWeight(2);

#def GX = SellSignal;
#GX.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#GX.SetDefaultColor(GetColor(8));
#GX.SetLineWeight(2);

plot scan = buy or strongbuy or neutral;
#end code
 
Last edited by a moderator:
Hey @majidg, I have found the Trend Painter Indicator very useful (screenshot below). You can search and add it to your charts. Below is the code I use to scan uptrend stocks. The code will give you a "Buy", "Strong Buy", and "Neutral" state of the stock. Add the code as a filter study for scans. Good luck! @cabe1332

# Trend Painter Indicator With Buy & Sell Signals
# Credit to then usethinkscript.com team for this script and share. It's an awesome indicator.
#
# Candle definitions/legends
# DARK_GREEN = Buy
# GREEN = Strong Buy
# DARK_RED = Sell
# RED = Strong Sell
# BLUE = Neutral or Otherwise

#Think of the BLUE as amber color at a traffic light signal, it is warning you that something is about to change.
#By changing the color scheme to a two COLOR green/red in my opinion would not give you the underlying sentiment of the momentum.

#start code
input ThermoLookBackBars = 50;
input PlotType = {default AdaptiveMovingAverages, Standard};

def HighLowScore = 1000 * ((high - high[1]) / (high[1]) +
(low - low[1]) / low[1]);

#ATR TrailingStop Code
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
loss = ATRFactor * ATRMod;
case unmodified:
loss = ATRFactor * Average(TrueRange(high, close, low), ATRPeriod);
}

rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
}
else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
}
else {
state = state.long;
trail = close - loss;
}
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def TrailingStop = trail;
#TrailingStop.Hide();
#End ATR Trailing Stop Code

def A = Highest(high[1], ThermoLookBackBars);
def B = Lowest(low[1], ThermoLookBackBars);

def FiftyTwoWeekHigh = A;

def FiftyTwoWeekLow = B;

def FiftyTwoWeekScore = 10 * (((high
- FiftyTwoWeekHigh) / FiftyTwoWeekHigh) +
((low - FiftyTwoWeekLow) / FiftyTwoWeekLow));

def ThermoScore = ExpAverage(HighLowScore + FiftyTwoWeekScore, ThermoLookBackBars);

input FastLengthShort = 5;
input SlowLengthShort = 15;
input EffRatioShort = 10;
#input FastLengthLong = 10;
#input SlowLengthLong = 25;
input FastLengthLong = 9;
input SlowLengthLong = 26;
input EffRatioLong = 5;

def AMA = MovAvgAdaptive(ThermoScore, FastLengthShort, SlowLengthShort, EffRatioShort);
def AMA2 = MovAvgAdaptive(ThermoScore, FastLengthLong, SlowLengthLong, EffRatioLong);

def Line1;
#Line1.Hide();
def Line2;
#Line2.Hide();

switch (PlotType) {
case AdaptiveMovingAverages:
Line1 = AMA;
Line2 = AMA2;
case Standard:
Line1 = ThermoScore;
Line2 = ThermoScore;
}

def InvisibleLine = close * 0;
#plot Line3 = InvisibleLine;
#Line3.Hide();

def Buy = Line1 > 0 and Line2 < 0 and state == state.long;
def StrongBuy = Line1 > 0 and Line2 >= 0 and state == state.long;
def Sell = Line1 < 0 and Line2 > 0 and state == state.short;
def StrongSell = Line1 < 0 and Line2 <= 0 and state == state.short;
def neutral = if !buy and !strongBuy and !sell and !strongSell then 1 else 0;

#def GU = BuySignal;
#GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#GU.SetDefaultColor(GetColor(8));
#GU.SetLineWeight(2);

#def GX = SellSignal;
#GX.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#GX.SetDefaultColor(GetColor(8));
#GX.SetLineWeight(2);

plot scan = buy or strongbuy or neutral;
#end code

7BbOLzv.png
That's great, thanks for providing the above codes and screen shot.
 
Hey @majidg, I have found the Trend Painter Indicator very useful (screenshot below). You can search and add it to your charts. Below is the code I use to scan uptrend stocks. The code will give you a "Buy", "Strong Buy", and "Neutral" state of the stock. Add the code as a filter study for scans. Good luck! @cabe1332

# Trend Painter Indicator With Buy & Sell Signals
# Credit to then usethinkscript.com team for this script and share. It's an awesome indicator.
#
# Candle definitions/legends
# DARK_GREEN = Buy
# GREEN = Strong Buy
# DARK_RED = Sell
# RED = Strong Sell
# BLUE = Neutral or Otherwise

#Think of the BLUE as amber color at a traffic light signal, it is warning you that something is about to change.
#By changing the color scheme to a two COLOR green/red in my opinion would not give you the underlying sentiment of the momentum.

#start code
input ThermoLookBackBars = 50;
input PlotType = {default AdaptiveMovingAverages, Standard};

def HighLowScore = 1000 * ((high - high[1]) / (high[1]) +
(low - low[1]) / low[1]);

#ATR TrailingStop Code
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
loss = ATRFactor * ATRMod;
case unmodified:
loss = ATRFactor * Average(TrueRange(high, close, low), ATRPeriod);
}

rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
}
else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
}
else {
state = state.long;
trail = close - loss;
}
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def TrailingStop = trail;
#TrailingStop.Hide();
#End ATR Trailing Stop Code

def A = Highest(high[1], ThermoLookBackBars);
def B = Lowest(low[1], ThermoLookBackBars);

def FiftyTwoWeekHigh = A;

def FiftyTwoWeekLow = B;

def FiftyTwoWeekScore = 10 * (((high
- FiftyTwoWeekHigh) / FiftyTwoWeekHigh) +
((low - FiftyTwoWeekLow) / FiftyTwoWeekLow));

def ThermoScore = ExpAverage(HighLowScore + FiftyTwoWeekScore, ThermoLookBackBars);

input FastLengthShort = 5;
input SlowLengthShort = 15;
input EffRatioShort = 10;
#input FastLengthLong = 10;
#input SlowLengthLong = 25;
input FastLengthLong = 9;
input SlowLengthLong = 26;
input EffRatioLong = 5;

def AMA = MovAvgAdaptive(ThermoScore, FastLengthShort, SlowLengthShort, EffRatioShort);
def AMA2 = MovAvgAdaptive(ThermoScore, FastLengthLong, SlowLengthLong, EffRatioLong);

def Line1;
#Line1.Hide();
def Line2;
#Line2.Hide();

switch (PlotType) {
case AdaptiveMovingAverages:
Line1 = AMA;
Line2 = AMA2;
case Standard:
Line1 = ThermoScore;
Line2 = ThermoScore;
}

def InvisibleLine = close * 0;
#plot Line3 = InvisibleLine;
#Line3.Hide();

def Buy = Line1 > 0 and Line2 < 0 and state == state.long;
def StrongBuy = Line1 > 0 and Line2 >= 0 and state == state.long;
def Sell = Line1 < 0 and Line2 > 0 and state == state.short;
def StrongSell = Line1 < 0 and Line2 <= 0 and state == state.short;
def neutral = if !buy and !strongBuy and !sell and !strongSell then 1 else 0;

#def GU = BuySignal;
#GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#GU.SetDefaultColor(GetColor(8));
#GU.SetLineWeight(2);

#def GX = SellSignal;
#GX.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#GX.SetDefaultColor(GetColor(8));
#GX.SetLineWeight(2);

plot scan = buy or strongbuy or neutral;
#end code

7BbOLzv.png
I entered the code in TOS and I don't see the above screen shot. Not sure why it is not same as the above. is the above uptrend scan code?
 
Last edited:
Hey @majidg, I have found the Trend Painter Indicator very useful (screenshot below). You can search and add it to your charts. Below is the code I use to scan uptrend stocks. The code will give you a "Buy", "Strong Buy", and "Neutral" state of the stock. Add the code as a filter study for scans. Good luck! @cabe1332

# Trend Painter Indicator With Buy & Sell Signals
# Credit to then usethinkscript.com team for this script and share. It's an awesome indicator.
#
# Candle definitions/legends
# DARK_GREEN = Buy
# GREEN = Strong Buy
# DARK_RED = Sell
# RED = Strong Sell
# BLUE = Neutral or Otherwise

#Think of the BLUE as amber color at a traffic light signal, it is warning you that something is about to change.
#By changing the color scheme to a two COLOR green/red in my opinion would not give you the underlying sentiment of the momentum.

#start code
input ThermoLookBackBars = 50;
input PlotType = {default AdaptiveMovingAverages, Standard};

def HighLowScore = 1000 * ((high - high[1]) / (high[1]) +
(low - low[1]) / low[1]);

#ATR TrailingStop Code
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
then high - close[1]
else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
then close[1] - low
else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
loss = ATRFactor * ATRMod;
case unmodified:
loss = ATRFactor * Average(TrueRange(high, close, low), ATRPeriod);
}

rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
if (!IsNaN(loss)) {
switch (firstTrade) {
case long:
state = state.long;
trail = close - loss;
case short:
state = state.short;
trail = close + loss;
}
} else {
state = state.init;
trail = Double.NaN;
}
case long:
if (close > trail[1]) {
state = state.long;
trail = Max(trail[1], close - loss);
}
else {
state = state.short;
trail = close + loss;
}
case short:
if (close < trail[1]) {
state = state.short;
trail = Min(trail[1], close + loss);
}
else {
state = state.long;
trail = close - loss;
}
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

def TrailingStop = trail;
#TrailingStop.Hide();
#End ATR Trailing Stop Code

def A = Highest(high[1], ThermoLookBackBars);
def B = Lowest(low[1], ThermoLookBackBars);

def FiftyTwoWeekHigh = A;

def FiftyTwoWeekLow = B;

def FiftyTwoWeekScore = 10 * (((high
- FiftyTwoWeekHigh) / FiftyTwoWeekHigh) +
((low - FiftyTwoWeekLow) / FiftyTwoWeekLow));

def ThermoScore = ExpAverage(HighLowScore + FiftyTwoWeekScore, ThermoLookBackBars);

input FastLengthShort = 5;
input SlowLengthShort = 15;
input EffRatioShort = 10;
#input FastLengthLong = 10;
#input SlowLengthLong = 25;
input FastLengthLong = 9;
input SlowLengthLong = 26;
input EffRatioLong = 5;

def AMA = MovAvgAdaptive(ThermoScore, FastLengthShort, SlowLengthShort, EffRatioShort);
def AMA2 = MovAvgAdaptive(ThermoScore, FastLengthLong, SlowLengthLong, EffRatioLong);

def Line1;
#Line1.Hide();
def Line2;
#Line2.Hide();

switch (PlotType) {
case AdaptiveMovingAverages:
Line1 = AMA;
Line2 = AMA2;
case Standard:
Line1 = ThermoScore;
Line2 = ThermoScore;
}

def InvisibleLine = close * 0;
#plot Line3 = InvisibleLine;
#Line3.Hide();

def Buy = Line1 > 0 and Line2 < 0 and state == state.long;
def StrongBuy = Line1 > 0 and Line2 >= 0 and state == state.long;
def Sell = Line1 < 0 and Line2 > 0 and state == state.short;
def StrongSell = Line1 < 0 and Line2 <= 0 and state == state.short;
def neutral = if !buy and !strongBuy and !sell and !strongSell then 1 else 0;

#def GU = BuySignal;
#GU.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#GU.SetDefaultColor(GetColor(8));
#GU.SetLineWeight(2);

#def GX = SellSignal;
#GX.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#GX.SetDefaultColor(GetColor(8));
#GX.SetLineWeight(2);

plot scan = buy or strongbuy or neutral;
#end code

7BbOLzv.png
Hi @cabe1332 , i have looked into the Trend Painter Indicator code in another post. But I am very interested in knowing how i put the 2 pieces of code together (or how to apply these) in order to get the same view in your screen capture.

Sorry if this is a stupid question.
If I can apply this to my charts, that will be very indicative.
 
Hi @cabe1332 , i have looked into the Trend Painter Indicator code in another post. But I am very interested in knowing how i put the 2 pieces of code together (or how to apply these) in order to get the same view in your screen capture.

Sorry if this is a stupid question.
If I can apply this to my charts, that will be very indicative.
Hey @KLMS, adding Trend Painter is pretty easy to add into your chart. A thousand links are on this site on how to apply scripts, studies, and more. I am not sure which pieces in the screenshot view you are looking at or interested in. If I can help I will but need more info. Good luck! @cabe1332
 
I entered the code in TOS and I don't see the above screen shot. Not sure why it is not same as the above. is the above uptrend scan code?
Won't come up for me either and I have download several ind. with no problem . There is a small section at the bottom of the code that stays black when I paste it ,so that seems to be the problem for me anyways .
 
Won't come up for me either and I have download several ind. with no problem . There is a small section at the bottom of the code that stays black when I paste it ,so that seems to be the problem for me anyways .
@HEC @KLMS the code I provided is used for scanning uptrend "Buy", "Strong Buy" or Neutral stocks. Don't use it as an indicator. I've said that on my post.

If you're looking for the actual indicator, the link is below.
https://usethinkscript.com/threads/...or-with-buy-sell-signals-for-thinkorswim.226/

Good luck! @cabe1332
 
Thread starter Similar threads Forum Replies Date
A Engulfing Candle Scan Questions 0
D Power X Scan Questions 0
A Bull/Bear 180 Scan Questions 0
T 3 day low and 8 day low scan Questions 0
rvaidyamath TTM Squeeze scan not working Questions 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
418 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top