 # Stocks within 75% of Todays ATR range

#### Chiku83

##### New member
VIP
I need to build scanner to find stock which close above 75% of its range. Suppose stocked yesterday moved 100\$ and was close above 75\$ than i want to find that stock. Can someone help with TOS logic.

#### XeoNoX

##### Well-known member
VIP
75% of its range... you didnt specify what range compared to what? what range?

100\$ and was close above 75\$ ... you will have to clarify this.

#### Chiku83

##### New member
VIP
no suppose stock did move 100\$ in a day ....at the start of the day opening was 200\$ and close was 300\$ ...so stock moved 100\$ ...hence if it closes above 275\$ ,,,that is 75% range.

#### XeoNoX

##### Well-known member
VIP
regular trading hour open to regular trading hour close or open from premarket to close of extended hours?

VIP

#### XeoNoX

##### Well-known member
VIP
no suppose stock did move 100\$ in a day ....at the start of the day opening was 200\$ and close was 300\$ ...so stock moved 100\$ ...hence if it closes above 275\$ ,,,that is 75% range.

you want the low to be calculated as well? lets say the stock went below the open for a few dollars and it hit 190... according to your example now the range is 110? you want the low calculated in the range as well?

#### Chiku83

##### New member
VIP
you want the low to be calculated as well? lets say the stock went below the open for a few dollars and it hit 190... according to your example now the range is 110? you want the low calculated in the range as well?
Low calculate as well

#### XeoNoX

##### Well-known member
VIP
Can you grab a stock from today an plug in the numbers of how you want it to calculate and post back so that way i can see how you came up with the numbers.

#### Chiku83

##### New member
VIP
Ticker: Baba
Open 231.99
Low: 230
High 239.19
Close 236.26

Range is High-Low = 239.19-230 = 9.19\$

Close delta from low = 236.26-230(low) = 6.26

Hence 100% =9.19

So baba close > 68% of range. I can adjust threshold of 60 % instead of 75%.

#### BenTen

Staff member
Staff
VIP
@Chiku83 So you want to calculate the range of the previous day and use that for the current trading day?

#### XeoNoX

##### Well-known member
VIP
so 9.19 would be 100% and 6.26 is roughly about 60% (guessing)..... whats the formula to get the percentage that you want compared?

#### XeoNoX

##### Well-known member
VIP
The range you are talking about for future reference is called the ATR in trading.
ATR is above or below X Percentage
Price is at XYZ Percent of Todays ATR

remember to hit that like button if you found my post useful Code:
``````# ATR is above or below X Percentage
# Price is at XYZ Percent of Todays ATR
# By XeoNoX via usethinkscript.com

input threshold = 60;

def high1 = (high(period = AggregationPeriod.DAY));
def low1 = (low(period = AggregationPeriod.DAY));
def range = (high1 -  low1);

def x = high1 - low1;
def x2= close-low1;

def percentage= (x2/x)*100;

def  scan=  percentage > threshold;

AddLabel (yes, "Price is at " +  round(percentage,2) + "% of Today's ATR" );``````

For the scan u change:

Code:
``def  scan=  percentage > threshold;``

to

Code:
``plot scan=  percentage > threshold;``

and remove or comment out the "addlabel"

Code:
``#AddLabel (yes, "Price is at " +  round(percentage,2) + "% of Today's ATR" );``

Last edited:
• Chiku83 and BenTen

#### Chiku83

##### New member
VIP
Also want to do another script similar to short stock..it would be similar to above but instead greater than 60%....close of stock should be less than 25% of the range.

Eg Roku previous day (12/28) is perfect example
Open
High: 360.99
Open 359.50
Low 339.13
Close:340.33

Range: 360.99-339.13 =21.86

Close from low = 340.33-339.13=1.20 \$

So 21.86 \$ = 100%

1.20 = 58.29 =5.48%

Hence it should be part of scanner for today and can sort on price action..today would be perfect day for ROKU to get sort.

The range you are talking about for future reference is called the ATR in trading.
OK thanks got it. Appreciate it. Hear about it but didn't knew about it..let me try for couple of days and see if it matches my requirements. Thank you once again for all your time and responding to it....tons of thanks

Last edited by a moderator:

#### Chiku83

##### New member
VIP
@Chiku83 So you want to calculate the range of the previous day and use that for the current trading day?
Yes Ben

#### XeoNoX

##### Well-known member
VIP
I have no clue where you got 58.29 from.... however if you want it below 5% you just change:

input threshold = 5;
plot scan= percentage < threshold;

NOTE: for simplicity sake i kept the aspercent out of the label so you could scan against easier.

Last edited:
• Chiku83

#### Chiku83

##### New member
VIP
Ok...thanks and if I have to plot ATR for previous day i have to add ?

Code:
``````# ATR is above or below X Percentage
# Price is at XYZ Percent of Todays ATR
# By XeoNoX via usethinkscript.com

input threshold = 60;

def high1 = (high(period = AggregationPeriod.DAY[B])[/B]);
def low1 = (low(period = AggregationPeriod.DAY[B][/B]));
def range = (high1 -  low1);

def x = high1 - low1;
def x2= close-low1;

def percentage= (x2/x)*100;

def  scan=  percentage > threshold;

AddLabel (yes, "Price is at " +  round(percentage,2) + "% of Yesterday's ATR" );``````

#### XeoNoX

##### Well-known member
VIP
To get the previous days you would at  so that it looks like this:

Code:
``````def high1 = (high(period = AggregationPeriod.DAY));
def low1 = (low(period = AggregationPeriod.DAY));``````

#### XeoNoX

##### Well-known member
VIP
you should change your subject header to "Stocks within 75% of Todays ATR range" so others can find it

• Chiku83

#### Chiku83

##### New member
VIP
Thank you so much. Let me try to edit

#### BenTen

• 