Here is the Smarter MACD code that I have from TOS Indicators...
Ruby:
#TOS Indicators
#Home of the Volatility Box
#Indicator Name: Smarter MACD
#Full tutorial here: tosindicators.com/indicators/smarter-macd
declare lower;
input lever = {default "Fast", "Slow", "Medium"};
input mode = {default "Aggressive", "Conservative"};
def fastLength;
def slowLength;
def averageType;
switch(lever){
case "Fast":
fastLength = 3;
slowLength = 8;
averageType = AverageType.Exponential;
case "Slow":
fastLength = 10;
slowLength = 20;
averageType = AverageType.Simple;
case "Medium":
fastLength = 12;
slowLength = 26;
averageType = AverageType.Exponential;
}
def outputLength;
switch(mode){
case "Aggressive":
outputLength = fastLength;
case "Conservative":
outputLength = slowLength;
}
def higherTF = if getAggregationPeriod() < AggregationPeriod.Five_Min then AggregationPeriod.Five_Min
else if getAggregationPeriod() < AggregationPeriod.Fifteen_Min then AggregationPeriod.Fifteen_Min
else if getAggregationPeriod() < AggregationPeriod.Thirty_Min then AggregationPeriod.Thirty_Min
else if getAggregationPeriod() < AggregationPeriod.Hour then AggregationPeriod.Hour
else if getAggregationPeriod() < AggregationPeriod.Day then AggregationPeriod.Day
else if getAggregationPeriod() < AggregationPeriod.Week then AggregationPeriod.Week
else if getAggregationPeriod() < AggregationPeriod.Month then AggregationPeriod.Month
else AggregationPeriod.Year;
def Value = MovingAverage(averageType, close(period = higherTF), fastLength) - MovingAverage(averageType, close(period = higherTF), slowLength);
plot smarterMACD = MovingAverage(averageType, Value, outputLength);
def upSwitch = if smarterMACD > smarterMACD[1] then 1 else if smarterMACD < smarterMACD[1] then 0 else upSwitch[1];
def downSwitch = if smarterMACD < smarterMACD[1] then 1 else if smarterMACD > smarterMACD[1] then 0 else downSwitch[1];
smarterMACD.setLineWeight(2);
smarterMACD.AssignValueColor(if upSwitch then color.green else if downSwitch then color.red else color.gray);