themainman
New member
I currently use the below SMI lower study across my ES charts. Right now, the study just plots the SMI and arrows when the crosses occur according to whatever timeframe the lower study is set to.
I typically am using this study on ES 1m, 3m, 5m charts. I was looking to see if you knew a way to add a time variable to the SMI script below so I could stack lower studies of it that would display the SMI of ES (or whatever ticker the chart is on) for 1m, 3m, 5m timeframes.
The reason so is right now I'm using a flexible grid with different timeframes, but if I could have the SMI plotted and stacked on top of each other, for example, 1m ES chart, but lower study will have 3 SMI's. One for 1m, 3m, and 5m.
Is it possible to tweak the script below and have it display for a specific timeframe rather than the one selected on the chart the lower study is added to? Your insight is much appreciated!
I typically am using this study on ES 1m, 3m, 5m charts. I was looking to see if you knew a way to add a time variable to the SMI script below so I could stack lower studies of it that would display the SMI of ES (or whatever ticker the chart is on) for 1m, 3m, 5m timeframes.
The reason so is right now I'm using a flexible grid with different timeframes, but if I could have the SMI plotted and stacked on top of each other, for example, 1m ES chart, but lower study will have 3 SMI's. One for 1m, 3m, and 5m.
Is it possible to tweak the script below and have it display for a specific timeframe rather than the one selected on the chart the lower study is added to? Your insight is much appreciated!
Code:
# Stochastic Momentum Index
# Base code by TD Ameritrade IP Company, Inc. (c) 2008-2020
# Added arrows and alerts when SMI/AvgSMI cross above/below the oversold/overbought lines
declare lower;
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;
input alerts = yes;
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);
plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
smi.setDefaultColor(getColor(1));
plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));
plot overbought = over_bought;
overbought.setDefaultColor(getcolor(5));
plot oversold = over_sold;
oversold.setDefaultColor(getcolor(5));
def signalUp = AvgSMI[1] < oversold and SMI[1] < AvgSMI[1] and SMI > AvgSMI;
def signalDn = AvgSMI[1] > overbought and SMI[1] > AvgSMI[1] and SMI < AvgSMI;
plot arrowUp = if signalUp then AvgSMI else double.nan;
arrowUp.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
arrowUp.SetDefaultColor(color.green);
plot arrowDn = if signalDn then AvgSMI else double.nan;
arrowDn.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
arrowDn.SetDefaultColor(color.red);
#end code
Last edited by a moderator: