TradingView
Lemrin
Apr 6, 2018 12:55 AM

Automatic Support, Resistance, Fibonacci Levels 

U.S. Dollar/Japanese YenFXCM

Description

This indicator plots absolute high and low values for up to five completely adjustable time periods (in months, weeks, days, hours, minutes) and optionally calculates the Fibonacci levels on the pair of absolutes of your choice, ascending or descending, and mimics the shading available in the built-in Fib charting tools (e.g. retracement).

Here are a few screenshots of the same chart with various options selected.

3-Month, 4-Week, and 5-Day absolutes with 3-Monthly Fib plotted:


The same chart with 4-Weekly Fib:


The same chart with 5-Daily Fib:



5-Day, 12-Hour, 90-Minute absolutes with 12-Hourly Fib:


Zoomed in, on a 30-minute interval, with 90-minute Fib:


With descending ("inverted") 90-minute Fib:


I started putting this together for Vazzyb, who was looking for a way to automate plotting horizontal support and resistance levels for monthly, weekly, and daily extremes, and then I added additional features as they occurred to me. Special thanks to Paaax, who suggested I add Fib levels.

I am leaving the code open, so you may feel free to grab snippets you like and use them for your own purposes. Of particular interest may be my custom "calc_fib()" function, which accepts any series pair, as well as a Boolean indicating whether to invert, and returns an array with each of the major Fibonacci levels: [_236,_382,_500,_618,_786,_1618].

If anyone likes this enough to feel generous, please feel free:
BTC
3KmFchJ18QvMzAJKDcFQXvyK9p1EHWQdhP
BCH
qqtrw64ptuwprk5vtj3z8qwkvh3v0jawxq7khqng7x
ETH
0x9b51361A278910Ba3945C7519C9f0FA8a77df18d
LTC
MDeWWsP7XCG2zQuZ2dYALZXQ52u2qkc8fh

P.S. If you want the time lengths to be as close to accurate as possible, don't forget to change the number of days per week when using for cryptocurrency!

Release Notes

Added the option to hold monthly, weekly, and daily S/R levels constant throughout each day, changing only at the start of each new trading session, by request.
Added the option to turn all lines gray...as a bonus.
Remember, Fibonacci levels can be turned off by selecting "None."

Release Notes

Removed all-grey option; added configurable zigzag indicator. Note that the TV built-in zigzag will usually be better, since that indicator redraws its past--something that a script cannot do. Depth and sensitivity are options, though.

Release Notes

Made more sensible color choices; added option to connect support/resist lines with a line and disabled this option by default; enabled "Keep Lines Straight All Day" by default; set default zigzag depth to 50.

Example of 1-week (red), 2-day (blue) levels plotted with no Fib:

Release Notes

Fixed an error in the zigzag logic. Shown in the preview image alongside my Support/Resistance (Daily Bars) indicator.
Comments
CarlEverest
Can you make this indicator to give an alert once an asset retraces into a specific fib level?
Lemrin
@Pipo78, That's a nice idea, sure. It will probably be some time before I can get around to it, but feel free to modify the code (open source) as you like in the meantime.
CarlEverest
@Lemrin, Thank you for the nice work, I will try to figure it out :)
gfglenn1
What time frame is best to use if you you are using the per minute basis the 2520?
siredward10
vinayksingh4
Can I use this as AutoSR for finding BTST stocks. MY BTST trading strategy will focus on correct entry using volume breakouts. To find those potential entry points, I will start by enabling Auto-Support/Resistance by applying your code to charts. Then I will select “Auto-SR Based on Current Cursor” so that the Auto-SR lines are dynamically drawn based on where the current cursor is (i.e. using the past 240 bars exclusive of current cursor). This can be a great way to visually back-test Auto-Support/Resistance. Then I will place a buy order (BTST). Now, I will need exit points, for that I need to create a custom scan based on “Chandelier Exit”. Can you code it too.
Oracle618
Useful indicator. I have an unrelated question: how do you find the bar# of each bar on the price chart? In tools such as pitchfork, you can actually enter price and bar# at the "coordinates" tab. I'd appreciate any hints.
Lemrin
@TheCryp, in Pine v3, use the built-in variable "n" to get bar number. In v4, which I have not yet bothered using, I think this was changed to "bar_index"
Oracle618
@Lemrin, how abut bar# of a bar in the past? n gives the current bar#. I guess once can count backwards but I was wondering if there is anything else. Such as pointing your mouse at a bar and get the bar#. Thanks for your time.
More