Conversion Force Index with ATR from TradingView

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #237739 quote
    Alera15
    Participant
    New

    Hello,
    I can’t manage to convert the Elder’s Force Index indicator with 3 ATR on my own. The indicator displays the FI with its ATRs, and when the FI is outside the 3rd ATR, it shows a dot to indicate that it’s overbought or oversold. Is anyone able to help me?

    Thank you very much.

    Original Indicator URL : https://www.tradingview.com/script/GNbQ24KL-Elder-Force-Index-With-ATR-Channels-loxx/

    Salve,
    Non riesco a convertire da solo l’indicatore Elder’s Force Index con 3 ATR. L’indicatore mostra l’FI con i suoi ATR e quando l’FI è al di fuori del 3° ATR, mostra un punto per indicare che è ipercomprato o ipervenduto. Qualcuno può aiutarmi?

    Grazie mille.

    URL indicatore originale:http://www.tradingview.com/script/GNbQ24KL-Elder-Force-Index-With-ATR-Channels-loxx/

    CODE:

    //@version=5
    indicator(title=‘Elder Force Index With ATR Channels [loxx]’, shorttitle=‘EFIATR [loxx]’, format=format.volume, timeframe=“”, timeframe_gaps=true, max_bars_back = 5000)RMA(x, t=>
        EMA1 = x
        EMA1 := na(EMA1[1]) ? x : (x  nz(EMA1[1])) * (1/t+ nz(EMA1[1])
        EMA1EMA(x, t=>
        EMA1 = x
        EMA1 := na(EMA1[1]) ? x : (x  nz(EMA1[1])) * (2 / (t + 1)) + nz(EMA1[1])
        EMA1
        
    _bpDom(len, bpw, mult=>
        HP = 0.0
        BP = 0.0
        Peak = 0.0
        Real = 0.0
        counter = 0.0
        DC = 0.0
        alpha2 = (math.cos(0.25 * bpw * 2 * math.pi / len+ math.sin(0.25 * bpw * 2 * math.pi  / len 1/ math.cos(0.25 * bpw * 2 * math.pi / len)
        HP := (1 + alpha2 / 2* (close  nz(close[1])) + (1  alpha2* nz(HP[1])
        beta1 = math.cos(2 * math.pi / len)
        gamma1 = 1 / math.cos(2 *  math.pi * bpw / len)
        alpha1 = gamma1  math.sqrt(gamma1 * gamma1  1)
        BP := 0.5 * (1  alpha1* (HP  nz(HP[2])) + beta1 * (1 + alpha1* nz(BP[1])  alpha1 * nz(BP[2])
        BP := bar_index == 1 or bar_index == 2  ? 0 : BP
        Peak := 0.991 * Peak
        Peak := math.abs(BP> Peak ? math.abs(BP: Peak
        Real := Peak != 0 ?  BP / Peak : Real
        DC := nz(DC[1])
        DC := DC < 6 ? 6 : DC
        counter := counter[1+ 1
        if ta.crossover(Real, 0or ta.crossunder(Real, 0)
            DC := 2 * counter
            if 2 * counter > 1.25 * nz(DC[1])
                DC := 1.25 * DC[1]
            if 2 * counter < 0.8 * nz(DC[1])
                DC := 0.8 * nz(DC[1])
            counter := 0
        temp_out = mult * DC
        temp_out

    //inputs

    src = input.source(close, title = “Source”, group = “Basic Settings”)
    calc_type = input.string(“Fixed”, title = “Calculation Type”, options =[“Fixed”, “Band-pass Dominant Cycle”], group = “Basic Settings”)

    len =   input.int(13, title = “Fixed EFI Period”, group = “Fixed Settings”)
    slen =  input.int(21, title=‘Fixed Signal Period’, group = “Fixed Settings”)
    atr_sm =  input.int(21, title =“Fixed ATR Smoothing Length”, group = “Fixed Settings”)

    bp_period = input.int(13, “Band-pass Period”, minval = 1, group = “Band-pass”)
    bp_width = input.float(0.20, “Band-pass Width”, step = 0.1, group = “Band-pass”)
    cycle_len = input.float(100, “Signal and ATR Percent of Dominant Cycle (%)”, step = 1.0, group = “Band-pass”)/100
    efi_reduction = input.float(75, “EFI Percent of Dominant Cycle (%) “, step = 1.0, group = “Band-pass”)/100

    len_out_fast = int(nz(_bpDom(bp_period, bp_width, efi_reduction), 1)) < 1 ? 1 : int(nz(_bpDom(bp_period, bp_width, efi_reduction), 1))
    len_out_slow = int(nz(_bpDom(bp_period, bp_width, cycle_len), 1)) < 1 ? 1 : int(nz(_bpDom(bp_period, bp_width, cycle_len), 1))

    atr_mult1 = input.int(1, title = “ATR Mult Level 1”, group = “ATR Multipliers”)
    atr_mult2 = input.int(2, title = “ATR Mult Level 2”, group = “ATR Multipliers”)
    atr_mult3 = input.int(3, title = “ATR Mult Level 3”, group = “ATR Multipliers”)

    trunc_atr = input.bool(true, title = “Truncate over ATR Mult Level 4?”, group = “UI Options”)

    //core calc
    efi = EMA(ta.change(close* volume, calc_type == “Fixed” ? len : len_out_fast)
    sig = EMA(efi, calc_type == “Fixed” ? len : len_out_slow)
    atr_ema = math.abs(efi[1 efi)
    atr_out =  RMA(atr_ema, calc_type == “Fixed” ? len : len_out_slow

    //atr channel calc
    atr_high1 = sig + atr_out * atr_mult1
    atr_low1 = sig  atr_out * atr_mult1

    atr_high2= sig + atr_out * atr_mult2
    atr_low2 = sig  atr_out * atr_mult2

    atr_high3 = sig + atr_out * atr_mult3
    atr_low3 = sig  atr_out * atr_mult3

    atr_obhigh = sig + atr_out * (atr_mult3 + 1)
    atr_oblow = sig  atr_out * (atr_mult3 + 1)

    efi_out  = trunc_atr ? efi > atr_obhigh ? atr_high3 : efi < atr_oblow ? atr_low3 : efi : efi

    //plot atr channels
    plot(atr_high1, color = bar_index % 2 == 0 ? na : color.new(color.gray, 30), linewidth = 1, title = “ATR1 High”)
    plot(atr_high2, color = bar_index % 4 == 0 ? na : color.new(color.gray, 30), linewidth = 1, title = “ATR2 High”)
    plot(atr_high3, color = color.new(color.gray, 30), linewidth = 2, title = “ATR3 High”)

    plot(atr_low1, color = bar_index % 2 == 0 ? na : color.new(color.gray, 30), linewidth = 1, title = “ATR1 Low”)
    plot(atr_low2, color = bar_index % 4 == 0 ? na : color.new(color.gray, 30), linewidth = 1, title = “ATR2 Low”)
    plot(atr_low3, color = color.new(color.gray, 30), linewidth = 2, title = “ATR3 Low”)

    //plot main
    plot(0, color=color.gray, style = plot.style_circles, title=‘Zero Line’, linewidth = 2)
    plot(sig, color=color.new(color.white, 0), title=‘Signal’, linewidth = 2)
    plot(efi_out, color = #4f6cdf, title=‘EFI’, linewidth = 2)

    //plot shapes
    plot(efi_out >= atr_high3 ? efi_out : na, style = plot.style_circles, linewidth = 3, color = #D2042D, title = “Over ATR4 High”)
    plot(efi_out <= atr_low3 ? efi_out : na, style = plot.style_circles, linewidth = 3, color = #2DD204, title = “Over ATR4 Low”)

    #237783 quote
    Iván González
    Moderator
    Master

    Eccolo qui:

    //-----------------------------------------//
    //PRC_Elder Force index
    //version = 0
    //18.09.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-----------------------------------------//
    //-----Inputs------------------------------//
    //-----------------------------------------//
    src=close
    calcType=1 //Boolean//1=Fixed 0=Band-pass Dominant Cycle
    len=13 //Fixed EFI Period
    slen=21 //Fixed Signal Period
    atrM=21 //Fixed ATR Smoothing Length
    
    bpPeriod=13 //Band-pass period
    bpWidth=0.20 //Band-pass Width
    cycleLen=100/100 //Signal and ATR percent of dominant cycle (%)
    efireduction=75/100 //EFI percent of dominat cycle (%)
    
    atrMult1=1
    atrMult2=2
    atrMult3=3
    
    truncAtr=1 //truncate over ATR Mult Level 4?
    //-----------------------------------------//
    //--Length Out calculation Band-pass type--//
    //-----------------------------------------//
    peak=0
    real=0
    counter=0
    dc=0
    alpha2=(cos(0.25*bpWidth*2*180/bpPeriod)+sin(0.25*bpWidth*2*180/bpPeriod)-1)/cos(0.25*bpWidth*2*180/bpPeriod)
    if barindex<=1 then
    hp=0
    else
    hp=(1+alpha2/2)*(close-close[1])+(1-alpha2)*hp[1]
    endif
    beta1=cos(2*180/bpPeriod)
    gamma1=1/cos(2*180*bpWidth/bpPeriod)
    alpha1=gamma1-sqrt(gamma1*gamma1-1)
    if barindex<=2 then
    bp=0
    else
    bp=0.5*(1-alpha1)*(hp-hp[2])+beta1*(1+alpha1)*bp[1]-alpha1*bp[2]
    endif
    peak=0.991*peak
    if abs(bp)>peak then
    peak=abs(bp)
    else
    peak=peak
    endif
    if peak<>0 then
    real=bp/peak
    else
    real=real
    endif
    
    if dc<6 then
    dc=6
    else
    dc=dc
    endif
    counter=counter+1
    if real crosses over 0 or real crosses under 0 then
    dc=2*counter
    if 2*counter>1.25*dc[1] then
    dc=1.25*dc[1]
    elsif 2*counter<0.8*dc[1] then
    dc=0.8*dc[1]
    endif
    counter=0
    endif
    tempoutFast=efireduction*dc
    tempoutSlow=cycleLen*dc
    
    if tempoutFast<1 then
    lenOutFast=1 
    else
    lenOutFast=round(tempoutFast)
    endif
    if tempoutSlow<1 then
    lenOutSlow=1
    else
    lenOutSlow=round(tempoutSlow)
    endif
    //-----------------------------------------//
    //-----EFI and Signal Calculation----------//
    //-----------------------------------------//
    if calcType=1 then
    efi=average[len,1]((close-close[1])*volume)
    sig=average[len,1](efi)
    length=len
    else
    efi=average[lenOutFast,1]((close-close[1])*volume)
    sig=average[lenOutSlow,1](efi)
    length=lenOutSlow
    endif
    
    atrEMA=abs(efi[1]-efi)
    
    src1 = atrEMA
    alpha = 1/length
    if barindex = 2*length then
    atrOUT = average[length](src1)
    else
    atrOUT = alpha*src1 + (1-alpha)*atrOUT[1]
    endif
    //-----------------------------------------//
    //-----ATR Channel Calculation-------------//
    //-----------------------------------------//
    atrHigh1=sig+atrOut*atrMult1
    atrHigh2=sig+atrOut*atrMult2
    atrHigh3=sig+atrOut*atrMult3
    
    atrLow1=sig-atrOut*atrMult1
    atrLow2=sig-atrOut*atrMult2
    atrLow3=sig-atrOut*atrMult3
    
    atrObHigh=sig+atrOut*(atrMult3+1)
    atrObLow=sig-atrOut*(atrMult3+1)
    
    if truncAtr then
    if efi>atrObHigh then
    efiOut=atrHigh3
    else
    if efi<atrOblow then
    efiOut=atrLow3
    else
    efiOut=efi
    endif
    endif
    else
    efiOut=efi
    endif
    //-----------------------------------------//
    //-----Plot shapes-------------------------//
    //-----------------------------------------//
    if efiOut>=atrHigh3 then
    drawpoint(barindex,efiOut,3)coloured(210,4,45)
    elsif efiout<=atrLow3 then
    drawpoint(barindex,efiOut,3)coloured(45,210,4)
    endif
    //-----------------------------------------//
    //-----------------------------------------//
    //-----------------------------------------//
    return efiOut as "EFI" coloured("blue")style(line,2), sig as "Signal" coloured("orange")style(line,2), 0 as "zero"style(dottedline,2)coloured("grey"), atrHigh1 as "ATR1 high"coloured("grey")style(dottedline,1), atrHigh2 as "ATR2 high"coloured("grey")style(dottedline2,1), atrHigh3 as "ATR3 high"coloured("grey")style(line,2), atrLow1 as "ATR1 low"coloured("grey")style(dottedline,1),atrLow2 as "ATR2 low"coloured("grey")style(dottedline2,1),atrLow3 as "ATR3 low"coloured("grey")style(line,2)
    
    Alera15 thanked this post
    #237786 quote
    Alera15
    Participant
    New

    ¡Es perfecto! ¡Eres mi nuevo héroe! ¡Muchísimas gracias por la conversión, por la rapidez y hasta pronto!

    È perfetto! Sei il mio nuovo eroe! Grazie mille per la conversione, per la velocità e a presto!

    #237790 quote
    robertogozzi
    Moderator
    Master

    @Alera15

    Hai iniziato usando l’Inglese ed hai finito con lo Spagnolo, pur avendo scelto il forum Italiano!

    Per  favore, non rispondere cercando di usare la lingua dell’interlocutore, né l’Inglese per forza. Usa SOLO la lingua del forum prescelto.

    Grazie 🙂

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

Conversion Force Index with ATR from TradingView


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
Alera15 @alera15 Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by robertogozzi
1 year, 4 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 09/18/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...