add divergence to indicator

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #197715 quote
    ullle73
    Participant
    Senior

    A while ago i found this indicator, looked everywhere for this with a divergence. Is it possible to get help adding it? 🙂

     

    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
    #199904 quote
    robertogozzi
    Moderator
    Master

    Try this one (add it to your chart, like MACD, then set it to be plotted as a histogram):

    //DEFPARAM CalculateOnLastBars = 5000
    //ONCE Periods = 50
    srcH = high   //or CLOSE
    srcL = low    //or CLOSE
    // indicator BEGINNING
    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)
    Cmax = max(cumdelta, cumdelta[1])
    Cmin = min(cumdelta, cumdelta[1])
    // indicator END
    //
    IF BarIndex > Periods THEN
    Diverg = 0
    HHbar = HighestBars[Periods](srcH[1])
    LLbar = lowestBars[Periods](srcL[1])
    // BULLISH divergence
    IF high[HHbar] > high THEN
    IF Cmax[HHbar] <= Cmax THEN
    Diverg = 1
    ENDIF
    ENDIF
    //
    // BEARISH divergence
    IF low[HHbar] < low THEN
    IF Cmin[HHbar] >= Cmin THEN
    Diverg = -1
    ENDIF
    ENDIF
    //
    ENDIF
    x = Diverg
    IF Diverg = Diverg[1] THEN
    x = 0
    ENDIF
    return x AS "Divergence",0 AS "Zero"
    Nicolas thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

add divergence to indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ullle73 @jonas_rydqvist Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
3 years, 5 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/22/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...