D

#### [deleted]13

##### Guest

Hello fellow traders and coders. I am new to the group. Personally, the coding gift passed me by. Fortunately, this group and few others lend a hand with their coding knowhow to assist others with our trading opportunities.

Does anybody know if it is possible to generate a scan or chart study alert for the following DualStochasticForecast Study?

"A powerful signal is present when both speeds are simultaneously below OS or above OB."

Does anybody know if it is possible to generate a scan or chart study alert for the following DualStochasticForecast Study?

"A powerful signal is present when both speeds are simultaneously below OS or above OB."

Code:

```
# https://jshingler.github.io/TOS-and-Thinkscript-Snippet-Collection/TOS & Thinkscript Collection.html
# Comments from donor BDPonydoc on Yahoo Groups #(18563)
# Title = My Favorite Indicator
# "Here is the code for my favorite indicator. It is an overbought oversold indicator that I use on just about everything. I think the settings I use are the best ones, I have tried different values over the last several years, but these seem to work the best across all time frames. The best major signal comes when the two oscillators line up. Plot it on a stock daily chart and a 5 min futures chart and I think you will get the picture. On my 3 minutes or 5 minutes futures charts, I use the same settings except for one, the second to the last choice for slowing period1 I use 9 instead of 24. It provides a more responsive Stochastic for day trading.
# Comment: Although there are many stochastic studies out there, this one looked very useful. It is similar to the Market Forecast. A powerful signal is present when both speeds are simultaneously below OS or above OB.
#TOS Title = "DualStochasticForecast"
#hint:<b>Dual speed stochastics</b>\nLook for both speeds being coincident at below the over-sold or above the overbought and for multi-aggs.\nArrows are plotted at the OS and OB crossings
declare lower;
def price = (high + low) / 2;
input over_bought = 90;
input over_sold = 10;
input length = 26;#hint length:For the faster stoch.Recommended default is 26
input KPeriod = 13;#hint KPeriod:For the faster stoch. Recommended default is 13
input DPeriod = 9;#hint DPeriod:For the faster stoch. Recommended default is 9
input slowing_period = 9;#hint slowing_period:For the faster stoch. Recommended default is 9
input smoothingType = 1;#hint smoothingType:For the faster stoch. Recommended default is 1
input DTSell = 95;
input DTBuy = 5;
plot WhiteLabel = Double.NaN;
WhiteLabel.SetDefaultColor(Color.White);
def NetChgAvg = WildersAverage(price - price[1], length);
def TotChgAvg = WildersAverage(AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def c1 = RSI - Lowest(RSI, KPeriod);
def c2 = Highest(RSI, KPeriod) - Lowest(RSI, KPeriod);
def FastK = c1 / c2 * 100;
plot FullK;
plot FullD;
if smoothingType == 1
then {
FullK = Average(FastK, slowing_period);
FullD = Average(FullK, DPeriod);
} else {
FullK = ExpAverage(FastK, slowing_period);
FullD = ExpAverage(FullK, DPeriod);
}
FullK.SetPaintingStrategy(PaintingStrategy.LINE);
FullK.SetLineWeight(2);
FullK.SetDefaultColor(Color.RED);
FullD.SetPaintingStrategy(PaintingStrategy.LINE);
FullD.SetLineWeight(1);
FullD.SetDefaultColor(Color.YELLOW);
#=== plot min arrows for FullK (fast)====
def cond1 = if crosses(FullK,Over_Sold,CrossingDirection.any) then 1 else 0;
Plot Min_Fast = if cond1 then FullK else double.nan;
Min_Fast.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Min_Fast.SetLineWeight(4);
Min_Fast.SetDefaultColor(Color.RED);
#=== plot max arrows for FullK (fast)====
def cond3 = if crosses(FullK,over_Bought,CrossingDirection.any) then 1 else 0;
Plot Max_Fast = if cond3 then FullK else double.nan;
Max_Fast.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Max_Fast.SetLineWeight(4);
Max_Fast.SetDefaultColor(Color.RED);
#========================================
plot OverBought = over_bought;
OverBought.SetDefaultColor(Color.CYAN);
plot OverSold = over_sold;
OverSold.SetDefaultColor(Color.CYAN);
#FullK.SetDefaultColor(GetColor(5));
#FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
#
# thinkorswim, inc. (c) 2008
# Stochastics
input KPeriod1 = 48;#hint KPeriod1:For slower stoch. Recommended default is 48
input DPeriod1 = 12;#hint DPeriod1:For slower stoch. Recommended default is 12
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period1 = 24;#hint slowing_period1:For slower stoch. Recommended default is 24 but use 9 for 3-mi and 5-min charts
input smoothingType1 = 3;#hint smoothingType1:For slower stoch. Recommended default is 3
def c11 = priceC - Lowest(priceL, KPeriod1);def c21 = Highest(priceH, KPeriod1) - Lowest(priceL, KPeriod1);
def FastK1 = c11 / c21 * 100;
plot FullK1;
plot FullD1;
if smoothingType1 == 1
then {
FullK1 = Average(FastK1, slowing_period1);
FullD1 = Average(FullK1, DPeriod1);
} else {
FullK1 = ExpAverage(FastK1, slowing_period1);
FullD1 = ExpAverage(FullK1, DPeriod1);
}
FullK1.SetPaintingStrategy(PaintingStrategy.LINE);
FullK1.SetLineWeight(2);
FullK1.SetDefaultColor(Color.GREEN);
FullD1.SetPaintingStrategy(PaintingStrategy.LINE);
FullD1.SetLineWeight(1);
FullD1.SetDefaultColor(Color.YELLOW);
############################################
#=== plot min arrows for FullK1 (Slow)====
def cond2 = if crosses(FullK1,Over_Sold,CrossingDirection.any) then 1 else 0;
Plot Min_Slow = if cond2 then FullK1 else double.nan;
Min_Fast.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Min_Fast.SetLineWeight(4);
Min_Fast.SetDefaultColor(Color.GREEN);
#=== plot max arrows for FullK1 (slow)====
def cond4 = if crosses(FullK1,over_Bought,CrossingDirection.any) then 1 else 0;
Plot Max_Slow = if cond4 then FullK1 else double.nan;
Max_Slow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Max_Slow.SetLineWeight(4);
Max_Slow.SetDefaultColor(Color.GREEN);
#========================================
Alert(Crosses(FullK, 5, CrossingDirection.ABOVE), "DT OSC Buy", Alert.ONCE, Sound.Ding);
Alert(Crosses(FullK, 95, CrossingDirection.BELOW), "DT OSC Sell", Alert.ONCE, Sound.Ding);
Plot Mid_line = 50;
Mid_line.SetPaintingStrategy(PaintingStrategy.DASHES);
Mid_line.SetLineWeight(1);
Mid_line.SetDefaultColor(Color.YELLOW);
plot StochBuy = If(Crosses(FullK1 or FullD1, 10, CrossingDirection.ABOVE), low, Double.NaN);
StochBuy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot StochSell = If(Crosses(FullK1 or FullD1, 90, CrossingDirection.BELOW) , high, Double.NaN);
StochSell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plot DTBuylevel = DTBuy;
DTBuylevel.SetDefaultColor(Color.YELLOW);
plot DTSelllevel = DTSell;
DTBuylevel.SetDefaultColor(Color.YELLOW);
Plot Label_Line = 105;
Label_Line.setDefaultColor(color.CURRENT);
```

Last edited by a moderator: