PRC_ Variable Moving Average

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #212689 quote
    Mary
    Participant
    Average

    Hello,

    The indicator  PRC_Variable Moving Average,

    I can plot as a line in two colors, Green for Positive, and Red for Negative but when I try to plot this indicator as a Histogram, it only appears in Green for both Positive and Negative although the Red option is available, its not working. Can you please help with code so that it can plot as both Green for Positive, and Red for Negative as a Histogram.

    Thank you in advance.

    See code and images below:

    //PRC_Variable Moving Average | indicator
    //14.12.2016
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //converted and adapted from Pinescript version
    
    // --- parameters
    src=customclose
    //l = 6
    
    if barindex>l then
    k = 1.0/l
    pdm = max((src - src[1]), 0)
    mdm = max((src[1] - src), 0)
    pdmS = ((1 - k)*(pdmS[1]) + k*pdm)
    mdmS = ((1 - k)*(mdmS[1]) + k*mdm)
    s = pdmS + mdmS
    pdi = pdmS/s
    mdi = mdmS/s
    pdiS = ((1 - k)*(pdiS[1]) + k*pdi)
    mdiS = ((1 - k)*(mdiS[1]) + k*mdi)
    d = abs(pdiS - mdiS)
    s1 = pdiS + mdiS
    iS = ((1 - k)*(iS[1]) + k*d/s1)
    hhv = highest[l](iS)
    llv = lowest[l](iS)
    d1 = hhv - llv
    vI = (iS - llv)/d1
    vma = (1 - k*vI)*(vma[1]) + k*vI*src
    endif
    
    RETURN VMA
    #212697 quote
    JS
    Participant
    Senior

    Hi,

    I adjusted the code slightly and incorporated the colors into the indicator by default…

    //PRC_Variable Moving Average | indicator
    //14.12.2016
    //Nicolas @ http://www.prorealcode.com
    //Sharing ProRealTime knowledge
    //converted and adapted from Pinescript version
    
    // — parameters
    src=customclose
    l = 6
    
    if barindex>l then
    k = 1.0/l
    pdm = max((src - src[1]), 0)
    mdm = max((src[1] - src), 0)
    pdmS = ((1 - k)*(pdmS[1]) + k*pdm)
    mdmS = ((1 - k)*(mdmS[1]) + k*mdm)
    s = pdmS + mdmS
    pdi = pdmS/s
    mdi = mdmS/s
    pdiS = ((1 - k)*(pdiS[1]) + k*pdi)
    mdiS = ((1 - k)*(mdiS[1]) + k*mdi)
    d = abs(pdiS - mdiS)
    s1 = pdiS + mdiS
    iS = ((1 - k)*(iS[1]) + k*d/s1)
    hhv = highest[l](iS)
    llv = lowest[l](iS)
    d1 = hhv - llv
    vI = (iS - llv)/d1
    vma = (1 - k*vI)*(vma[1]) + k*vI*src
    endif
    
    If vma < vma[1] then
    R=255
    G=0
    B=0
    Else
    R=0
    G=255
    B=0
    EndIf
    
    RETURN VMA Coloured(R,G,B)
    Mary thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

PRC_ Variable Moving Average


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Mary @mila Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by JS
2 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/03/2023
Status: Active
Attachments: 3 files
Logo Logo
Loading...