# MACD SD # By Seth Hahn # Normalizes MACD values to itself with StDev calculation # Default settings are 3,10,9 compared to conventional MACD settings of 12,26,9 declare lower; input fastLength = 3; input slowLength = 10; input MACDLength = 9; input SDLength = 200; input averageType = AverageType.EXPONENTIAL; input showBreakoutSignals = no; def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength); def ValueSD = StDev(Value, SDLength); plot ZValue = Value/ValueSD; plot ZAvg = MovingAverage(averageType, ZValue, MACDLength); plot Diff = ZValue - ZAvg; plot ZeroLine = 0; plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN; plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN; UpSignal.SetHiding(!showBreakoutSignals); DownSignal.SetHiding(!showBreakoutSignals); ZValue.SetDefaultColor(GetColor(1)); ZAvg.SetDefaultColor(GetColor(8)); Diff.SetDefaultColor(GetColor(5)); Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Diff.SetLineWeight(3); Diff.DefineColor("Positive and Up", Color.GREEN); Diff.DefineColor("Positive and Down", Color.DARK_GREEN); Diff.DefineColor("Negative and Down", Color.RED); Diff.DefineColor("Negative and Up", Color.DARK_RED); Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up")); ZeroLine.SetDefaultColor(GetColor(0)); UpSignal.SetDefaultColor(Color.UPTICK); UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP); DownSignal.SetDefaultColor(Color.DOWNTICK); DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);