conversion code tradingwiew ” Redk VADER V4.0″

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

    Bonjour à tous,
    Une ame charitable pour traduire ce code tradingwiew.
    Merci

    // © RedKTrader
    
    //@version=5
    indicator('RedK Volume-Accelerated Directional Energy Ratio', 'RedK VADER v4.0', precision=0, timeframe='', timeframe_gaps=false)
    
    // ***********************************************************************************************************
    // Choose MA type for the base DER calculation .. 
    // WMA is my preference and is default .. SMA is really slow and lags a lot - but added for comparison
    f_derma(_data, _len, MAOption) =>
        value = 
          MAOption == 'SMA' ? ta.sma(_data, _len) :
          MAOption == 'EMA' ? ta.ema(_data, _len) :
          ta.wma(_data, _len)
    // ***********************************************************************************************************
    
    
    // ===========================================================================================================
    //      Inputs
    // ===========================================================================================================
    
    price   = close
    length  = input.int(10, minval=1)
    DER_avg = input.int(5, 'Average', minval=1, inline='DER', group='Directional Energy Ratio')
    MA_Type = input.string('WMA', 'DER MA type', options=['WMA', 'EMA', 'SMA'], inline='DER', group='Directional Energy Ratio') 
    smooth  = input.int(3, 'Smooth', minval=1,  inline='DER_1', group='Directional Energy Ratio')
    
    show_senti = input.bool(false, 'Sentiment',  inline='DER_s', group='Directional Energy Ratio')
    senti   = input.int(20, 'Length', minval=1, inline='DER_s', group='Directional Energy Ratio')
    
    
    v_calc  = input.string('Relative', 'Calculation', options=['Relative', 'Full', 'None'], group='Volume Parameters')
    vlookbk = input.int(20, 'Lookback (for Relative)', minval=1,                            group='Volume Parameters')
    
    // ===========================================================================================================
    //          Calculations
    // ===========================================================================================================
    
    // Volume Calculation Option  -- will revert to no volume acceleration for instruments with no volume data
    // v4.0 => updated Relative Volume calculation fix per @m_b_round
    
    v = volume
    
    vola    = 
      v_calc == 'None' or na(volume) ? 1 : 
      v_calc == 'Relative' ?   ta.stoch(v, v, v, vlookbk) / 100 : 
      v
    
    R       = (ta.highest(2) - ta.lowest(2)) / 2                    // R is the 2-bar average bar range - this method accomodates bar gaps
    sr      = ta.change(price) / R                                  // calc ratio of change to R
    rsr     = math.max(math.min(sr, 1), -1)                         // ensure ratio is restricted to +1/-1 in case of big moves
    c       = fixnan(rsr * vola)                                    // add volume accel -- fixnan adresses cases where no price change between bars
    
    c_plus  = math.max(c, 0)                                        // calc directional vol-accel energy
    c_minus = -math.min(c, 0)
    
    // plot(c_plus)
    // plot(c_minus)
    
    
    avg_vola    = f_derma(vola, length, MA_Type)
    dem         = f_derma(c_plus, length, MA_Type)  / avg_vola          // directional energy ratio
    sup         = f_derma(c_minus, length, MA_Type) / avg_vola
    
    adp         = 100 * ta.wma(dem, DER_avg)                            // average DER
    asp         = 100 * ta.wma(sup, DER_avg)
    anp         = adp - asp                                             // net DER..
    anp_s       = ta.wma(anp, smooth)
    
    // Calculate Sentiment - a VADER for a longer period and can act as a baseline (compared to a static 0 value)
    // note we're not re-calculating vol_avg, demand or supply energy for sentiment. this would've been a different approach
    s_adp       = 100 * ta.wma(dem, senti)                            // average DER for sentiment length
    s_asp       = 100 * ta.wma(sup, senti)
    V_senti     = ta.wma(s_adp - s_asp, smooth)
    
    
    // ===========================================================================================================
    //      Colors & plots
    // ===========================================================================================================
    c_adp   = color.new(color.aqua, 30)
    c_asp   = color.new(color.orange, 30)
    c_fd    = color.new(color.green, 80)
    c_fs    = color.new(color.red, 80)
    c_zero  = color.new(#ffee00, 70)
    
    c_up    = color.new(#359bfc, 0)
    c_dn    = color.new(#f57f17, 0)
    
    c_sup   = color.new(#33ff00, 80)
    c_sdn   = color.new(#ff1111, 80)
    up      = anp_s >= 0
    s_up    = V_senti >=0 
    
    hline(0, 'Zero Line', c_zero, hline.style_solid)
    
    // =============================================================================
    // v3.0 --- Sentiment will be represented as a 4-color histogram
    c_grow_above = #1b5e2080 
    c_grow_below = #dc4c4a80
    c_fall_above = #66bb6a80  
    c_fall_below = #ef8e9880     
    
    sflag_up = math.abs(V_senti) >= math.abs(V_senti[1])
    
    plot(show_senti ? V_senti : na, "Sentiment", style=plot.style_columns, 
     color = s_up ? (sflag_up ? c_grow_above : c_fall_above) : 
     sflag_up ? c_grow_below : c_fall_below) 
    // =============================================================================
    
    s = plot(asp, 'Supply Energy', c_asp, 2, style=plot.style_circles,  join=true)
    d = plot(adp, 'Demand Energy', c_adp, 2, style=plot.style_cross,    join=true)
    fill(d, s, adp > asp ? c_fd : c_fs)
    
    plot(anp, 'VADER', color.new(color.gray, 30), display=display.none)
    plot(anp_s, 'Signal', up ? c_up : c_dn, 4)
    
    // ===========================================================================================================
    //      v2.0 adding alerts 
    // ===========================================================================================================
    
    Alert_up    = ta.crossover(anp_s,0)
    Alert_dn    = ta.crossunder(anp_s,0)
    Alert_swing = ta.cross(anp_s,0)
    
    // "." in alert title for the alerts to show in the right order up/down/swing 
    alertcondition(Alert_up,    ".   VADER Crossing 0 Up",      "VADER Up - Buying Energy Detected!")
    alertcondition(Alert_dn,    "..  VADER Crossing 0 Down",    "VADER Down - Selling Energy Detected!")
    alertcondition(Alert_swing, "... VADER Crossing 0",         "VADER Swing - Possible Reversal")
    
    // ===========================================================================================================
    //      v3.0 more alerts for VADER crossing Sentiment
    // ===========================================================================================================
    
    v_speedup = ta.crossover(anp_s, V_senti)
    v_slowdn  = ta.crossunder(anp_s, V_senti)
    alertcondition(v_speedup,   "*  VADER Speeding Up",      "VADER Speeding Up!")
    alertcondition(v_slowdn,    "** VADER Slowing Down",    "VADER Slowing Down!")
    #245915 quote
    Iván González
    Moderator
    Legend

    Bonjour. Ici vous avez :

    //--------------------------------------------//
    //PRC_Volume Accelerated Directional Energy Ratio
    //version = 0
    //15.04.25
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------//
    // Inputs
    //--------------------------------------------//
    src=close
    length=10
    deravg=5
    matype=2
    smooth=3
    showsenti=1
    senti=20
    vcalc=1 //1=Relative, 2=full, 0=none
    vlookback=20
    //--------------------------------------------//
    // Calculations
    //--------------------------------------------//
    v=volume
    if vcalc=0 then
       vola=1
    elsif vcalc=1 then
       vola=(v-lowest[length](v))/(highest[length](v)-lowest[length](v))
    else
       vola=v
    endif
    r=(highest[2](high)-lowest[2](low))/2
    sr=(src-src[1])/r
    rsr=max(min(sr,1),-1)
    c=rsr*vola
    cplus=max(c,0)
    cminus=-min(c,0)
    
    avgvola=average[length,matype](vola)
    dem=average[length,matype](cplus)/avgvola
    sup=average[length,matype](cminus)/avgvola
    
    adp=100*average[deravg,2](dem)
    asp=100*average[deravg,2](sup)
    anp=adp-asp
    anps=average[smooth,2](anp)
    
    sadp=100*average[senti,2](dem)
    sasp=100*average[senti,2](sup)
    vsenti=average[smooth,2](sadp-sasp)
    //--------------------------------------------//
    // Colors and plot
    //--------------------------------------------//
    if vsenti>=0 then
       if abs(vsenti)>=abs(vsenti[1]) then
          red=27
          green=94
          blue=32
          alpha=100
       else
          red=107
          green=187
          blue=106
          alpha=100
       endif
    else
       if abs(vsenti)>=abs(vsenti[1]) then
          red=220
          green=76
          blue=74
          alpha=100
       else
          red=239
          green=142
          blue=152
          alpha=100
       endif
    endif
    if showsenti then
       plotsenti=vsenti
    else
       plotsenti=undefined
    endif
    
    if asp>adp then
       r1=255
       g1=0
       b1=0
    else
       r1=0
       g1=255
       b1=0
    endif
    colorbetween(asp,adp,r1,g1,b1,50)
    
    if anps>0 then
       r3=64
       g3=112
       b3=255
       
    else
       r3=255
       g3=143
       b3=53
       
    endif
    //--------------------------------------------//
    return anps coloured(r3,g3,b3)style(line,4),asp coloured("orange")style(line,2),adp coloured("aqua")style(line,2),0 as "Zero" coloured("yellow"), plotsenti as "Sentiment" style(histogram)coloured(red,green,blue,alpha)
    
    #245919 quote
    larouedegann
    Participant
    Master

    merci ivan

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

conversion code tradingwiew ” Redk VADER V4.0″


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
Summary

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

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 04/11/2025
Status: Active
Attachments: No files
Logo Logo
Loading...