Hi Robert,
Thanks for the reply. But it looks different than the original one.
Here are the codes from ThinkOrSwim (see the attached chart):
input length = 30;
input emaLength = 3;
input averageLength = 30;
input factor = 0.1;
input criticalValue = 10;
input averageType = AverageType.EXPONENTIAL;
def atr = WildersAverage(TrueRange(high, close, low), length);
def diff = hlc3 – hlc3[1];
def vp = Sum(if diff > factor * atr then volume else 0, length);
def vn = Sum(if diff < -factor * atr then volume else 0, length);
plot VPN = ExpAverage(100 * (vp – vn) / Sum(volume, length), emaLength);
plot VPNAvg = MovingAverage(averageType, VPN, averageLength);
plot CriticalLevel = criticalValue;
And here are my ProRealTime code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
length = 30
emaLength = 3
averageLength = 30
factor = 0.1
criticalValue = 10
src = customclose
//src = close
MyTR = max (Range ,max (abs (high - src[ 1 ] ),abs (low - src[ 1 ] )))
IF BarIndex < length THEN
MyATR = MyTR
ELSE
MyATR = ((MyATR[ 1 ] * (length - 1 )) + MyTR) / length
ENDIF
atr = WilderAverage [ length] (MyATR)
diff = src - src[ 1 ]
at2 = factor * atr
vp= 0
for i= 1 to length
if diff > factor * atr then
vp = vp + volume [ i]
endif
next
vn= 0
for i= 1 to length
if diff < - 1 * (factor * atr) then
vn = vn + volume [ i]
endif
next
vpn = ExponentialAverage [ emaLength] (100 * (vp - vn)/ summation [ length] (volume ))
RETURN vpn as "VPN" , criticalValue as "Thredshold"