Trendline Scythes TW

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #242208 quote
    StenozarStenozar
    Participant
    Master

    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_index

    type trend
    float h = na
    float l = na

    type scythe
    polyline a = na
    line b = na

    type target
    float u = na
    float l = na
    float p = na
    int d = 0
    bool r = false
    line v = na
    line h = na
    label e = na

    type alerts
    bool u = na
    bool d = na
    bool b = na
    bool s = na

    type prompt
    string s = ”
    bool c = false

    method 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’
    => na

    prompt.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
    => true

    b

    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) : na

    bool ucon = false
    bool dcon = false
    bool bcon = false
    bool scon = false

    if g.cr(b) and not g.r and bts
    g.reached(b)
    g.r := true
    scon := true

    if 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()

    #243786 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Ciao! Questo è difficile per me 🙁 Ecco il codice che ho:

    //--------------------------------------------------//
    // PRC_TrendLine Scythes
    //--------------------------------------------------//
    
    //--------------------------------------------------//
    // Parameters
    //--------------------------------------------------//
    len = 40       // Length for pivot detection
    ext = 80       // Scythe extension
    showScythes = 1 // Display scythes on the chart
    sensivity = 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 index
    z = z + 1                     // Increment counter
    if z > 1 then
    $slopeL[z] = ABS(($PLy[z] - $PLy[z-1]) / ($PLx[z] - $PLx[z-1]))  // Always positive slope
    endif
    endif
    
    if 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 index
    t = t + 1                      // Increment counter
    if t > 1 then
    $slopeH[t] = -ABS(($PHy[t] - $PHy[t-1]) / ($PHx[t] - $PHx[t-1])) // Always negative slope
    endif
    endif
    
    //--------------------------------------------------//
    // Drawing the Scythe with More Pronounced Curve
    //--------------------------------------------------//
    if islastbarupdate and showScythes then
    // Iterate through all high pivots (descending scythe)
    FOR i = t DOWNTO 2 DO
    x1 = $PHx[i]
    y1 = $PHy[i]
    slope = $slopeH[i]
    // Draw the base straight line
    x2 = x1 + ext
    y2 = 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 curvature
    FOR j = 0 TO ext DO
    // Define the base line equation: Ax + By + C = 0
    A = slope
    B = -1
    C = y1 - (slope * x1)
    
    IF j <= 40 THEN
    x3 = x1 + j
    y3 = y1 + 2 * (slope * j) - (slope * pow(j,2) / ext)  // First half
         
    // Apply reflection formula
    denom = (A * A + B * B)
    x3r = x3 - (2 * A * (A * x3 + B * y3 + C)) / denom
    y3r = y3 - (2 * B * (A * x3 + B * y3 + C)) / denom
    
    // Draw the segment between the previous and current point
    IF j > 0 THEN
    drawsegment(x4r, y4r, x3r, y3r) coloured("darkred")
    ENDIF
    // Store the current point for the next segment
    x4r = x3r
    y4r = y3r
    ELSE
    x3 = x2 - (80-j)
    y3 = y2 - 2*(slope * (80-j)) + (slope * pow(80-j,2) / ext)  // Second half
    y4 = 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")
    ENDIF
    NEXT
    NEXT
    
    // Iterate through all low pivots (ascending scythe)
    FOR i = z DOWNTO 2 DO
    x1 = $PLx[i]
    y1 = $PLy[i]
    slope = $slopeL[i]
    
    // Draw the base straight line
    x2 = x1 + ext
    y2 = 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 curvature
    FOR j = 0 TO ext DO
    // Define the base line equation: Ax + By + C = 0
    A = slope
    B = -1
    C = y1 - (slope * x1)
    
    IF j <= 40 THEN
    x3 = x1 + j
    y3 = y1 + 2 * (slope * j) - (slope * pow(j,2) / ext)  // First half
                    
    // Apply reflection formula
    denom = (A * A + B * B)
    x3r = x3 - (2 * A * (A * x3 + B * y3 + C)) / denom
    y3r = y3 - (2 * B * (A * x3 + B * y3 + C)) / denom
    // Draw the segment between the previous and current point
    IF j > 0 THEN
    drawsegment(x4r, y4r, x3r, y3r) coloured("darkblue")
    ENDIF
    // Store the current point for the next segment
    x4r = x3r
    y4r = y3r
    ELSE
    x3 = x2 - (80-j)
    y3 = y2 - 2*(slope * (80-j)) + (slope * pow(80-j,2) / ext)  // Second half
    y4 = 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")
    ENDIF
    NEXT
    
    NEXT
    ENDIF
    return
    #243808 quote
    StenozarStenozar
    Participant
    Master

    Grazie mille Ivan, sempre gentilissimo!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Trendline Scythes TW


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Stenozar @stenozar Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by StenozarStenozar
1 year, 7 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 01/05/2025
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...