Help with VIDYA and DARVAS box

Forums ProRealTime English forum ProBuilder support Help with VIDYA and DARVAS box

Viewing 1 post (of 1 total)
  • #177135

    Hi All,

    I’m new to prorealtime and am hoping for someone who can help me translate the following pine script into an indicator that works in PRT

    Many thanks

    NJ

    //@version=4

    study(“VIDYA”, overlay=true)
    src = input(ohlc4, title=”Source”)
    pds = input(6,”Length”)
    fixCMO = input(title=”Fixed CMO Length (9)?”, type=input.bool, defval=false)
    select = input(title=”Calculation Method: CMO/StDev?”, type=input.bool, defval=true)
    boxp = input(5, “Box Length”)

    // Calculate VIDYA
    alpha = 2/(pds+1)

    momm = change(src)
    f1(m) => m >= 0.0 ? m : 0.0
    f2(m) => m >= 0.0 ? 0.0 : -m
    m1 = f1(momm)
    m2 = f2(momm)
    sm1 = fixCMO ? sum(m1, 9) : sum(m1, pds)
    sm2 = fixCMO ? sum(m2, 9) : sum(m2, pds)
    percent(nom, div) => 100 * nom / div
    chandeMO = nz(percent(sm1-sm2, sm1+sm2))
    k= select ? abs(chandeMO)/100 : stdev(src,pds)
    VIDYA=0.0
    VIDYA:= nz(alpha*k*src)+(1-alpha*k)*nz(VIDYA[1])
    col12 = VIDYA > VIDYA[1]
    col32 = VIDYA < VIDYA[1]
    color2 = col12 ? #001AE1 : col32 ? color.red : color.blue
    plot(VIDYA,”VAR”,color2,2)

    alertcondition(cross(VIDYA,VIDYA[1]), title=”Color ALARM!”, message=”VIDYA has changed color!”)

     

    //Calculate Darvas boxex

    LL = lowest(low, boxp)
    k1 = highest(high, boxp)
    k2 = highest(high, boxp – 1)
    k3 = highest(high, boxp – 2)

    NH = valuewhen(high > k1[1], high, 0)
    box1 = k3 < k2
    TopBox = valuewhen(barssince(high > k1[1]) == boxp – 2 and box1, NH, 0)
    BottomBox = valuewhen(barssince(high > k1[1]) == boxp – 2 and box1, LL, 0)

     

    draw_box(left, top, right, bottom) =>
    color = close > top ? color.green : close < bottom ? color.red : color.yellow
    box = box.new(left, top, right, bottom)
    box.set_border_color(box, color)
    box.set_bgcolor(box, color.rgb(color.r(color), color.g(color), color.b(color), 95))
    box

    var Left = 0

    if TopBox == 0 or TopBox != TopBox[1] or BottomBox != BottomBox[1]
    Left := bar_index
    else
    Left := Left[1]

    if TopBox != TopBox[1] or BottomBox != BottomBox[1] or barstate.islast
    draw_box(Left[1], TopBox[1], barstate.islast ? bar_index : bar_index[1], BottomBox[1])

    alertcondition(close > TopBox, “Darvas box break to the upside”, “Darvas box break to the upside”)
    alertcondition(close < BottomBox, “Darvas box break to the downside”, “Darvas box break to the downside”)

    // plot 44 moving average
    len1 = input(44, minval=1, title=”SMA #1″)
    src1 = input(close, title=”SMA Source #1″)
    out1 = sma(src1, len1)
    plot(out1, title=”SMA #1″)

Viewing 1 post (of 1 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login