1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//@version=3
//
// A port of the MT4 indicator of Mladen Rakic found at https://www.mql5.com/en/forum/179876
// which is based on Dynamic Zones that was originally published in Stocks & Commodities 1996 issue.
//
// Dynamic Zones is meant to be applied to oscillators to get dynamic overbought and oversold levels
// quantified using statistical methods.
//
// -----------------------------------------------------------------------------
// Copyright 2018 sherwind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License can be found here
// <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//
study("Dynamic Zones")
input_src = input(close, title="Price Source", type=source)
input_lookbackbars = input(70, title="Lookback Bars", minval=1)
input_startbuyprobability = input(0.12, title="Start Buy Probability")
input_startsellprobability = input(0.12, title="Start Sell Probability")
dzsell(src, initvalue, lookbackbars) =>
left = -10000.0
right = 10000.0
eps = 0.001
yval = (left + right)/2.0
delta = yval - left
maxsteps = 0
for i = 0 to 99999
if not (delta > 0.005 and maxsteps < 50)
break
maxsteps := maxsteps + 1
count = 0
for k = 0 to lookbackbars - 1
if src[k] > yval
count := count + 1
prob = count / lookbackbars
if prob > (initvalue + eps)
left := yval
yval := (yval + right)/2.0
if prob < (initvalue - eps)
right := yval
yval := (yval + left)/2.0
if prob < (initvalue + eps) and prob > (initvalue - eps)
left := yval
yval := (yval + right)/2.0
delta := yval - left
[yval, delta, maxsteps]
dzbuy(src, initvalue, lookbackbars) =>
left = -10000.0
right = 10000.0
eps = 0.001
yval = (left + right)/2.0
delta = yval - left
maxsteps = 0
for i = 0 to 99999
if not (delta > 0.005 and maxsteps < 50)
break
maxsteps := maxsteps + 1
count = 0
for k = 0 to lookbackbars - 1
if src[k] < yval
count := count + 1
prob = count / lookbackbars
if prob > (initvalue + eps)
right := yval
yval := (yval + left)/2.0
if prob < (initvalue - eps)
left := yval
yval := (yval + right)/2.0
if prob < (initvalue + eps) and prob > (initvalue - eps)
right := yval
yval := (yval + left)/2.0
delta := yval - left
[yval, delta, maxsteps]
[sell_zone, sell_delta, sell_maxsteps] = dzsell(input_src, input_startsellprobability, input_lookbackbars)
[buy_zone, buy_delta, buy_maxsteps] = dzbuy(input_src, input_startbuyprobability, input_lookbackbars)
upper_band = plot(sell_zone, title="Sell Zone", color=gray)
lower_band = plot(buy_zone, title="Buy Zone", color=gray)
fill(upper_band, lower_band, color=purple, transp=90)
plot(input_src, color=purple, transp=0)
8 comments
I have not released it as public because it is not my script to release. TradingView House Rules must be respected, and should I wish to release it as Public, I would first need to ask the Author for Permission to Re-Use his script, as well as update my version to something that is more read-able and user-friendly. I aim to provide insightful ideas and thinking with my current library of Open-Source scripts, and try to come up with original ideas, which this is not. If the author gives me permission, I would gladly make a private publication(So it does not show on my Main Library) with Open-Source Code and share it here so others who may be interested may get it here. However I did nothing fancy, just copy & pasted a few lines from the original script for personal use.
-Regards,
@DayTradingOil