Code:
declare lower;
input length = 30;
input emaLength = 3;
input averageLength = 30;
input factor = 0.1;
input criticalValue = 10;
input averageType = AverageType.SIMPLE;
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;
#VPN.DefineColor("Above", Color.UPTICK);
#VPN.DefineColor("Below", Color.DOWNTICK);
#VPN.AssignValueColor(if VPN > CriticalLevel then VPN.Color("Above") else VPN.Color("Below"));
#VPNAvg.SetDefaultColor(GetColor(7));
CriticalLevel.SetDefaultColor(GetColor(1));
AddCloud(VPN, VPNAvg, Color.GREEN, Color.RED);
VPN.DefineColor("Up", GetColor(1));
VPN.DefineColor("Down", GetColor(0));
VPN.AssignValueColor( if VPN > VPN[1] and VPN > criticallevel then Color.GREEN else if VPN < VPN[1] and VPN > criticallevel then Color.downtick else if VPN > VPN[1] and VPN < criticallevel then Color.YELLOW else if VPN < VPN[1] and VPN < criticallevel then Color.RED else Color.GRAY);
VPNAvg.AssignValueColor(if VPNAvg > CriticalLevel and VPNAvg>VPNAvg[1] then Color.green else if VPNAvg > CriticalLevel and VPNAvg<VPNAvg[1] then Color.red else if VPNAvg < CriticalLevel and VPNAvg>VPNAvg[1] then color.yellow else if VPNAvg < CriticalLevel and VPNAvg<VPNAvg[1] then color.red else color.gray);
Last edited by a moderator: