#
# TD Ameritrade IP Company, Inc. (c) 2015-2016
#
declare lower;
input fastLength = 20;
input slowLength = 50;
input KPeriod = 10;
input DPeriod = 3;
input over_bought = 75;
input over_sold = 25;
input averageType = AverageType.EXPONENTIAL;
def macd = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def fastK1 = FastKCustom(macd, KPeriod);
def fastD1 = MovingAverage(averageType, fastK1, DPeriod);
def fastK2 = FastKCustom(fastD1, KPeriod);
plot STC = MovingAverage(averageType, fastK2, DPeriod);
STC.SetDefaultColor(GetColor(8));
plot line50 = 50;
plot line0 = 0;
plot line100 = 100;
line50.SetDefaultColor(GetColor(7));
line50.SetLineWeight(1);
line50.SetStyle(Curve.FIRM);
line0.SetDefaultColor(GetColor(7));
line0.SetLineWeight(1);
line0.SetStyle(Curve.SHORT_DASH);
line100.SetDefaultColor(GetColor(7));
line100.SetLineWeight(1);
line100.SetStyle(Curve.SHORT_DASH);
plot line80 = 90;
plot line20 = 10;
line80.SetDefaultColor(Color.BLACK);
line20.SetDefaultColor(Color.BLACK);
AddCloud(100, 90, Color.PINK, Color.PINK);
AddCloud(0, 10, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
def stc1 = STC;
def buy = if stc1 > stc1[1] then 1 else if buy[1] == 1 and stc1 >= stc1[1] then 1 else 0;
def sell = if stc1 < stc1[1] then 1 else if sell[1] == 1 and stc1 <= stc1[1] then 1 else 0;
input alerts = no;
Alert(alerts and buy[1] == 0 and buy, "BUY", Alert.BAR, Sound.Ding);
Alert(alerts and sell[1] == 0 and sell, "SELL", Alert.BAR, Sound.Ding);
# --- script end ----
script normalized {
input data = close;
input Min = 0;
input Max = 100;
input length = 50;
def hhData = Highest(data, length);
def llData = Lowest(data, length);
plot resized = (((Max - Min) * (data - llData)) /
(hhData - llData)) + Min;
}
def OBV = TotalSum(Sign(close - close[1]) * volume);
plot x = normalized(OBV);