I've added a Input for Average Type for the PPO MacD created by North Vanhooser. The issue is when set to Exponential it's no where near matching the signal of Exponential comparing it to the standard TOS MacD study, MacD line, Signal line and Historgram is way off. Change it to Simple MA its a match.
Anyhow was hoping someone could help me out to get the problem solved.
Code:
# PPO - North Vanhooser
declare lower;
input fastPeriod = 12;
input slowPeriod = 26;
input signalPeriod = 9;
input price = close;
input avgType = {
default EXPONENTIAL,
SIMPLE,
WEIGHTED,
WILDERS,
HULL
};
input histoColorStyle = {
default Original,
Green_Red,
Cyan_Blue
};
def fastMA = MovingAverage(avgType, price, fastPeriod);
def slowMA = MovingAverage(avgType, price, slowPeriod);
def periodOK = fastPeriod < slowPeriod;
AddLabel(!periodOK, "ERROR: fastPeriod MUST be less than slowPeriod", Color.YELLOW);
def ppo = if periodOK then ((fastMA - slowMA) / slowMA) * 100 else Double.NaN;
def signal = MovingAverage(avgType, ppo, signalPeriod);
def histo = ppo - signal;
plot PpoLine = ppo;
PpoLine.SetDefaultColor(Color.BLUE);
PpoLine.HideBubble();
plot SignalLine = signal;
SignalLine.SetDefaultColor(Color.CYAN);
SignalLine.HideBubble();
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.BLACK);
ZeroLine.HideBubble();
plot HistoPlot = histo;
HistoPlot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
HistoPlot.SetLineWeight(3);
# === Slope Detection
def isUp = histo > histo[1];
def isDown = histo < histo[1];
# === Define color index for styles
def colorIndex =
if histoColorStyle == histoColorStyle.Original then
if isUp then 1
else if isDown then 2
else 3
else if histoColorStyle == histoColorStyle.Green_Red then
if isUp and histo > 0 then 4 # Green
else if isDown and histo > 0 then 5 # Dark Green
else if isDown and histo < 0 then 6 # Red
else if isUp and histo < 0 then 7 # Dark Red
else 3
else if histoColorStyle == histoColorStyle.Cyan_Blue then
if isUp then 8
else if isDown then 9
else 3
else 3;
# === Assign color once
HistoPlot.AssignValueColor(
if colorIndex == 1 then Color.UPTICK
else if colorIndex == 2 then Color.DOWNTICK
else if colorIndex == 3 then Color.GRAY
else if colorIndex == 4 then Color.GREEN
else if colorIndex == 5 then Color.DARK_GREEN
else if colorIndex == 6 then Color.RED
else if colorIndex == 7 then Color.DARK_RED
else if colorIndex == 8 then Color.CYAN
else if colorIndex == 9 then Color.BLUE
else Color.LIGHT_GRAY
);