Conversion of Delta Volume

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #196370 quote
    Khaled
    Participant
    Veteran

    Can anyone help converting the code below ? Thanks

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © LonesomeTheBlue

    //@version=4
    study(“Cumulative Delta Volume”, “CDV”)
    linestyle = input(defval = ‘Candle’, title = “Style”, options = [‘Candle’, ‘Line’])
    hacandle = input(defval = true, title = “Heikin Ashi Candles?”)
    showma1 = input(defval = false, title = “SMA 1”, inline = “ma1”)
    ma1len = input(defval = 50, title = “”, minval = 1, inline = “ma1”)
    ma1col = input(defval = color.lime, title = “”, inline = “ma1”)
    showma2 = input(defval = false, title = “SMA 2”, inline = “ma2”)
    ma2len = input(defval = 200, title = “”, minval = 1, inline = “ma2”)
    ma2col = input(defval = color.red, title = “”, inline = “ma2”)
    showema1 = input(defval = false, title = “EMA 1”, inline = “ema1”)
    ema1len = input(defval = 50, title = “”, minval = 1, inline = “ema1”)
    ema1col = input(defval = color.lime, title = “”, inline = “ema1”)
    showema2 = input(defval = false, title = “EMA 2”, inline = “ema2”)
    ema2len = input(defval = 200, title = “”, minval = 1, inline = “ema2”)
    ema2col = input(defval = color.red, title = “”, inline = “ema2”)
    colorup = input(defval = color.lime, title = “Body”, inline = “bcol”)
    colordown = input(defval = color.red, title = “”, inline = “bcol”)
    bcolup = input(defval = #74e05e, title = “Border”, inline = “bocol”)
    bcoldown = input(defval = #ffad7d, title = “”, inline = “bocol”)
    wcolup = input(defval = #b5b5b8, title = “Wicks”, inline = “wcol”)
    wcoldown = input(defval = #b5b5b8, title = “”, inline = “wcol”)

    tw = high – max(open, close)
    bw = min(open, close) – low
    body = abs(close – open)

    _rate(cond) =>
    ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body)
    ret := nz(ret) == 0 ? 0.5 : ret
    ret

    deltaup = volume * _rate(open <= close)
    deltadown = volume * _rate(open > close)
    delta = close >= open ? deltaup : -deltadown
    cumdelta = cum(delta)
    float ctl = na
    float o = na
    float h = na
    float l = na
    float c = na
    if linestyle == ‘Candle’
    o := cumdelta[1]
    h := max(cumdelta, cumdelta[1])
    l := min(cumdelta, cumdelta[1])
    c := cumdelta
    ctl
    else
    ctl := cumdelta

    plot(ctl, title = “CDV Line”, color = color.blue, linewidth = 2)

    float haclose = na
    float haopen = na
    float hahigh = na
    float halow = na
    haclose := (o + h + l + c) / 4
    haopen := na(haopen[1]) ? (o + c) / 2 : (haopen[1] + haclose[1]) / 2
    hahigh := max(h, max(haopen, haclose))
    halow := min(l, min(haopen, haclose))

    c_ = hacandle ? haclose : c
    o_ = hacandle ? haopen : o
    h_ = hacandle ? hahigh : h
    l_ = hacandle ? halow : l

    plotcandle(o_, h_, l_, c_, title=’CDV Candles’, color = o_ <= c_ ? colorup : colordown, bordercolor = o_ <= c_ ? bcolup : bcoldown, wickcolor = o_ <= c_ ? bcolup : bcoldown)

    plot(showma1 and linestyle == “Candle” ? sma(c_, ma1len) : na, title = “SMA 1”, color = ma1col)
    plot(showma2 and linestyle == “Candle” ? sma(c_, ma2len) : na, title = “SMA 2”, color = ma2col)
    plot(showema1 and linestyle == “Candle” ? ema(c_, ema1len) : na, title = “EMA 1”, color = ema1col)
    plot(showema2 and linestyle == “Candle” ? ema(c_, ema2len) : na, title = “EMA 2”, color = ema2col)

    #196372 quote
    Khaled
    Participant
    Veteran

    if it’s too long, can you please convert only the following part? Thanks a lot!

     

    _rate(cond) =>
    ret = 0.5 * (tw + bw + (cond ? 2 * body : 0)) / (tw + bw + body)
    ret := nz(ret) == 0 ? 0.5 : ret
    ret

    deltaup = volume * _rate(open <= close)
    deltadown = volume * _rate(open > close)
    delta = close >= open ? deltaup : -deltadown
    cumdelta = cum(delta)
    float ctl = na
    float o = na
    float h = na
    float l = na
    float c = na
    if linestyle == ‘Candle’
    o := cumdelta[1]
    h := max(cumdelta, cumdelta[1])
    l := min(cumdelta, cumdelta[1])
    c := cumdelta
    ctl
    else
    ctl := cumdelta

    plot(ctl, title = “CDV Line”, color = color.blue, linewidth = 2)

    #196377 quote
    Nicolas
    Keymaster
    Legend

    Please post screenshots of how it looks, it fastened the comprehension of the code and its translation.

    Khaled thanked this post
    #196378 quote
    Khaled
    Participant
    Veteran

    Please see image below. Thanks

    Cumulative-Delta.png Cumulative-Delta.png
    #196884 quote
    EZolla
    Participant
    New

    Pretty close, without the HH candles:

    var
    ctl,
    o, h , l, c, tw,
    body, rateup, ratedown, ku, kd, bw, k2,
    deltaup, deltadown, cumdelta, deltaa: float;

    begin
    tw := high – f_max(open, close) ;
    bw := f_min(open, close) – low ;
    body := abs(close – open) ;

    if open <= close then ku := 2*body
    else ku:=0;
    rateup := 0.5 * (tw + bw + ku) / (tw + bw + body) ;
    if rateup = 0 then rateup := 0.5
    else rateup:=rateup;

    if open > close then kd := 2*body
    else kd:=0;
    ratedown := 0.5 * (tw + bw + kd) / (tw + bw + body) ;
    if ratedown = 0 then ratedown:= 0.5 else ratedown:=ratedown;

    deltaup := quantity * rateup ;
    deltadown := quantity * ratedown ;
    if close >= open then deltaa := deltaup
    else deltaa := -deltadown;
    cumdelta := cum(deltaa);
    ctl := F_Smoother( cumdelta);

    plot(ctl);
    end

    #196892 quote
    Nicolas
    Keymaster
    Legend

    Here is a code translated from different versions you shared in the thread for the Cumulative Volume Delta:

    tw = high - max(open, close)
    bw = min(open, close) - low
    body = abs(close - open)
    
    if open<=close then 
    deltaup = 0.5 * (tw + bw + (2 * body)) / (tw + bw + body)
    endif
    
    if open > close then 
    deltadown = 0.5 * (tw + bw + (2 * body)) / (tw + bw + body)
    endif 
    
    if close >= open then 
    delta= deltaup 
    else
    delta= -deltadown
    endif
    
    cumdelta = cumsum(delta)
    
    drawcandle(cumdelta[1],max(cumdelta, cumdelta[1]),min(cumdelta, cumdelta[1]),cumdelta)
    return
    cumulative-volume-delta-prorealtime.png cumulative-volume-delta-prorealtime.png
    #196897 quote
    Nicolas
    Keymaster
    Legend

    Sorry there was no volumes in the previous version, correct one is below:

    tw = high - max(open, close)
    bw = min(open, close) - low
    body = abs(close - open)
    
    if volume then 
    if open<=close then
    deltaup = volume*(0.5 * (tw + bw + (2 * body)) / (tw + bw + body))
    endif
    
    if open > close then
    deltadown = volume*(0.5 * (tw + bw + (2 * body)) / (tw + bw + body))
    endif
    endif
    
    if close >= open then
    delta= deltaup
    else
    delta= -deltadown
    endif
    
    cumdelta = cumsum(delta)
    
    drawcandle(cumdelta[1],max(cumdelta, cumdelta[1]),min(cumdelta, cumdelta[1]),cumdelta)
    return
    
    Khaled thanked this post
    #197087 quote
    ullle73
    Participant
    Senior

    nicholas, is it possible to add to this indicator divergence from pice and delta? see pic 🙂

    thanks

    #197088 quote
    ullle73
    Participant
    Senior

    weird, i did attach the picture, but it did not upload, anyway, here it is again:

    div-delta.jpg div-delta.jpg
Viewing 9 posts - 1 through 9 (of 9 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 of Delta Volume


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Khaled @khaled Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by ullle73
4 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/29/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...