#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#
# INPUTS
input price = close;
input length_fast = 3;
input displace_fast = 0;
input length_slow = 9;
input displace_slow = 0;
# MACD
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;
# Erg
input longLength = 2;
input shortLength = 10;
input signalLength = 36;
input averageType = AverageType.EXPONENTIAL;
#
# SMA
#
def SMA_fast = Average(price[-displace_fast], length_fast);
def SMA_slow = Average(price[-displace_slow], length_slow);
#
# MACD
#
def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);
def MACD_Dots = MACD_Data;
def MACD_Line = MACD_Data;
#
# ErgodicOsc
#
def ErgodicOsc = TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal;
def ZeroLine = 0;
def UpCond1 = SMA_fast crosses above SMA_slow within 10 bars;
def UpCond2 = MACD_Dots >= 0.5;
def UpCond3 = ErgodicOsc >= 5;
def UpCond4 = MACD_Dots crosses above ZeroLine within 10 bars;
def UpCond5 = MACD_Dots > MACD_Dots[1];
def DownCond1 = SMA_fast crosses below SMA_slow within 10 bars;
def DownCond2 = MACD_Dots <= -0.5;
def DownCond3 = ErgodicOsc <= -5;
def DownCond4 = MACD_Dots crosses below ZeroLine within 10 bars;
def DownCond5 = MACD_Dots < MACD_Dots[1];
plot SPXUp = UpCond1 and UpCond2 and UpCond3 and UpCond4 and UpCond5;
plot SPXDown = DownCond1 and DownCond2 and DownCond3 and DownCond4 and DownCond5;
SPXUp.SetDefaultColor(Color.DARK_ORANGE);
SPXUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SPXDown.SetDefaultColor(Color.DARK_RED);
SPXDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);