|
| 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("My Script") |
| 6 | + |
| 7 | +f_grad(_value)=> |
| 8 | + _value >= 11 ? #0002A2 : |
| 9 | + _value == 10 ? #0045A9 : |
| 10 | + _value == 09 ? #008EB0 : |
| 11 | + _value == 08 ? #00B690 : |
| 12 | + _value == 07 ? #00BD4A : |
| 13 | + _value == 06 ? #01C400 : |
| 14 | + _value == 05 ? #52CA00 : |
| 15 | + _value == 04 ? #A8D100 : |
| 16 | + _value == 03 ? #D7AC00 : |
| 17 | + _value == 02 ? #DE5800 : |
| 18 | + _value == 01 ? #E50000 : color.white |
| 19 | + |
| 20 | +float feature01 = close-close[1] |
| 21 | +float feature02 = round(rsi(close, 14)[1]*10) |
| 22 | + |
| 23 | +int data_range = 10 |
| 24 | +int nclusters = 3 |
| 25 | + |
| 26 | +float[] X = array.newfloat(data_range, feature01) |
| 27 | +float[] Y = array.newfloat(data_range, feature02) |
| 28 | + |
| 29 | +for _i = 0 to data_range-1 |
| 30 | + array.set(id=X, index=_i, value=feature01[_i]) |
| 31 | + array.set(id=Y, index=_i, value=feature02[_i]) |
| 32 | + |
| 33 | +plot(series=array.get(X, 0), color=f_grad(0), linewidth=10, style=plot.style_circles, offset=int(-1000+array.get(Y, 0)), show_last=1) |
| 34 | +plot(series=array.get(X, 1), color=f_grad(1), linewidth=9, style=plot.style_circles, offset=int(-1000+array.get(Y, 1)), show_last=1) |
| 35 | +plot(series=array.get(X, 2), color=f_grad(2), linewidth=8, style=plot.style_circles, offset=int(-1000+array.get(Y, 2)), show_last=1) |
| 36 | +plot(series=array.get(X, 3), color=f_grad(3), linewidth=7, style=plot.style_circles, offset=int(-1000+array.get(Y, 3)), show_last=1) |
| 37 | +plot(series=array.get(X, 4), color=f_grad(4), linewidth=6, style=plot.style_circles, offset=int(-1000+array.get(Y, 4)), show_last=1) |
| 38 | +plot(series=array.get(X, 5), color=f_grad(5), linewidth=5, style=plot.style_circles, offset=int(-1000+array.get(Y, 5)), show_last=1) |
| 39 | +plot(series=array.get(X, 6), color=f_grad(6), linewidth=4, style=plot.style_circles, offset=int(-1000+array.get(Y, 6)), show_last=1) |
| 40 | +plot(series=array.get(X, 7), color=f_grad(7), linewidth=3, style=plot.style_circles, offset=int(-1000+array.get(Y, 7)), show_last=1) |
| 41 | +plot(series=array.get(X, 8), color=f_grad(8), linewidth=2, style=plot.style_circles, offset=int(-1000+array.get(Y, 8)), show_last=1) |
| 42 | +plot(series=array.get(X, 9), color=f_grad(9), linewidth=1, style=plot.style_circles, offset=int(-1000+array.get(Y, 9)), show_last=1) |
| 43 | + |
| 44 | +// plot different shapes: |
| 45 | +// plotshape(series=array.get(X, 9), title='', style=shape.cross, location=location.absolute, color=f_grad(9), transp=25, offset=int(-1000+array.get(Y, 9)), size=size.normal, show_last=1) |
| 46 | +// plotshape(series=array.get(X, 5), title='', style=shape.diamond, location=location.absolute, color=f_grad(5), transp=25, offset=int(-1000+array.get(Y, 5)), size=size.normal, show_last=1) |
| 47 | + |
| 48 | +// not centered location |
| 49 | +//plotchar(series=array.get(X, 2), title='', char='*', location=location.absolute, color=f_grad(2), transp=25, offset=int(-1000+array.get(Y, 2)), size=size.normal, show_last=1) |
| 50 | + |
| 51 | +var line box_top = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, xloc=xloc.bar_index, extend=extend.none, color=color.gray, style=line.style_solid, width=1) |
| 52 | +var line box_bot = line.new(x1=bar_index, y1=0., x2=bar_index, y2=0., xloc=xloc.bar_index, extend=extend.none, color=color.gray, style=line.style_solid, width=1) |
| 53 | +var line box_left = line.new(x1=bar_index, y1=0., x2=bar_index, y2=0., xloc=xloc.bar_index, extend=extend.none, color=color.gray, style=line.style_solid, width=1) |
| 54 | +var line box_right = line.new(x1=bar_index, y1=0., x2=bar_index, y2=0., xloc=xloc.bar_index, extend=extend.none, color=color.gray, style=line.style_solid, width=1) |
| 55 | + |
| 56 | +var line box_ob = line.new(x1=bar_index, y1=0., x2=bar_index, y2=0., xloc=xloc.bar_index, extend=extend.none, color=color.olive, style=line.style_dashed, width=1) |
| 57 | +var line box_os = line.new(x1=bar_index, y1=0., x2=bar_index, y2=0., xloc=xloc.bar_index, extend=extend.none, color=color.orange, style=line.style_dashed, width=1) |
| 58 | + |
| 59 | +var float top = 0.0 |
| 60 | +var float bot = 0.0 |
| 61 | +int left = bar_index-1000 |
| 62 | +int right = bar_index |
| 63 | +int ob = bar_index-250 |
| 64 | +int os = bar_index-750 |
| 65 | + |
| 66 | +top := cum(array.max(id=X)) / (bar_index + 1)//max(nz(top), array.max(id=X)) |
| 67 | +bot := cum(array.min(id=X)) / (bar_index + 1)//min(nz(bot), array.min(id=X)) |
| 68 | + |
| 69 | +// plot(series=top) |
| 70 | +// plot(series=bot) |
| 71 | +hline(0) |
| 72 | + |
| 73 | +line.set_xy1(id=box_top, x=left, y=top) |
| 74 | +line.set_xy2(id=box_top, x=right, y=top) |
| 75 | +line.set_xy1(id=box_bot, x=left, y=bot) |
| 76 | +line.set_xy2(id=box_bot, x=right, y=bot) |
| 77 | +line.set_xy1(id=box_left, x=left, y=top) |
| 78 | +line.set_xy2(id=box_left, x=left, y=bot) |
| 79 | +line.set_xy1(id=box_right, x=right, y=top) |
| 80 | +line.set_xy2(id=box_right, x=right, y=bot) |
| 81 | +line.set_xy1(id=box_ob, x=ob, y=top) |
| 82 | +line.set_xy2(id=box_ob, x=ob, y=bot) |
| 83 | +line.set_xy1(id=box_os, x=os, y=top) |
| 84 | +line.set_xy2(id=box_os, x=os, y=bot) |
| 85 | + |
0 commit comments