MaryParticipant
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
JSParticipant
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)