# Search for symbols that rose sharply

#### kkrac

##### New member
I've seen other posts talking about angle calculation, but for some reason I can make it work.

I've used the code in the thinkOrSwim reference page for ATan to calculate an angle:

Code:
``````declare lower;
input length = 50;
def avg = Average(close, length);
def height = avg - avg[length];
plot "Angle, deg" = ATan(height/length) * 180 / Double.Pi;``````

I created an indicator "slope" at the bottom of my chart below, which shows the slope of the 50 moving average (blue line), using the code above.
The trend line I drew says that the angle from the last point 50 bars back is 7.93º, so I would expect the "slope" indicator to show the same value for that last point in the chart but instead it says 0.393685.
Why??
Can anyone explain?

Last edited:

#### halcyonguy

##### Well-known member
VIP
I've seen other posts talking about angle calculation, but for some reason I can make it work.

I've used the code in the thinkOrSwim reference page for ATan to calculate an angle:

Code:
``````declare lower;
input length = 3;
def avg = Average(close, length);
def height = avg - avg[length];
plot "Angle, deg" = ATan(height/length) * 180 / Double.Pi;``````

I created an indicator "slope" at the bottom of my chart below, which shows the slope of the 50 moving average (blue line), using the code above.
The trend line I drew says that the angle from the last point 50 bars back is 7.93º, so I would expect the "slope" indicator to show the same value for that last point in the chart but instead it says 0.393685.
Why??
Can anyone explain?

explain ? , no, not without seeing the code.
please post the code you have trouble with and i'm sure someone will spot something.

i've never understood, why do people ask for help to fix their code,... and then don't post their code.

---------

my opinion, a chart has 2 different axis units, dollars and time. the image can change with zooming, so calculating an angle number is questionable. what i do for slope is, find the average change in dollars over a quantity of bars , \$/bars

#### kkrac

##### New member
explain ? , no, not without seeing the code.
please post the code you have trouble with and i'm sure someone will spot something.

i've never understood, why do people ask for help to fix their code,... and then don't post their code.

---------

my opinion, a chart has 2 different axis units, dollars and time. the image can change with zooming, so calculating an angle number is questionable. what i do for slope is, find the average change in dollars over a quantity of bars , \$/bars
Hi @halcyonguy, thanks for the reply

But the code is there. Now that I look at it I think I forgot to update in the code the actual length of the average that I used, my bad.
I just updated it, the length I used was actually 50, not 3 as it read originally.

I think the problem was that the angle shown with the trendline says 7.93 degrees, whereas the value for the indicator (in cyan) for the right dot of the trendline (where I had the cursor of the mouse) says 0.393685. So was a bit confused, not sure if they were showing different type of units or what.

Interesting what you mention about finding the average change in dollars vs. quantity of bars...

Last edited by a moderator:

#### kkrac

##### New member
I want to look for symbols for which their ema21 in the 5 minute chart were up in a 30 degree angle or more, for at least 12 candles (1 hour), at some point during the day.

I tried to use this code below, but it's not working as expected: I know that on May 10th, for instance \$HCDI met the condition, but it's not showing up in the results of the scan.

Can someone let me know where the issue is?

Code:
``````def lookBack = 12;
def minSlope = 30;
def ema21 = ExpAverage(close, 21);

def maDiff = ema21 - ema21[lookBack];
def maSlope = Atan(maDiff / lookBack) * 180 / Double.Pi;

def startTime = 0930;
def endTime = 1600;
def targetPeriod = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

def isSteepSlope = if targetPeriod and !targetPeriod[1] then 0
else if !targetPeriod then isSteepSlope[1]
else if maSlope >= minSlope then 1
else 0;

plot signal = isSteepSlope;``````

Last edited by a moderator:

#### Chemmy

##### Active member
VIP
I want to look for symbols for which their ema21 in the 5 minute chart were up in a 30 degree angle or more, for at least 12 candles (1 hour), at some point during the day.

I tried to use this code below, but it's not working as expected: I know that on May 10th, for instance \$HCDI met the condition, but it's not showing up in the results of the scan.

Can someone let me know where the issue is?

Code:
``````def lookBack = 12;
def minSlope = 30;
def ema21 = ExpAverage(close, 21);

def maDiff = ema21 - ema21[lookBack];
def maSlope = Atan(maDiff / lookBack) * 180 / Double.Pi;

def startTime = 0930;
def endTime = 1600;
def targetPeriod = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

def isSteepSlope = if targetPeriod and !targetPeriod[1] then 0
else if !targetPeriod then isSteepSlope[1]
else if maSlope >= minSlope then 1
else 0;

plot signal = isSteepSlope;``````

So, what I think you may not be considering (and what @halcyonguy mentioned) is exactly how slow a 21-candle EMA can move; these EMAs are moving in terms of cents, or fractions of dollars, while each new candle moves in integers. Therefore, any sort of slope or angle calculation using Tan is going to be giving you minuscule values rather than an accurate slope. What you may want to try is normalizing the values instead -- I added a simple multiplication by 10 to your code and it seems to be doing the job (I also added absolute value code for the EMA falling steeply as well):

Is that what you had in mind? I didn't do anything in terms of showing the signals other than changing them to arrows, and adding test logic in. Here's the code below if you want to fix it up to your preference:

Code:
``````input show_test = yes;
input lookBack = 5;
input minSlope = 30;
input malen = 21;
plot ema21 = ExpAverage(close, malen);

def maDiff = 10*(ema21 - ema21[lookBack]);
def maSlope = Atan(maDiff / lookBack) * 180 / Double.Pi;

def startTime = 0930;
def endTime = 1600;
def targetPeriod = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

def isSteepSlope = if targetPeriod and !targetPeriod[1] then 0
else if !targetPeriod then isSteepSlope[1]
else if AbsValue(maSlope) >= minSlope then 1
else 0;

addlabel(show_test, "Slope: " + maSlope, color.yellow);

plot signal = isSteepSlope;
signal.setpaintingstrategy(paintingstrategy.boolean_arrow_down);
ema21.sethiding(!show_test);``````

87k+ Posts
293 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?