Scan for Last Bar Above ATR by Certain Percentage


Category:
0
0

I’m trying to build a scan that finds tickers whose last bar (on daily timeframe) is above the ATR by a certain percentage (e.g. 30%).

Here is what I’ve tried:

#Wizard text: range is more than
#Wizard input: percentage
#Wizard text: ATR Input period
#Wizard input: ATRPeriod

input ATRPeriod = 14;
input percentage = 20.0;
def bar = close – open;
def x = 1 + (percentage / 100);
def compare = ATR() * x;
plot scan = bar > compare;

There are two problems:

  1. The drop-down input windows don’t appear. Instead, I just see some text.
  2. When the scan runs, it gives some results that don’t appear to match the criteria.

Hope you can help.

Thanks!

Marked as spam
Posted by (Questions: 7, Answers: 5)
Asked on July 4, 2019 9:42 am
168 views
0
Private answer

As to part one of your question. There is no way (at this time) to get user input fields to populate when creating custom Study Filters for the scans in Thinkorswim.

The second part of your question. The code contains a user input for ATRPeriod. However this input is never used in the subsequent lines of code. But that is not the problem. I would offer a solution however I really don't understand what your goal is. "Scan for last bar above ATR....". ATR is computed using the high, close and low of each candle over a given length. And you are trying to compare that to the range of the body of the candle (close - open). To me, that is comparing apples to oranges.

Seems to me that you would want to compare the ATR of the current bar to the ATR averaged over a given length. So perhaps you would compute the ATR with a length of 14. Then compute the ATR with a length of 1. The later is the ATR value of the current bar. But I'm really not sure that is what you intended. So I don't have a solution for you.

After receiving feedback from the author of this post I have the following update for this response:

input atrPeriod = 14;
input percentage = 20.0;
plot scan = ATR(1) > ATR(atrPeriod) * (1 + (percentage * 0.01));

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 5, 2019 11:36 am
0
Thank you for the response. This is my first attempt at Thinkscript, so much appreciated. What I'm trying to do is get a sense of range expansion of the current bar compared to previous bars. My plan was to scan for stocks whose last bar has a range that's x% higher than the ATR. Your point about comparing apples to oranges is valid. I suppose it's better to compare the range of the current bar ATR to ATR of the previous (e.g. 14) bars. Would appreciate if you can help with this approach.
( at July 5, 2019 4:08 pm)
0
I have updated my answer to include the code for this approach.
( at July 6, 2019 8:53 am)