absolute strenght histogram v2 (trading view)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #230761 quote
    luxrun
    Participant
    Master

    E’ possibile realizzare la traduzione di questo codice trading view? E’ un indicatore e istogramma che combina diverse medie e indicatori insieme, come visibile dalla foto

    //@version=4
    //Original code from alexgrover
    //Modified the value of Price1 and Price2 with SMA period of 1
    //Added additional MA types
    //Modified columns to reflect trend strength or ranging periods

    study(“Absolute Strength Histogram v2 | jh”)

    //—-
    Length = input(9,title=”Period of Evaluation”, type=input.integer)
    Smooth = input(3,title=”Period of Smoothing”, type=input.integer)
    show_histo = input(true, title=”Show Histogam”, type=input.bool)
    //—-
    src = input(close,title=”Source”)
    Mode = input(title=”Indicator Method”, type=input.string, defval=”RSI”, options=[“RSI”, “STOCHASTIC”,”ADX”])
    ma_type = input(title=”MA”, type=input.string, defval=”WMA”, options=[“ALMA”, “EMA”, “WMA”, “SMA”, “SMMA”, “HMA”])
    alma_offset = input(defval=0.85, title=”* Arnaud Legoux (ALMA) Only – Offset Value”, minval=0, step=0.01)
    alma_sigma = input(defval=6, title=”* Arnaud Legoux (ALMA) Only – Sigma Value”, minval=0)

    ma(type, src, len) =>
    float result = 0
    if type==”SMA” // Simple
    result := sma(src, len)
    if type==”EMA” // Exponential
    result := ema(src, len)
    if type==”WMA” // Weighted
    result := wma(src, len)
    if type==”SMMA” // Smoothed
    w = wma(src, len)
    result := na(w[1]) ? sma(src, len) : (w[1] * (len – 1) + src) / len
    if type==”HMA” // Hull
    result := wma(2 * wma(src, len / 2) – wma(src, len), round(sqrt(len)))
    if type==”ALMA” // Arnaud Legoux
    result := alma(src, len, alma_offset, alma_sigma)
    result

    //—-
    Price = src

    //—-
    Price1 = ma(“SMA”,Price,1)
    Price2 = ma(“SMA”,Price[1],1)

    //RSI
    Bulls0 = 0.5*(abs(Price1-Price2)+(Price1-Price2))
    Bears0 = 0.5*(abs(Price1-Price2)-(Price1-Price2))

    //STOCHASTIC
    Bulls1 = Price1 – lowest(Price1,Length)
    Bears1 = highest(Price1,Length) – Price1

    //ADX
    Bulls2 = 0.5*(abs(high-high[1])+(high-high[1]))
    Bears2 = 0.5*(abs(low[1]-low)+(low[1]-low))

    //
    Bulls = Mode == “RSI” ? Bulls0 : Mode == “STOCHASTIC” ? Bulls1 : Bulls2
    Bears = Mode == “RSI” ? Bears0 : Mode == “STOCHASTIC” ? Bears1 : Bears2
    AvgBulls=ma(ma_type,Bulls,Length)
    AvgBears=ma(ma_type,Bears,Length)

    //—-
    SmthBulls=ma(ma_type,AvgBulls,Smooth)
    SmthBears=ma(ma_type,AvgBears,Smooth)

    difference = abs(SmthBulls – SmthBears)

    bull_trend_color = (SmthBulls<SmthBulls[1])?color.lime:color.green
    bear_trend_color = (SmthBears SmthBulls ? ((SmthBears SmthBears ? ((SmthBulls<SmthBulls[1])?color.lime:color.green) : color.gray
    plot(difference, style=plot.style_histogram, linewidth=3, color=show_histo ? difference_color : na, transp=45, title="Strength")

    //—-
    A = plot(SmthBulls,color=bull_trend_color,linewidth=4,transp=0)
    B = plot(SmthBears,color=bear_trend_color,linewidth=4,transp=0)
    //fill(A,B,color=trend==1?color.aqua:color.fuchsia,transp=80)

    immagine_2024-03-30_183146263.png immagine_2024-03-30_183146263.png
    #230837 quote
    Iván González
    Moderator
    Legend

    Ecco il codice:

    //PRC_ABSOLUTE STRENGTH HISTOGRAM
    //version = 0
    //01.04.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    ///////////////////////////////////////////////////////
    //-----Inputs----------------------------------------//
    length = 9 //Period of evaluation
    smooth = 3 //Period of smoothing
    src = customclose
    Mode = 1 //RSI = 1 / Stochastic = 2 / ADX = 3
    Matype = 2 //Moving average Type - WMA by default
    //---------------------------------------------------//
    //-----Bull and Bear Trends calculation-------------//
    if mode = 2 then //Stochastic
    Bulls = src - lowest[length](src)
    Bears = highest[Length](src)-src
    elsif mode = 3 then //ADX
    Bulls = 0.5*(abs(high-high[1])+(high-high[1]))
    Bears = 0.5*(abs(low[1]-low)+(low[1]-low))
    else //RSI
    Bulls = 0.5*(abs(src-src[1])+(src-src[1]))
    Bears = 0.5*(abs(src-src[1])-(src-src[1]))
    endif
    
    avgbulls = average[length,maType](Bulls)
    avgbears = average[length,maType](Bears)
    
    SmthBulls = average[Smooth,maType](avgbulls)
    SmthBears = average[Smooth,maType](avgbears)
    
    difference = abs(SmthBulls-SmthBears)
    //---------------------------------------------------//
    //----Bull trend color------------------------------//
    if SmthBulls < SmthBulls[1] then
    rbull=0
    gbull=230
    bbull=118
    else
    rbull=76
    gbull=175
    bbull=80
    endif
    //----Bear trend color------------------------------//
    if SmthBears < SmthBears[1] then
    rbear=255
    gbear=152
    bbear=0
    else
    rbear=255
    gbear=82
    bbear=82
    endif
    //----Difference color------------------------------//
    if difference > SmthBulls then
    if SmthBears < SmthBears[1] then
    r=255
    g=152
    b=0
    else
    r=255
    g=82
    b=82
    endif
    elsif difference > SmthBears then
    if SmthBulls < SmthBulls[1] then
    r=0
    g=230
    b=118
    else
    r=76
    g=175
    b=80
    endif
    else
    r=120
    g=123
    b=134
    endif
    //---------------------------------------------------//
    return difference as "Strength" coloured(r,g,b)style(histogram,1), SmthBulls as "Bull Trend" coloured(rbull,gbull,bbull)style(line,4), SmthBears as "Bear Trend" coloured(rbear,gbear,bbear)style(line,4)
    
    luxrun thanked this post
    #230853 quote
    luxrun
    Participant
    Master

    Grazie innanzitutto per la traduzione del codice. C’è un unico problema relativo a lenght, che la piattaforma non mi permette di variare, come puoi vedere dalla foto.  Il resto mi sembra ok, ma non potendo variare la lunghezza del periodo è difficile usarlo nei diverso timeframe. Cordiali saluti

    immagine_2024-04-01_183743624.png immagine_2024-04-01_183743624.png
    #230875 quote
    Iván González
    Moderator
    Legend

    Questo perché devi nascondere nel codice le variabili che definisci nella casella di configurazione. Devi nascondere le linee 8,9,11 e 12.

    #230991 quote
    Iván González
    Moderator
    Legend
    #231087 quote
    Msport71
    Participant
    Senior

    Interessante, grazie

Viewing 6 posts - 1 through 6 (of 6 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

absolute strenght histogram v2 (trading view)


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
author-avatar
luxrun @luxrun Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Msport71
2 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 03/30/2024
Status: Active
Attachments: 2 files
Logo Logo
Loading...