Trendline Scythes TW
Forums › ProRealTime forum Italiano › Supporto ProBuilder › Trendline Scythes TW
-
-
01/05/2025 at 11:08 PM #242208
Ciao, chiedo la traduzione di questo indicatore:
// This Pine Script™ code is subject to the terms of the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © EliCobra//@version=5
indicator(“TrendLine Scythes”, “[Ʌ] – TL Scythes”, true, max_polylines_count = 100, max_lines_count = 500, max_labels_count = 500)type bar
float o = open
float h = high
float l = low
float c = close
int i = bar_indextype trend
float h = na
float l = natype scythe
polyline a = na
line b = natype target
float u = na
float l = na
float p = na
int d = 0
bool r = false
line v = na
line h = na
label e = natype alerts
bool u = na
bool d = na
bool b = na
bool s = natype prompt
string s = ”
bool c = falsemethod notify(prompt p) =>
if p.c
alert(p.s, alert.freq_once_per_bar_close)method any(alerts a) =>
string s = switch
a.s => ‘Target Reached ‘
a.b => ‘Target Invalidated’
a.u => ‘Breakout ‘
a.d => ‘Breakdown’
=> naprompt.new(s, not na(s))
method atr(bar b, simple int len = 1) =>
float tr =
na(b.h[1]) ?
b.h – b.l :
math.max(
math.max(
b.h – b.l,
math.abs(b.h – b.c[1])),
math.abs (b.l – b.c[1]))len == 1 ? tr : ta.rma(tr, len)
method piv(trend t) =>
bool b = switch
na(t.h) and na(t.l) => false
=> trueb
method blade(array<chart.point> a, bool p, simple color u, simple color d) =>
polyline.new(a, false, true, xloc.bar_index, p ? d : u, p ? color.new(d, 80) : color.new(u, 80))
method handle(bar b, trend t, float s) =>
line l = switch
not na(t.l) =>
line.new(b.i, b.h + s, b.i, b.l , xloc.bar_index, extend.none, #9c4b11, line.style_solid, 3)not na(t.h) =>
line.new(b.i, b.h , b.i, b.l – s, xloc.bar_index, extend.none, #9c4b11, line.style_solid, 3)l
method goal(target t, bar b, simple int len) =>
t.v := line .new(b.i, b.c, b.i , t.p, xloc.bar_index, extend.none, chart.fg_color, line.style_dashed)
t.h := line .new(b.i, t.p, b.i + len, t.p, xloc.bar_index, extend.none, chart.fg_color, line.style_dashed)t.e := label.new(b.i + len, t.p, “Target”, xloc.bar_index, yloc.price, #f0a71f78, label.style_label_left, chart.fg_color, size.tiny)
method cu(target t, bar b) =>
t.l[1] < b.c[1] and t.l > b.c
method co(target t, bar b) =>
t.u[1] > b.c[1] and t.u < b.c
method cr(target t, bar b) =>
((t.d == 1 and b.c > t.p) or
(t.d == -1 and b.c < t.p))method reached(target t, bar b) =>
t.h.set_xy2(b.i, t.h.get_y2())
t.e.set_xy (b.i, t.h.get_y2())t.e.set_color(#4caf4f78)
t.e.set_text (‘Reached’ )method failed(target t, bar b) =>
t.h.set_xy2(b.i, t.h.get_y2())
t.e.set_xy (b.i, t.h.get_y2())t.e.set_color(#a53a3a78)
t.e.set_text (‘Invalid’ )const string ts = ‘Controls how restrained the target calculation is, higher values will result in tighter targets.’
const string tl = ‘Displays only the last Scythe and its target on chart.’
const string tb = ‘Adjusts the length of the scythes blade’
const string tp = ‘Swing detection length’
const string gs = ‘Scythes’, const string gt = ‘Targets’, const string gu = ‘UI Options’
len = input.int (40 , “Pivot Length” , 20, 100, 1 , tp, group = gs)
ext = input.int (80 , “Scythe Length” , 20, 200, 1 , tb, group = gs)
sen = input.int (50 , “Sensitivity %”, 0 , 100, 10, ts, group = gt)
bts = input.bool (true , “Display” , group = gt)
bol = input.bool (false , “Only Last” , tl, group = gu)
bbs = input.bool (true , “Breakouts” , group = gu)
colu = input.color(#eee7df, “” , inline = ‘1’, group = gu)
cold = input.color(#c71313, “” , inline = ‘1’, group = gu)bar b = bar .new( )
float s = b .atr( len) / len
trend t = trend.new(
ta.pivothigh(len, len),
ta.pivotlow (len, len))var target g = target.new ()
var map<int, float> u = map .new<int, float>()
var map<int, float> l = map .new<int, float>()if t.piv()
array<chart.point> a = array.new<chart.point>()
bar z = b[len]
bool p = na(t.l)for i = 0 to ext – 1
float c = s * i + s * math.pow(i, 2) / ext
a.push(chart.point.from_index(z.i + i, (p ? (z.h – c) : (z.l + c))))a.push(chart.point.from_index(z.i, (p ? (z.h – s * ext / 5) : (z.l + s * ext / 5))))
switch
not na(t.l) =>
l.clear()
for point in a
l.put(point.index, point.price)not na(t.h) =>
u.clear()
for point in a
u.put(point.index, point.price)scythe n = scythe.new(a.blade(p, colu, cold), z.handle(t, s * len))
if bol
array<polyline> blades = polyline.all
for [i, ln] in blades
if i < blades.size() – 1
ln.delete()array<line> lines = line.all
for [j, ls] in lines
if j < lines.size() – 4
ls.delete()array<label> labels = label.all
for [k, lb] in labels
if k < labels.size() – 1
lb.delete()g.u := u.contains(b.i) ? u.get(b.i) : na
g.l := l.contains(b.i) ? l.get(b.i) : nabool ucon = false
bool dcon = false
bool bcon = false
bool scon = falseif g.cr(b) and not g.r and bts
g.reached(b)
g.r := true
scon := trueif g.co(b) and bts
if not g.r
g.failed(b)
bcon := true
else
ucon := true
g.r := false
g.d := 1
g.p := b.c + s * ext * (2 – sen / 100)
g.goal(b, len)if g.cu(b) and bts
if not g.r
g.failed(b)
bcon := true
else
dcon := true
g.r := false
g.d := -1
g.p := b.c – s * ext * (2 – sen / 100)
g.goal(b, len)alerts a = alerts.new(
ucon,
dcon,
bcon,
scon)plotshape(not na(t.l) ? (b[len]).l + s * len / 5 : na, “Handle”, shape.diamond, location.absolute, colu, -len, size = size.tiny)
plotshape(not na(t.h) ? (b[len]).h – s * len / 5 : na, “Handle”, shape.diamond, location.absolute, cold, -len, size = size.tiny)plotshape(bbs and a.d, “Breakout”, shape.labeldown, location.abovebar, color.new(cold, 60), 0, ‘▿’, chart.fg_color, size = size.tiny)
plotshape(bbs and a.u, “Breakout”, shape.labelup , location.belowbar, color.new(colu, 60), 0, ‘▵’, chart.fg_color, size = size.tiny)alertcondition(a.b, ‘Target Reached ‘, ‘Target Reached ‘)
alertcondition(a.s, ‘Target Invalidated’, ‘Target Invalidated’)
alertcondition(a.u, ‘Breakout ‘ , ‘Breakout ‘ )
alertcondition(a.d, ‘Breakdown’ , ‘Breakdown’ )a.any().notify()
-
AuthorPosts
Find exclusive trading pro-tools on