Realtime Divergence for Any Indicator - By John BartleThe main purpose of this script is to show historical and real-time divergences for any oscillating indicator. The secondary purpose is to give the user a lot of precise control over identifying divergences and determining what they are. This is an improved version of my other script which is similarly called "Realtime Divergence for Any Indicator"
There are four types of divergences that are offered:
Bull divergence
Hidden bull divergence
Bear divergence
Hidden Bear divergence
There are three types of potential(real-time) divergences which include:
1) Without right side bars for rightside pivots. Plus without waiting for the rightside pivot bar to complete
2) Without right side bars for rightside pivots. Plus with waiting for the rightside pivot bar to complete
3) With right side bars for rightside pivots. Plus without waiting for the rightside pivot right-most bar to complete
A definite divergence occurs when all specified bars are accounted for and fully formed.
Potential divergences use dashed lines and definite(historical) divergences use solid lines.
In addition to several other categories of settings to filter out unwanted divergences or manipulate the search process, this script also offers Alerts. Remember that alerts must not only be set within this scripts settings but also your "Alerts" panel on your right. It's strange but BOTH must be set for alerts to work...
Other interesting Things To Know:
1)I actually don't trade and so I have no need of a paid account. Unpaid accounts don't have the playback feature so I haven't really tested this script out very well. Sorry. Just let me know if something seems off and IF I have time I'll try to fix it.
2)Keep in mind that Pinescript limits the number of lines that can be shown at one time. This means that if your settings allow for a large number of divergence lines they will be removed from the leftward side of your chart but appear in the rightward side.
3) The time and the values for the price or oscillator are not the same things as each other nor are they physical things with physical space. This means that slopes of lines using the time as X and value as Y can not have definite angles. Consequently, under the setting "DIVERGENCES: SLOPE ANGLE EXCLUSION" YOU have to decide what slope equals what angle by using the setting called "Normalization Factor".
4) Remember that some individual settings apply to both the oscillator and price chart. This means that even if the setting's conditions are fulfilled in one they may not be fulfilled in the other.
5) Under the category "DIVERGENCES: INTERSECTION ALLOWANCE", if you set the "Measurement Type" to Relative Percentage then FYI any single given length will equate to an increasingly smaller percentage the further away from zero it is. Because of this, I think "Reletive Percentage" is probably only useful for price charts or oscillators with big values. Maybe >200 is OK ?
Errors:
1) If you get the error mentioning that the script must complete execution within X amount of time, this is because this is a big script and sometimes takes longer than your service plan's allotted time limit. You can just disable some of the settings to reduce the scripts amount of work and time. The biggest time savers will be to disable some lines and labels
2) If you get an error saying the script accessed a negative index(e.g. ) then try temporarily increasing the "Add More Array Elements" setting to 100-200. Sometimes it fixes the problem.
3) You may sometimes temporarily get an error that reads: "Pine cannot determine the referencing length of a series. Try using max_bars_back in the study or strategy function".
If this happens there are several things that you can do:
3A) Create a copy of my script. Then edit the section of code that looks like this ")//, max_bars_back = INSERT_YOUR_QUANTITY_HERE)" and transform it to look like this new code ", max_bars_back = INSERT_YOUR_QUANTITY_HERE)" then repeatedly try replacing "INSERT_YOUR_QUANTITY_HERE" with an increasingly larger number greater than 244 but less than 5000.
This method will increase your system resources and could cause other problems. Try changing the code back after a few hours and see if all is well again. It is a Pinescript limitation issue and happens when certain functions or variables don't get used at least once within the first 244 bars.
3B) Adjust your settings to hopefully find a divergence within the first 244 bars. If one is found then the problematic variables or functions should get used and the Pinescript 244 bar limitation should be temporarily resolved.
3C) Wait for X number of new bars to occur. If a divergence is eventually found within the first 244 bars that should solve the issue.
Tips:
1) If the amount that a setting changes value is undesirable for each time you click it then you can change that amount in the code. To do that, you'll need your own copy of my script. To make your own copy just click on "create a working copy" in the brown colored strip area above the code. Then within approximately the first 108 lines find the title of the setting you want to change. Then look to it's right to find the parameter called "step =". Change what the step equals to whatever you want. FYI, you can hover your mouse over the blue colored code and a popup will tell you what parameters(i.e. settings) that function(e.g. "input.int()") has available.
Real-time
Pocket Pivot with extrapolated Volume and Moving AveragesThe script shows historical pocket pivots, much as other scripts with a green diamond shape on the volume pane.
When the market is open, the current bar, however, is extrapolated to the end of the day using a sixth-order polynomial.
Thus real-time pocket pivots are shown. To work properly, the user must input a time-zone offset parameter; the default is west coast USA.
Time-zone offset is -12 hours to +12 hours compared to the NYSE exchange time zone (USA west coast: -3.)
The volume extrapolation polynomial is based on a historical NASDAQ intraday volume model developed locally by a team.
Only ten-day lookback pocket pivots are computed as defined initially by Dr. Chris Kacher. (The default lookback can be changed by the user.)
Only pocket pivots are shown where the low of the daily bar is within user-defined proximity to the 50-day moving average or 10-day moving average (for continuation pocket pivots.)