Free Scan! Basic Coding On Think or Swim.

2 years ago
57

Creating buy and sell signals on the stochastic momentum Index.

# Stochastic Momentum Index Scan Bull and Bear

#
# TD Ameritrade IP Company, Inc. (c) 2008-2021
#

declare lower;

input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;

def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);

def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;

def AvgSMI = ExpAverage(SMI, percentDLength);

def overbought = over_bought;

def oversold = over_sold;

Plot Uparrow = SMI > AvgSmi and SMI[1] < AvgSMI[1] and SMI < Oversold and AvgSMI < Oversold ;

def DownArrow = SMI < AvgSmi and SMI[1] > AvgSMI[1] and SMI > OverBought and AvgSMI > Oversold ;

Loading comments...