Directional Movement Change

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #20034 quote
    Johan
    Participant
    Average

    I want to make a indicator that calculates the change of Directional Movement (DI) in current bar, compared to last bar.

    Say the last bar has a value of 20 and the current bar has a value of 10. The change would then be = 100%.

    Say the last bar has a value of -10 and the current bar has a value of 30. The change would then be = 400%.

    Say the last bar has a value of 15 and the current bar has a value of -15. The change would then be = 200%.

    This is some what easy to do. But the problem i face is when a bar has a value that starts with 0. Or when there’s a negative value on either side.

    My code

    volaDI = di[14](close)
    volaDIchange = ((volaDI - volaDI[1]) / volaDI[1]) * 100
    
    #20035 quote
    Johan
    Participant
    Average

    It’s not necessary to calculate it so it displays exactly like the example above. What i want is a indicator that shows the strength of the change.

    #20062 quote
    Nicolas
    Keymaster
    Master

    Hey Johan, you are reinventing the wheel. You can use the Rate Of Change (ROC) to compare the change between the current value and one of the past. In your case, you only want to compare the actual one to the previous one, so the ROC period should be set to 1 and your code should now look like this:

    volaDI = di[14](close)
    //volaDIchange = ((volaDI - volaDI[1]) / volaDI[1]) * 100
    volaDIchange = abs(ROC[1](volaDI)-volaDI[1])
    
    return volaDIchange

    Please tell me if I’m totally wrong, it’s Friday coding 🙂

    #20075 quote
    Johan
    Participant
    Average

    Thanks Nicolas. Looks like this is the way to go. But still, get’s huge spikes when there’s a zero value involved. This becomes nasty noise when there’s a small rate of change in price action but the DI value flips side. See my attached image. If you look to the right, the ROC of the last green and the first red bar should have the spike. Does this make any sense? 🙂

    #20083 quote
    Johan
    Participant
    Average

    Made some changes to get rid of the zero value.

    volaDI = di[14](close)
    volaDIround = round(volaDI)
    
    if (volaDIround = 0) then
    volaDIround = sgn(volaDIround)
    endif
    
    volaDIroc = abs(roc[1](volaDIround))
    
    return volaDIroc

    But what i don’t understand is how the ROC work. If i draw two rulers between the values of the one that i can see has the most ROC (distance) and the one where the indicator spikes. You can clearly see the it don’t correspond to the distance of the DI move. See image…

    #20086 quote
    Johan
    Participant
    Average

    OK. The ruler drawing was a good thing to do 🙂  I think i found the solution.

    volaDI = di[14](close)
    volaDIroc = abs(volaDI - volaDI[1])
    
    return volaDIroc 
    Nicolas thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Directional Movement Change


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Johan @johan_holmberg Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Johan
9 years, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/06/2017
Status: Active
Attachments: No files
Logo Logo
Loading...