Swami Stochastics
Swami Stochastics was developed by John Ehlers and Ric Way. It utilizes a series of stochastic values to determine bullish and bearish periods. The indicator will be green when entering a bullish period, red when entering a bearish period. Yellow is displayed when the direction is indeterminate. The user may change the period lengths. This indicator’s definition is further expressed in the raw code given in the calculation below.
Click here for details.
How To Trade Using Swami Stochastics
No trading signals are calculated for this indicator.
How To Access in MotiveWave
Go to the top menu, choose Study>Custom>Swami Stochastics
or go to the top menu, choose Add Study, start typing in this study name until you see it appear in the list, click on the study name, click OK.
Important Disclaimer: The information provided on this page is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. Please see our Risk Disclosure and Performance Disclaimer Statement.
Calculation
//minPeriod = user defined, default is 12
//maxPeriod = user defined, default is 48
//MT = more than, LT = less than
//index = current bar number
protected void calculate(int index, DataContext ctx)
int minPeriod = getSettings().getInteger(Inputs.MIN_PERIOD);
int maxPeriod = getSettings().getInteger(Inputs.MAX_PERIOD);
if (minPeriod MT maxPeriod)
int tmp = maxPeriod;
minPeriod = maxPeriod;
maxPeriod = tmp;
end
getRuntimeDescriptor().setFixedBottomValue(minPeriod);
getRuntimeDescriptor().setFixedTopValue(maxPeriod);
if (index+1 LT minPeriod) return;
DataSeries series = ctx.getDataSeries();
int count = maxPeriod - minPeriod;
// Calculate the stochastic
ColorRange range = new ColorRange(series.getStartTime(index));
double pNum[] = (double[])series.getValue(index-1, Values.NUMERATOR);
double pDenom[] = (double[])series.getValue(index-1,Values.DENOMINATOR);
double pStoch[] = (double[])series.getValue(index-1, Values.STOCH);
double num[] = new double[count];
double denom[] = new double[count];
double stoch[] = new double[count];
for(int i = 0; i LT count; i++)
int period = i + minPeriod;
Double high = series.highest(index, period, Enums.BarInput.HIGH);
Double low = series.lowest(index, period, Enums.BarInput.LOW);
if (high == null || low == null) break;
num[i] = (series.getClose(index) - low + (pNum == null ? 0 : pNum[i]))/2;
denom[i] = (high - low + (pDenom == null ? 0 : pDenom[i]))/2;
if (denom[i] != 0)
stoch[i] = 0.2*(num[i]/denom[i]) + 0.8*(pStoch == null ? 0 : pStoch[i]);
end
int R = 255;
int G = 255;
if (stoch[i] MT 0.5) R = (int)(255*(2 - 2*stoch[i]));
else G = (int)(255*2*stoch[i]);
range.addRegion(new Color(R, G, 0), period, period+1);
end
addFigure(range);
series.setValue(index, Values.NUMERATOR, num);
series.setValue(index, Values.DENOMINATOR, denom);
series.setValue(index, Values.STOCH, stoch);
end