Join useThinkScript to post your question to a community of 21,000+ developers and traders.
### Stochastic for current chart symbol (QQQ)
def x = ExpAverage(close, 28);
def s = StochasticFull(14,3,3);
### Stochastic for comparison symbol (SPY)
def SPYstoch = stochasticFull("SPY",14,3,3);
input ticker = "SPY"; (or any second ticker symbol)
### Stochastic for current chart symbol (QQQ)
def x = ExpAverage(close, 28);
def s = StochasticFull();
### Stochastic for comparison symbol (SPY)
input ticker = "SPY";
def x2 = ExpAverage(close, 28);
def s2 = StochasticFull();
#test code 1 - does NOT use the price of SPY, even though an input is created
input ticker = "SPY";
def h = high;
def l = low;
def c = close;
plot x2 = StochasticFull();
#test code 2 - DOES use the price of SPY
input ticker = "SPY";
def h = high(ticker);
def l = low(ticker);
def c = close(ticker);
plot x2 = StochasticFull(priceH = h, priceL = l, priceC = c);
#test code 3
input ticker = "SPY";
def c = close(ticker);
plot x2 = ExpAverage(c,28);
#test code 4
plot x2 = ExpAverage(close("SPY"),28);
Pensar: that was very very kind of you! Thank you!
... but I am not sure that is the correct formula for StochasticFull (aren't there three values inside the stochastic( ), kperiod, dperiod, and slowing? - not your high, low, close) - I think I can find the formula somewhere to calculate the StochasticFull value from back 14 (or however) many high, low, and closes are involved but ExpAverage(close("SPY"),28) looks right and is a big help.
plot sf = StochasticFull(priceH = high, priceL = low, priceC = close, over_bought = 80, over_sold = 20, Kperiod = 10, Dperiod = 10, slowing_period = 3, averagetype = AverageType.SIMPLE);
plot x = StochasticFull().FullK;
plot y = StochasticFull().FullD;
plot os = StochasticFull().OverSold;
plot ob = StochasticFull().OverBought;
# StochasticFull with user-adjustable symbol input
declare lower;
input symbol = "SPY";
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};
def priceH = high(symbol);
def priceL = low(symbol);
def priceC = close(symbol);
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);
plot OverBought = over_bought;
plot OverSold = over_sold;
def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;
plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
UpSignal = Double.NaN;
DownSignal = Double.NaN;
case "On FullK":
UpSignal = if upK then OverSold else Double.NaN;
DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
UpSignal = if upD then OverSold else Double.NaN;
DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
UpSignal = if upK or upD then OverSold else Double.NaN;
DownSignal = if downK or downD then OverBought else Double.NaN;
}
UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
# End Code
# Stochastic for current chart symbol
declare lower;
input symbol = "QQQ";
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
def priceH = high(symbol);
def priceL = low(symbol);
def priceC = close(symbol);
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);
# Stochastic comparison for second symbol (not on chart)
input symbol2 = "SPY";
input over_bought2 = 80;
input over_sold2 = 20;
input KPeriod2 = 10;
input DPeriod2 = 10;
input slowing_period2 = 3;
input averageType2 = AverageType.SIMPLE;
def priceH2 = high(symbol2);
def priceL2 = low(symbol2);
def priceC2 = close(symbol2);
def lowest_k2 = Lowest(priceL2, KPeriod2);
def c1.2 = priceC2 - lowest_k2;
def c2.2 = Highest(priceH2, KPeriod2) - lowest_k2;
def FastK2 = if c2.2 != 0 then c1.2 / c2.2 * 100 else 0;
plot FullK2 = MovingAverage(averageType2, FastK2, slowing_period2);
plot FullD2 = MovingAverage(averageType2, FullK2, DPeriod2);
#Plot Two Candle Fills Above MA
plot twoUp = close is greater than MovAvgExponential()."AvgExp" and close[1] is greater than MovAvgExponential()."AvgExp"[1] and close crosses above MovAvgExponential()."AvgExp" within 2 bars;
twoUp.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
twoUp.SetLineWeight(3);
twoUp.SetDefaultColor(Color.GREEN);
#Plot Two Candle Fills Below MA
plot twoDn = close is less than MovAvgExponential()."AvgExp" within 1 bar and close[1] is less than MovAvgExponential()."AvgExp"[1] and close crosses below MovAvgExponential()."AvgExp" within 2 bars;
twoDn.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Down);
twoDn.SetLineWeight(3);
twoDn.SetDefaultColor(Color.RED);
# Alerts
Alert(twoUp, " ", Alert.Bar, Sound.Chimes);
Alert(twoDn, " ", Alert.Bar, Sound.Chimes);
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.