Trendline Scythes TW
Forums › ProRealTime forum Italiano › Supporto ProBuilder › Trendline Scythes TW
- This topic has 2 replies, 2 voices, and was last updated 1 week ago by
Stenozar.
-
-
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()
02/13/2025 at 4:28 PM #243786Ciao! Questo è difficile per me 🙁 Ecco il codice che ho:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133//--------------------------------------------------//// PRC_TrendLine Scythes//--------------------------------------------------////--------------------------------------------------//// Parameters//--------------------------------------------------//len = 40 // Length for pivot detectionext = 80 // Scythe extensionshowScythes = 1 // Display scythes on the chartsensivity = 100//--------------------------------------------------//// Pivot Detection and Storage//--------------------------------------------------//if low > lowest[len](low) and lowest[len](low) > low[len] and low[len] < lowest[len](low)[len+1] then$PLy[z+1] = low[len] // Store pivot low price$PLx[z+1] = barindex[len] // Store pivot low indexz = z + 1 // Increment counterif z > 1 then$slopeL[z] = ABS(($PLy[z] - $PLy[z-1]) / ($PLx[z] - $PLx[z-1])) // Always positive slopeendifendifif high < highest[len](high) and highest[len](high) < high[len] and high[len] > highest[len](high)[len+1] then$PHy[t+1] = high[len] // Store pivot high price$PHx[t+1] = barindex[len] // Store pivot high indext = t + 1 // Increment counterif t > 1 then$slopeH[t] = -ABS(($PHy[t] - $PHy[t-1]) / ($PHx[t] - $PHx[t-1])) // Always negative slopeendifendif//--------------------------------------------------//// Drawing the Scythe with More Pronounced Curve//--------------------------------------------------//if islastbarupdate and showScythes then// Iterate through all high pivots (descending scythe)FOR i = t DOWNTO 2 DOx1 = $PHx[i]y1 = $PHy[i]slope = $slopeH[i]// Draw the base straight linex2 = x1 + exty2 = y1 + (ext * slope)drawsegment(x1, y1, x2, y2) coloured("red")// Draw the TP line$tpH1[i]=y1-slope*ext*(2-sensivity/100)$tpH2[i]=y2-slope*ext*(2-sensivity/100)//drawsegment(x1,tp1,x2,tp2)style(dottedline)// Draw the curve with a more pronounced curvatureFOR j = 0 TO ext DO// Define the base line equation: Ax + By + C = 0A = slopeB = -1C = y1 - (slope * x1)IF j <= 40 THENx3 = x1 + jy3 = y1 + 2 * (slope * j) - (slope * pow(j,2) / ext) // First half// Apply reflection formuladenom = (A * A + B * B)x3r = x3 - (2 * A * (A * x3 + B * y3 + C)) / denomy3r = y3 - (2 * B * (A * x3 + B * y3 + C)) / denom// Draw the segment between the previous and current pointIF j > 0 THENdrawsegment(x4r, y4r, x3r, y3r) coloured("darkred")ENDIF// Store the current point for the next segmentx4r = x3ry4r = y3rELSEx3 = x2 - (80-j)y3 = y2 - 2*(slope * (80-j)) + (slope * pow(80-j,2) / ext) // Second halfy4 = y2 - 2*(slope *(80-(j-1))) + (slope * pow(80-(j-1),2) / ext)x4 = x2 - (80-j + 1)drawsegment(x4, y4, x3, y3) coloured("darkred")ENDIFNEXTNEXT// Iterate through all low pivots (ascending scythe)FOR i = z DOWNTO 2 DOx1 = $PLx[i]y1 = $PLy[i]slope = $slopeL[i]// Draw the base straight linex2 = x1 + exty2 = y1 + (ext * slope)drawsegment(x1, y1, x2, y2) coloured("blue")// Draw the TP line$tpL1[i]=y1-slope*ext*(2-sensivity/100)$tpL2[i]=y2-slope*ext*(2-sensivity/100)//drawsegment(x1,tp1,x2,tp2)style(dottedline)coloured("black")// Draw the curve with a more pronounced curvatureFOR j = 0 TO ext DO// Define the base line equation: Ax + By + C = 0A = slopeB = -1C = y1 - (slope * x1)IF j <= 40 THENx3 = x1 + jy3 = y1 + 2 * (slope * j) - (slope * pow(j,2) / ext) // First half// Apply reflection formuladenom = (A * A + B * B)x3r = x3 - (2 * A * (A * x3 + B * y3 + C)) / denomy3r = y3 - (2 * B * (A * x3 + B * y3 + C)) / denom// Draw the segment between the previous and current pointIF j > 0 THENdrawsegment(x4r, y4r, x3r, y3r) coloured("darkblue")ENDIF// Store the current point for the next segmentx4r = x3ry4r = y3rELSEx3 = x2 - (80-j)y3 = y2 - 2*(slope * (80-j)) + (slope * pow(80-j,2) / ext) // Second halfy4 = y2 - 2*(slope *(80-(j-1))) + (slope * pow(80-(j-1),2) / ext)x4 = x2 - (80-j + 1)drawsegment(x4, y4, x3, y3) coloured("darkblue")ENDIFNEXTNEXTENDIFreturn02/13/2025 at 9:19 PM #243808 -
AuthorPosts
Find exclusive trading pro-tools on