DMI indicator DI+ and DI-

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #8064 quote
    deleted190722
    Participant
    New

    Hi,

    I need to create the DI+ and DI- indicators manually because I need to use them in lower TF.

    I need to use DI based on daily candles on a hour time frame.

    Does anyone knows how to build manually the DI+ and DI-?

    (I can after this transform the indicator to work for lower TF)

    Thanks

    david

    #8079 quote
    Nicolas
    Keymaster
    Master

    Hi David, you remember me that someone ask me the same question some days ago. Didn’t have time already to code it. Find the right formula on internet is quiet hard, but here is the metastock one, that can be easily converted:


    ADX Raw

    {MetaStock code written by Equis and published in the Oct99 TASC}

    Periods:= Input(“Enter time periods”,1,100,14);

    PlusDM:= If(HIGH>Ref(HIGH,-1) AND

    LOW>=Ref(LOW,-1), HIGH-Ref(HIGH,-1),

    If(HIGH>Ref(HIGH,-1) AND LOW<Ref(LOW,-1)

    AND HIGH-Ref(HIGH,-1)>Ref(LOW,-1)-LOW,

    HIGH-Ref(HIGH,-1), 0));

    DIPlus:= 100 * Wilders(PlusDM,Periods) /

    ATR(Periods);

    MinusDM:= If(LOW<Ref(LOW,-1) AND

    HIGH<=Ref(HIGH,-1), Ref(LOW,-1)-LOW,

    If(HIGH>Ref(HIGH,-1) AND LOW<Ref(LOW,-1)

    AND HIGH-Ref(HIGH,-1)<Ref(LOW,-1)-LOW,

    Ref(LOW,-1)-LOW, 0));

    DIMinus:= 100 * Wilders(MinusDM,Periods) /

    ATR(Periods);

    DIDif:= Abs(DIPlus – DIMinus);

    DISum:= DIPlus + DIMinus;

    ADXRaw:= 100 * Wilders(DIDif/DISum, Periods);


    That’s a good exercise for your ProBuilder knowledge 🙂

    #8093 quote
    deleted190722
    Participant
    New

    the DI+ and DI- can be calculated in this way:

     

    n=14
    
    plusDM = MAX(DHIGH(0)-DHIGH(1), 0)
    minusDM = MAX(DLOW(1)-DLOW(0), 0)
    
    IF plusDM > minusDM THEN
    minusDM = 0
    ENDIF
    
    IF plusDM < minusDM THEN
    plusDM = 0
    ENDIF
    
    IF plusDM = minusDM THEN
    plusDM = 0
    minusDM = 0
    ENDIF
    
    plusDI = WILDERAVERAGE[n](plusDM)
    minusDI = WILDERAVERAGE[n](minusDM)
    
    Return plusDI, minusDI
    

     

    The problem is how to do the wilderavarage of the PlusDM. It work in daily TF but if I reduce the TF to 1 hours the wilderavarage is done on the previus n Hours and not days…

     

    To do so we have to create also the wilderavarage by ourself…

     

    I am tring but with big fails for the moment…

     

    n=2
    K = 1/n
    y=2/(n+1)
    ONCE Ema=0
    ONCE plusDI=0
    //EMA formula = price today * y + EMA yesterday * (1-y)
    
    
    //Wilder EMA formula = price today * K + EMA yesterday (1-K)
    
    
    FOR i=0 TO n DO
    
    plusDM = MAX(DHIGH(i)-DHIGH(i+1), 0)
    minusDM = MAX(DLOW(i+1)-DLOW(i), 0)
    
    IF plusDM > minusDM THEN
    minusDM = 0
    ENDIF
    
    IF plusDM < minusDM THEN
    plusDM = 0
    ENDIF
    
    IF plusDM = minusDM THEN
    plusDM = 0
    minusDM = 0
    ENDIF
    Ema = PlusDM*y + Ema*(1-y)
    PlusDI=plusDM*k + ema
    
    //Wilder EMA formula = plusDM(0)* K + EMA yesterday (1-K)
    NEXT
    
    //plusDI = WILDERAVERAGE[n](plusDM)
    //minusDI = WILDERAVERAGE[n](minusDM)
    
    Return PlusDI
    
    #8101 quote
    Nicolas
    Keymaster
    Master

    Because you use instruction of daily OHLC! 🙂

    You should replace your code with:

    plusDM = MAX(HIGH(0)-HIGH(1), 0)
    minusDM = MAX(LOW(1)-LOW(0), 0)

    So now you can use the wilderaverage instruction directly and not recode it all.

    Very nice work! BIG APPLAUSE!

    #8102 quote
    Nicolas
    Keymaster
    Master

    Oh sorry, I realize you were looking for the daily values, not the actual timeframe one.

    The big problem here is that your wilderaverage on n period give your result of the n period of the current timeframe.

    #8105 quote
    deleted190722
    Participant
    New

    yes Nicolas… that’s my issue 🙂

     

    The big Applause go to another users… I copied a little from him. but… our work is 99% copy, fix and paste! 🙂

    #8114 quote
    Nicolas
    Keymaster
    Master

    Ok, maybe a trick to calculate correctly the daily values is to only consider to do it only if the current bar is include in a day that is not the same as the previous bar:

    n=14
    
    plusDM = MAX(DHIGH(0)-DHIGH(1), 0)
    minusDM = MAX(DLOW(1)-DLOW(0), 0)
    
    if day[0]<>day[1] then
    IF plusDM > minusDM THEN
    minusDM = 0
    ENDIF
    
    IF plusDM < minusDM THEN
    plusDM = 0
    ENDIF
    
    IF plusDM = minusDM THEN
    plusDM = 0
    minusDM = 0
    ENDIF
    
    plusDI = WILDERAVERAGE[n](plusDM)
    minusDI = WILDERAVERAGE[n](minusDM)
    endif
    
    Return plusDI, minusDI

    But something still wrong in the returned values…

    #14777 quote
    gregoire
    Participant
    Senior

    bonjour

    j essais de modifié le di pour le faire fonctionné avec les valeur de williams R % mais je bloque en tant que débutant, monindicateur me sort bien quelque chose mais rien a voir avec le di de base.

    besoin d un peu d aide merci

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

DMI indicator DI+ and DI-


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by gregoire
9 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/26/2016
Status: Active
Attachments: No files
Logo Logo
Loading...