Blackflag FTS indicator

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

    Buon pomeriggio, chiedo la traduzione del seguente indicatore.

    Grazie

     

    //@version=6
    indicator(“Blackflag FTS”, overlay = true)

    // inputs
    trailType = input.string(“modified”, title = “Trailtype”, options = [“modified”, “unmodified”])
    ATRPeriod = input.int(28, title = “ATR Period”)
    ATRFactor = input.int(12, title = “ATR Factor”)
    show_fib_entries = input.bool(true, title = “Show Fib Entries?”)

    norm_o = request.security(syminfo.tickerid, timeframe.period, open)
    norm_h = request.security(syminfo.tickerid, timeframe.period, high)
    norm_l = request.security(syminfo.tickerid, timeframe.period, low)
    norm_c = request.security(syminfo.tickerid, timeframe.period, close)

    //////// FUNCTIONS //////////////
    Wild_ma(_src, _malength) =>
    var _wild = 0.0
    _wild := na(_wild[1]) ? _src : _wild[1] + (_src – _wild[1]) / _malength

    /////////// TRUE RANGE CALCULATIONS /////////////////
    HiLo = math.min(norm_h – norm_l, 1.5 * ta.sma((norm_h – norm_l), ATRPeriod))

    HRef = norm_l <= norm_h[1] ?
    norm_h – norm_c[1] :
    (norm_h – norm_c[1]) – 0.5 * (norm_l – norm_h[1])

    LRef = norm_h >= norm_l[1] ?
    norm_c[1] – norm_l :
    (norm_c[1] – norm_l) – 0.5 * (norm_l[1] – norm_h)

    trueRange =
    trailType == “modified” ? math.max(HiLo, HRef, LRef) :
    math.max(norm_h – norm_l, math.abs(norm_h – norm_c[1]), math.abs(norm_l – norm_c[1]))

    /////////// TRADE LOGIC ////////////////////////
    loss = ATRFactor * Wild_ma(trueRange, ATRPeriod)

    Up = norm_c – loss
    Dn = norm_c + loss

    var TrendUp = Up
    var TrendDown = Dn
    var Trend = 1 // Initialize Trend as long (1)

    TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up
    TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn

    Trend := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 : Trend[1]
    trail = Trend == 1 ? TrendUp : TrendDown

    ex = 0.0
    ex :=
    ta.crossover(Trend[1], 0) ? norm_h :
    ta.crossunder(Trend[1], 0) ? norm_l :
    Trend == 1 ? math.max(ex[1], norm_h) :
    Trend == -1 ? math.min(ex[1], norm_l) : ex[1]

    ////// FIBONACCI LEVELS ///////////
    state = Trend == 1 ? “long” : “short”

    fib1Level = 61.8
    fib2Level = 78.6
    fib3Level = 88.6

    f1 = ex + (trail – ex) * fib1Level / 100
    f2 = ex + (trail – ex) * fib2Level / 100
    f3 = ex + (trail – ex) * fib3Level / 100
    l100 = trail + 0

    Fib1 = plot(f1, title = “Fib 1”, style = plot.style_line, color = color.black)
    Fib2 = plot(f2, title = “Fib 2”, style = plot.style_line, color = color.black)
    Fib3 = plot(f3, title = “Fib 3”, style = plot.style_line, color = color.black)
    L100 = plot(l100, title = “l100”, style = plot.style_line, color = color.black)

    fill(Fib1, Fib2, color = state == “long” ? color.green : state == “short” ? color.red : na)
    fill(Fib2, Fib3, color = state == “long” ? color.new(color.green, 70) : state == “short” ? color.new(color.red, 70) : na)
    fill(Fib3, L100, color = state == “long” ? color.new(color.green, 60) : state == “short” ? color.new(color.red, 60) : na)

    l1 = state[1] == “long” and ta.crossunder(norm_c, f1[1])
    l2 = state[1] == “long” and ta.crossunder(norm_c, f2[1])
    l3 = state[1] == “long” and ta.crossunder(norm_c, f3[1])
    s1 = state[1] == “short” and ta.crossover(norm_c, f1[1])
    s2 = state[1] == “short” and ta.crossover(norm_c, f2[1])
    s3 = state[1] == “short” and ta.crossover(norm_c, f3[1])

    atr = ta.sma(trueRange, 14)

    /////////// FIB PLOTS /////////////////
    plotshape(show_fib_entries and l1 ? low – atr : na, title = “LS1”, style = shape.triangleup, location = location.belowbar, color = color.yellow, size = size.tiny)
    plotshape(show_fib_entries and l2 ? low – 1.5 * atr : na, title = “LS2”, style = shape.triangleup, location = location.belowbar, color = color.yellow, size = size.tiny)
    plotshape(show_fib_entries and l3 ? low – 2 * atr : na, title = “LS3”, style = shape.triangleup, location = location.belowbar, color = color.yellow, size = size.tiny)
    plotshape(show_fib_entries and s1 ? high + atr : na, title = “SS1”, style = shape.triangledown, location = location.abovebar, color = color.purple, size = size.tiny)
    plotshape(show_fib_entries and s3 ? high + 2 * atr : na, title = “SS3″, style = shape.triangledown, location = location.abovebar, color = color.purple, size = size.tiny)

    /////////// ADDING BUY and SELL INDICATORS ////////////

    // Conditions for Trend Change (Green -> Red or Red -> Green)
    trendChangeToRed = Trend == -1 and Trend[1] == 1 // Green to Red
    trendChangeToGreen = Trend == 1 and Trend[1] == -1 // Red to Green

    // Plot only the color changes without text
    plotshape(trendChangeToRed, title=”Trend Change to Red”, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
    plotshape(trendChangeToGreen, title=”Trend Change to Green”, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)

    // Adding Alerts for Trend Change
    alertcondition(trendChangeToRed, title=”Trend Change to Red”, message=”Trend changed from Green to Red.”)
    alertcondition(trendChangeToGreen, title=”Trend Change to Green”, message=”Trend changed from Red to Green.”)

    #245333 quote
    Iván González
    Moderator
    Master

    Ecco

    //------------------------------------------------//
    //PRC_BlackFlags FTS
    //version = 0
    //27.03.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //------------------------------------------------//
    // Inputs
    //------------------------------------------------//
    trailType=1 //modified=1 unmodified=0
    atrPeriod=28
    atrFactor=5
    ShowFibEntries=0
    //------------------------------------------------//
    // True Range Calculations
    //------------------------------------------------//
    HiLo=min(high-low,1.5*average[atrPeriod](high-low))
    
    if low<=high[1] then
    Href=high-close[1]
    else
    Href=(high-close[1])-0.5*(low-high[1])
    endif
    
    if high>=low[1] then
    Lref=close[1]-low
    else
    Lref=(close[1]-low)-0.5*(low[1]-high)
    endif
    
    if trailType=1 then
    trueRange=max(HiLo,max(Href,Lref))
    else
    trueRange=max(high-low,max(abs(high-close[1]),abs(low-close[1])))
    endif
    //------------------------------------------------//
    // Trade Logic
    //------------------------------------------------//
    wildMa=WilderAverage[atrPeriod](trueRange)
    iloss=atrFactor*wildMa
    
    up=close-iloss
    dn=close+iloss
    
    trendUp=up
    trendDown=dn
    trend=1
    
    if close[1]>trendUp[1] then
    TrendUp=max(Up,TrendUp[1])
    else
    TrendUp=Up
    endif
    
    if close[1]<trendDown[1] then
    trendDown=min(Dn,trendDown[1])
    else
    trendDown=Dn
    endif
    
    if close>trendDown[1] then
    Trend=1
    elsif close<TrendUp[1] then
    Trend=-1
    else
    Trend=Trend[1]
    endif
    
    if trend=1 then
    trail=TrendUp
    r=0
    g=255
    b=0
    rex=0
    gex=230
    bex=118
    else
    trail=TrendDown
    r=255
    g=0
    b=0
    rex=225
    gex=64
    bex=251
    endif
    
    ex=0
    if trend crosses over 0 then
    ex=high
    elsif trend crosses under 0 then
    ex=low
    elsif trend=1 then
    ex=max(ex[1],high)
    elsif trend=-1 then
    ex=min(ex[1],low)
    else
    ex=ex[1]
    endif
    //------------------------------------------------//
    // Fibonacci levels
    //------------------------------------------------//
    fib1Level=61.8
    fib2Level=78.6
    fib3Level=88.6
    
    f1=ex+(trail-ex)*fib1Level/100
    f2=ex+(trail-ex)*fib2Level/100
    f3=ex+(trail-ex)*fib3Level/100
    l100=trail
    
    colorbetween(f1,f2,r,g,b,90)
    colorbetween(f3,f2,r,g,b,45)
    colorbetween(f3,l100,r,g,b,23)
    //------------------------------------------------//
    // Signals
    //------------------------------------------------//
    atr=averagetruerange[14](close)
    
    if ShowFibEntries=1 then
    if trend=1 and close crosses under f3[1] then
    drawtext("▲",barindex,low-2*atr)coloured("orange")
    elsif trend=1 and close crosses under f2[1] then
    drawtext("▲",barindex,low-1.5*atr)coloured("orange")
    elsif trend=1 and close crosses under f1[1] then
    drawtext("▲",barindex,low-1*atr)coloured("orange")
    elsif trend=-1 and close crosses over f3[1] then
    drawtext("▼",barindex,high+2*atr)coloured("purple")
    elsif trend=-1 and close crosses over f2[1] then
    drawtext("▼",barindex,high+1.5*atr)coloured("purple")
    elsif trend=-1 and close crosses over f1[1] then
    drawtext("▼",barindex,high+1*atr)coloured("purple")
    endif
    endif
    //------------------------------------------------//
    return f1 as "Fib1"style(line,1), f2 as "Fib2"style(line,1),f3 as "Fib3"style(line,1),l100 as "L100"style(line,1),trail as "trailing stop" coloured(r,g,b)style(line,2),ex as "extremun" coloured(rex,gex,bex)style(point,2)
    #245366 quote
    Stenozar
    Participant
    Master

    Grazie mille!

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

Blackflag FTS indicator


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 Stenozar
10 months, 1 week ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 03/26/2025
Status: Active
Attachments: No files
Logo Logo
Loading...