# freeware kp_PPO – Plots the Percent Price Oscillator on a daily chart. # The PPO is similar to then MACD except the MACD is # based on absolute values whereas the PPO is relative # to its average price. declare lower; input fastPeriod = 8; input slowPeriod = 17; input signalPeriod = 9; input price = close; input showSignals = yes; def fastEma = ExpAverage(price, fastPeriod); def slowEma = ExpAverage(price, slowPeriod); def periodOK = fastPeriod < slowPeriod; AddLabel(!periodOK, “ERROR: fastPeriod MUST be less than slowPeriod”); def _ppo = if periodOK then (((fastEma – slowEma) / slowEma) * 100) else 0; def _signal = ExpAverage(_ppo, signalPeriod); plot PPO = _ppo; AddLabel(yes, "PPO: " + AsText(PPO, NumberFormat.TWO_DECIMAL_PLACES) + (if PPO > PPO[1] AND PPO > _SIGNAL then " rising" else if PPO < PPO[1] then " falling" else ""), CreateColor(0, 1, 1)); AddLabel(yes, "ppo: " + AsText(PPO[1], NumberFormat.TWO_DECIMAL_PLACES) + (if PPO[1] > PPO[2] then " last week rising" else if PPO[1] < PPO[2] then " last week falling" else ""), CreateColor(0, 1, 1)); PPO.SetLineWeight(3); PPO.HideBubble(); plot PPOEMA = _signal; PPOEMA.SetDefaultColor(Color.RED); plot zeroLine = 0; zeroLine.HideBubble(); zeroLine.SetDefaultColor(Color.LIGHT_GRAY); plot PPOHistogram = _ppo – _signal; PPOHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); PPOHistogram.DefineColor(“Up”, Color.UPTICK); PPOHistogram.DefineColor(“Down”, Color.DOWNTICK); PPOHistogram.DefineColor(“Flat”, Color.GRAY); PPOHistogram.AssignValueColor( if (PPOHistogram > PPOHistogram[1] && PPOHistogram > 0) then PPOHistogram.Color(“Up”) else if (PPOHistogram < PPOHistogram[1] && PPOHistogram < 0) then PPOHistogram.Color(“Down”) else PPOHistogram.Color(“Flat”) ); PPOHistogram.HideBubble(); PPOHistogram.SetLineWeight(5); plot UpSignal = if PPOHistogram crosses above zeroLine then zeroLine else Double.NaN; plot DnSignal = if PPOHistogram crosses below zeroLine then zeroLine else Double.NaN; UpSignal.SetHiding(!showSignals); DnSignal.SetHiding(!showSignals); UpSignal.SetDefaultColor(Color.UPTICK); UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); DnSignal.SetDefaultColor(Color.DOWNTICK); DnSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);