+ ATR Support and Resistance

This script originally began as just a candle coloring exercise with some optional shapes plotted above/below certain candles, but I quickly realized I wanted to draw lines or zones from these candles, so eventually, after many hours spent figuring out and learning 'line.new' and 'box.new' I got things sorted.
Essentially, my line of thinking is that on impulsive candles down, the origin of the impulse is more important than the close (not always of course, as there are no unbreakable rules in what markets can do), and with impulsive candles up, the same theory applies.
So, for upward impulsive candles I've marked out the zone from the open to the low as a support (until broken, in which case it may become resistance). For downward impulsive candles the zone encompasses the open to the high. I've given the option to plot a line from the close for all of these. It's turned off by default as it's just less stuff on the chart, but you may like it.
The line length is customizable in a menu. It does funny things on low timeframes on forex and stock charts (long lines that result in chart compression), but for some reason very rarely on crypto charts. If someone who is smart (not me) and has much experience with pinescript could perhaps help me out with a fix for this, that would be great. I suspect it has something to do with my "bar_index_duration" that I defined using the time function, but I'm not sure how or why.
Line length on time frames of one hour and up it is typically fine.
Use the ATR multiple to change the sensitivity of the indicator. This is basically the determination of when a candle is beyond the ATR. A multiple of two is two times the ATR. With lower volatile pairs you can maybe make this lower. On lower time frames or with more volatile pairs (illiquid alts in particular) a higher multiple might serve better. I find the default 1.75 is mostly acceptable.
As I started this I also thought adding some sort of volume information to the candles might be useful as well, so I added a simple candle coloring feature referencing the OBV and a 21 period EMA. Candles are colored based on the OBV's relation to its moving average.
I added some plot shapes and candle coloring utilizing the RSI as well. Options to turn on or off shapes plotted for overbought and oversold across the top of the chart. The most interesting feature that I implemented here is a support/resistance zone around the centerline of the RSI. If the RSI is between 49 and 51 then you can have optional candle coloring, shapes plotted above the candles, and s/r zones drawn on the chart. In trending markets the centerline of the RSI will frequetly act as support or resistance, so by being alerted of this condition on the chart you can use that with actual levels marked off in order to help make a judgement on a trade. I think it's a nice addition, and an oft overlooked aspect of the usefulness of the RSI.
I've also included a calculation, with candle coloring and/or plot shapes, for something like a stop run on high volume. The calculation for that is in its section below, and should be pretty self explanatory.
Lastly, typing this as I'm posting it, this indicator could also be useful for helping to find placement for trailing a stop. Just a thought!
also, fixed it so if you don't want to plot zones, but are curious about where the RSI is about the centerline, symbols are plotted above or below the bar depending on if it's acting as resistance or support
Also, i've eliminated the boxes for turning off the ATR support/resistance (or supply/demand I think would be more accurate) zones, and instead have added a menu with which you may adjust for the size of the candle wick that would print a zone. The premise of this portion of the indicator, being that candles outside the true range are important, and can play a role in showing areas of supply and demand, or support and resistance, often results in, especially if trading illiquid crypto pairs, extremely long wicks. These of course result in a huge colored patch, or a large box, on the price chart. Now you can adjust for how much of the total percentage of the candle the wick consumes, and if the wick is beyond that percentage, and qualifies as a support resistance candle, a zone/box won't be displayed. Setting the number to 100 (0% 'relevant' wick--and by 'relevant' I mean that part of the candle that should produce support or resistance, with down candles having resistance, or supply at the top wick, and up candles showing support, or demand, at the bottom wick.). A lower number allows for more wick (thus will show more and potentially larger zones (although this obviously also depends on the ATR multiplier setting)) while a higher number allows for less wick. If this seems backwards, that's because it's an inversion, so the actual number in the box refers to the amount of candle comprised of the body and irrelevant (not indicative of supply/demand) wick.
I also added inputs for RSI ob/os levels in case anyone uses the shapes that print at the top of the chart. This way you can adjust what is overbought or oversold depending on your preference. I may end up adding some plotted lines for these regions as well (similar to the 49-51 s/r zone).
I need to contact TradingView about many lines not drawing on the chart, however. Not sure what happened on the change from Pinescript v4 to v5 but "close lines" won't print unless RSI s/r lines are turned off, and even then it doesn't draw them all. Also, the RSI s/r lines are not all drawn either. So I apologize for parts of this indicator not displaying as intended, and big apologies (though no one has seemed to notice?) for part of the main portion of this indicator not working.
- S/R boxes now extend automatically until they are broken. Bearish boxes get broken bullishly, bullish boxes get broken bearishly.
- added option for a mid line on impulse candles. You can set the range for the mid line to be defined by the wicks or body of the candle. The mid line terminates in the same way boxes do.
- added adjustment for the RSI S/R lines zone. The zone is defined as the area around the 50 line. Previously I had this hardcoded to 51-49. I've changed the default to 52-48, but you can adjust these as you like. They are adjustable in 0.1 steps. I suppose some people may set these to "oversold" and "overbought" regions and have lines extend from there. These lines extend in the same manner that they did in previous versions. The way the mid line and boxes terminate make less sense here, so, oh well...
Everything else functions exactly the same.
Enjoy.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.