|
| 1 | +// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ |
| 2 | +// © RicardoSantos |
| 3 | + |
| 4 | +//@version=4 |
| 5 | +study(title="[RS]Simple Forecast - Keltner Worms", shorttitle="KC", overlay=true, resolution="") |
| 6 | + |
| 7 | +src = input(close, title="Source") |
| 8 | + |
| 9 | +f_kc(_src, _length)=> |
| 10 | + _ma = ema(_src, _length) |
| 11 | + _rangema = rma(tr(true), _length) |
| 12 | + var _auto_mult = 0 |
| 13 | + for _i = _auto_mult to 9999 |
| 14 | + if abs(_src - _ma) > (_rangema * _auto_mult) |
| 15 | + _auto_mult := _auto_mult + 1 |
| 16 | + continue |
| 17 | + else |
| 18 | + break |
| 19 | + |
| 20 | + _upper = _ma + _rangema * _auto_mult |
| 21 | + _lower = _ma - _rangema * _auto_mult |
| 22 | + [_ma, _upper, _lower] |
| 23 | + |
| 24 | +[p005ma, p005upper, p005lower] = f_kc(src, 5) |
| 25 | +[p010ma, p010upper, p010lower] = f_kc(src, 10) |
| 26 | +[p025ma, p025upper, p025lower] = f_kc(src, 25) |
| 27 | +[p050ma, p050upper, p050lower] = f_kc(src, 50) |
| 28 | +[p100ma, p100upper, p100lower] = f_kc(src, 100) |
| 29 | +[p200ma, p200upper, p200lower] = f_kc(src, 200) |
| 30 | + |
| 31 | +c = color.blue |
| 32 | + |
| 33 | +p005u = plot(p005upper, color=#0094FF, title="Upper", offset=5, show_last=5) |
| 34 | +plot(p005ma, color=#0094FF, title="Basis", offset=5, show_last=5) |
| 35 | +p005l = plot(p005lower, color=#0094FF, title="Lower", offset=5, show_last=5) |
| 36 | +fill(p005u, p005l, color=#0094FF, transp=95, title="Background") |
| 37 | + |
| 38 | +p010u = plot(p010upper, color=#0094FF, title="Upper", offset=10, show_last=5) |
| 39 | +plot(p010ma, color=#0094FF, title="Basis", offset=10, show_last=5) |
| 40 | +p010l = plot(p010lower, color=#0094FF, title="Lower", offset=10, show_last=5) |
| 41 | +fill(p010u, p010l, color=#0094FF, transp=95, title="Background") |
| 42 | + |
| 43 | +p025u = plot(p025upper, color=#0094FF, title="Upper", offset=25, show_last=15) |
| 44 | +plot(p025ma, color=#0094FF, title="Basis", offset=25, show_last=15) |
| 45 | +p025l = plot(p025lower, color=#0094FF, title="Lower", offset=25, show_last=15) |
| 46 | +fill(p025u, p025l, color=#0094FF, transp=95, title="Background") |
| 47 | + |
| 48 | +p050u = plot(p050upper, color=#0094FF, title="Upper", offset=50, show_last=25) |
| 49 | +plot(p050ma, color=#0094FF, title="Basis", offset=50, show_last=25) |
| 50 | +p050l = plot(p050lower, color=#0094FF, title="Lower", offset=50, show_last=25) |
| 51 | +fill(p050u, p050l, color=#0094FF, transp=95, title="Background") |
| 52 | + |
| 53 | +p100u = plot(p100upper, color=#0094FF, title="Upper", offset=100, show_last=50) |
| 54 | +plot(p100ma, color=#0094FF, title="Basis", offset=100, show_last=50) |
| 55 | +p100l = plot(p100lower, color=#0094FF, title="Lower", offset=100, show_last=50) |
| 56 | +fill(p100u, p100l, color=#0094FF, transp=95, title="Background") |
| 57 | + |
| 58 | +p200u = plot(p200upper, color=#0094FF, title="Upper", offset=200, show_last=100) |
| 59 | +plot(p200ma, color=#0094FF, title="Basis", offset=200, show_last=100) |
| 60 | +p200l = plot(p200lower, color=#0094FF, title="Lower", offset=200, show_last=100) |
| 61 | +fill(p200u, p200l, color=#0094FF, transp=95, title="Background") |
0 commit comments