Price approaching ADR levels scan

TonyStark

New member
Hello,
I've attempted to locate a scan using the criteria Im looking for prior to posting. If I missed one, please forward me to the thread. If not, this is what I desire; I want a scan to trigger when price is near either .50% or full ADR. This will give me enough time to look at the charts for potential setups. I do have a study (code below) that I got off the site here
https://usethinkscript.com/threads/average-daily-range-indicator-for-thinkorswim.244/
and love it. I just want it to be able to be scanned with some lead time before price hits ADR levels. Can someone help me out?
Thanks,
Chris

#Average Daily Range Levels
#By Vah for TOS, based on cristian.d CD_Average Daily Range Zones - highs and lows of the day

#The number of days you'd like average
input lenght = 21;

def dayHigh = DailyHighLow(AggregationPeriod.DAY).Dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY).DailyLow;
def dayrange = dayHigh - dayLow;
def AvgRange = average(DayRange, lenght);

plot ADR_H = open(period = AggregationPeriod.DAY) + (AvgRange/2);
plot ADR_L = open(period = AggregationPeriod.DAY) - (AvgRange/2);

plot ADR_H1 = open(period = AggregationPeriod.DAY) + (AvgRange);
plot ADR_L1 = open(period = AggregationPeriod.DAY) - (AvgRange);
 
Last edited by a moderator:
Solution
The scanner can not reference secondary aggregations. To calculate an ADR from an intraday scan, you would have to determine the beginning and end of each day, and figure out the high and low of each day yourself, and so on. This I can do quite easily, but the scanner also has limited access to historical data. The smaller the aggregation, the fewer days worth of data are available.

If you're using a 1min scan, there isn't going to be enough price history to calculate an ADR of any meaningful length. The scanner also doesn't update in real time anyway, it will only update periodically every few minutes or so. Its not going to notify you immediately if price touches a line in the same way that an alert might for example.

We're going to...
@Joshua Hello I was wondering if you could help me. Ive never added any custom code to a scan. Would you mind giving me the steps to include the below code (I found this in another thread you replied with using this code you developed.) in a scan? I would appreciate it.

input lenght = 21;
input Thresh = .001;

def dayHigh = DailyHighLow(AggregationPeriod.DAY).Dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY).DailyLow;
def dayrange = dayHigh - dayLow;
def AvgRange = average(DayRange, lenght);

def ADR_H = open(period = AggregationPeriod.DAY) + (AvgRange/2);
def ADR_L = open(period = AggregationPeriod.DAY) - (AvgRange/2);

def iRange = (ADR_H - ADR_L) * Thresh;

def HTT = ADR_H + iRange;
def HTB = ADR_H - iRange;

def LTT = ADR_L + iRange;
def LTB = ADR_L - iRange;

plot Result = (close < HTT and close > HTB) or
(close < LTT and close > LTB);
 

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

Thanks much @Joshua . I'd like it to scan on a 1m timeframe. In the editor, when I attempt to change from D to 1m I get:
"Error: Secondary period not allowed: Day."
The editor only activates the OK button on the D time aggregation. Is there a way to get it to accept anything other than D?
 
Last edited by a moderator:
@Joshua If I understand your last post, here is the current script I use as an indicator. I have it plotting a .5 and 1 of ADR above and below open. Id like a scan to pick up a stock that comes within a definable threshold. Im not sure what would be better, a percentage or tick value.

#Average Daily Range Levels
#By Vah for TOS, based on cristian.d CD_Average Daily Range Zones - highs and lows of the day

#The number of days you'd like average
input lenght = 21;

def dayHigh = DailyHighLow(AggregationPeriod.DAY).Dailyhigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY).DailyLow;
def dayrange = dayHigh - dayLow;
def AvgRange = average(DayRange, lenght);

plot ADR_H = open(period = AggregationPeriod.DAY) + (AvgRange/2);
plot ADR_L = open(period = AggregationPeriod.DAY) - (AvgRange/2);

plot ADR_H1 = open(period = AggregationPeriod.DAY) + (AvgRange);
plot ADR_L1 = open(period = AggregationPeriod.DAY) - (AvgRange);
 
Last edited:
For now, I just want to verify that I am understanding your question correctly. Put the code below on a chart. It will show you a full ADR from the open, as well as a threshold above and below it based on a percentage of the ADR. It will draw an arrow if the close is within that threshold, or in other words, near it. It will also give you an idea of how the inputs work. The rest can easily be fleshed out if this part is correct.

You will not need to use a one minute chart, and doing so would be detrimental. The price is the price no matter what, that's the beauty of price action. The high of the day is the high of the day regardless of the aggregation, the close of a daily bar will be the close of the current intraday bar as well, and so forth. Use the daily aggregation.

I'll check back here after the closing bell.

CvnC9FE.png
Code:
Script Near
{
    Input Level = 0;
    Input Thresh = 0;
    Plot Near =
        Between(
            close,
            Level - Thresh,
            Level + Thresh
        )
    ;
}
Input Length = 21;
Input Threshold = 25;
def ADR = Average(High - Low, 21);
def Thresh = (Threshold * 0.01) * ADR;
plot Full = Open + ADR; # <--
def Half = Open + (ADR / 2);
def Null = Open - ADR;
def Nalf = Open - (ADR / 2);
def NearPosFull = Near(Full,Thresh);
def NearPosHalf = Near(Half,Thresh);
def NearNegFull = Near(Null,Thresh);
def NearNegHalf = Near(Nalf,Thresh);

plot Test = Full + Thresh;
plot Test2 = Full - Thresh;
plot test3 = NearPosFull;
Test3.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);
 
@Joshua Thanks for your time. That's not really what Im looking for. Ive attached a screenshot. This chart is a 1m aggregation. The dotted grey lines are the .5 ADR and 1 (full) ADR respectively. The red lines above them are the areas (roughly) that I want a scan to pick up stocks when their price reaches this threshold - a percentage probably. Finally the green line is the open. Obviously, when price would be approaching the ADR's from above the open, stocks would be picked up by scan and when approaching from below the open, same thing.

nsXpmRG.png
 
And you would like the scan to be triggered when current prices are between a red line and a gray line? Be very specific.
I would like the scan to trigger as price touches the redline, not between. If price is above the open, scan would trigger when price touches red line BELOW the gray plotline. If price is below the open, scan would trigger when prices touches red line ABOVE the gray plotline. My code I posted on this thread plots those gray lines. I want to be notified when price touches the red line (input would be a percentage I imagine. I open to other / better suggestions on this). This gives me time to pull stock up on a chart in time to enter a trade if my other criteria is met.
 
The scanner can not reference secondary aggregations. To calculate an ADR from an intraday scan, you would have to determine the beginning and end of each day, and figure out the high and low of each day yourself, and so on. This I can do quite easily, but the scanner also has limited access to historical data. The smaller the aggregation, the fewer days worth of data are available.

If you're using a 1min scan, there isn't going to be enough price history to calculate an ADR of any meaningful length. The scanner also doesn't update in real time anyway, it will only update periodically every few minutes or so. Its not going to notify you immediately if price touches a line in the same way that an alert might for example.

We're going to need to create some type of zone or threshold around your preferred price level, this has less to do with your actual strategy, and more to do with giving the scanner some freedom to actually trigger. The length of the ADR will also determine the minimum aggregation that can be used. Were you dead set on 21 days, or is that just an example?
 
Solution
Hi Sorry - the lateness. Was down w flu. So I was thinking w what you said about the scanner not updating in real time. Right now, I have a scan that notifies me when price hits 68 on the RSI for a 1m chart, and another that notifies me when price is at 32. RSI is the first criteria of a few that make up my setups. I began noticing that when price hits 70 or 30 and there's an ADR plotted, it adds probability to a fade. Having the scanner trigger when price is a couple digits away from overbought or oversold gives me time to set an Alert on the chart near the ADR's plotted. With all of this in mind, I'm going to leave this effort on notifying me about when price is near the ADR's out of the equation. I dont mind manually setting alerts on the charts to accomplish this in real time. I appreciate your helping me and engaging in my thread. Thanks very much.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
363 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