TritonHawk
New member
Could someone please convert this indicator from TV? https://www.tradingview.com/v/lJiDn2VR/. It's the lower indicator "StochD". Please and Thank you!
try this. Arrow will show instead of divergence lines.Could someone please convert this indicator from TV? https://www.tradingview.com/v/lJiDn2VR/. It's the lower indicator "StochD". Please and Thank you!
View attachment 19335
#//@Jesse.Lau
#indicator(title="[JL] Stochastic Divergence Alert", shorttitle="StochD", format=format.price, precision=2
# -- Converted by Sam4Cok@Samer800 - 08/2023 - request form UseThinkScript.com member
Declare lower;
input periodK = 9;
input smoothK = 3; # "%K Smoothing"
input periodD = 3; # "%D Smoothing"
input TopLevel = 70; # "Top Level"
input BottomLevel = 30; # "Bottom Level"
def na = Double.NaN;
def last = IsNaN(close);
# stoch(source, high, low, length) =>
script stoch {
input src = close;
input h = high;
input l = low;
input len = 14;
def hh = Highest(h, len);
def ll = Lowest(l, len);
def stoch = 100 * (src - ll) / (hh - ll);
plot return = stoch;
}
def stoch = stoch(close, high, low, periodK);
def k = Average(stoch, smoothK);
def d = Average(k, periodD);
plot FullK = k; # "%K"
plot FullD = d; # "%D"
FullK.SetLineWeight(2);
FullD.SetLineWeight(2);
FullK.SetDefaultColor(CreateColor(33, 150, 243));
FullD.SetDefaultColor(GetColor(0));
plot ht = if last then na else TopLevel; # "Upper Band"
plot hb = if last then na else BottomLevel; # "Lower Band"
ht.SetDefaultColor(Color.GRAY);
hb.SetDefaultColor(Color.GRAY);
AddCloud(ht, hb, Color.DARK_GRAY); # "Background"
def GC1 = (k >= d);
def DC1 = (k <= d);
def GC = Crosses(k, d, CrossingDirection.ABOVE);
def DC = Crosses(k, d, CrossingDirection.BELOW);
def counter;# = 0
def lastgc;# = 0
def lastdc;# = 0
def kh;# = 0.0
def kl;# = 100.0
def l1;# = 10000.0
def kl_ = if kl[1]==0 then 100 else kl[1];
def l1_ = if l1[1]==0 then 10000 else l1[1];
def h1;# = 0.0
def cnt = counter[1] + 1;
if(GC1) {
kh = if k < kh[1] then kh[1] else k;
kl = 100.0;
h1 = if high < h1[1] then h1[1] else high;
l1 = 10000.0;
} else
if(DC1) {
kl = if k > kl_ then kl_ else k;
kh = 0.0;
l1 = if low > l1_ then l1_ else low;
h1 = 0.0;
} else {
kl = kl_;
kh = kh[1];
l1 = l1_;
h1 = h1[1];
}
if (DC) {
lastgc = cnt;
lastdc = lastdc[1];
counter = 0;
} else
if (GC) {
lastgc = lastgc[1];
lastdc = cnt;
counter = 0;
} else {
lastgc = lastgc[1];
lastdc = lastdc[1];
counter = cnt;
}
def klValue = GetValue(kl, lastdc + lastgc + 1);
def l1Value = GetValue(l1, lastdc + lastgc + 1);
def khValue = GetValue(kh, lastdc + lastgc + 1);
def h1Value = GetValue(h1, lastdc + lastgc + 1);
def turnGreen = GC and kl[1] > klValue and l1[1] <= l1Value and klValue < BottomLevel;
def turnRed = DC and kh[1] < khValue and h1[1] >= h1Value and khValue > TopLevel;
def shapeGreen = if turnGreen then kl[1] - 5 else na;#Value - 5 else na;
def shapeRed = if turnRed then kh[1] + 5 else na;#Value + 5 else na;
plot greenLine = shapeGreen;
plot redLine = shapeRed;
greenLine.SetDefaultColor(Color.GREEN);
redLine.SetDefaultColor(Color.RED);
greenLine.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
redLine.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#-- END of CODE
It is possible to add alerts to the arrows and aggregation time frames? I've tried multiple times but horrible at coding. Please and Thank you!try this. Arrow will show instead of divergence lines.
CSS:#//@Jesse.Lau #indicator(title="[JL] Stochastic Divergence Alert", shorttitle="StochD", format=format.price, precision=2 # -- Converted by Sam4Cok@Samer800 - 08/2023 - request form UseThinkScript.com member Declare lower; input periodK = 9; input smoothK = 3; # "%K Smoothing" input periodD = 3; # "%D Smoothing" input TopLevel = 70; # "Top Level" input BottomLevel = 30; # "Bottom Level" def na = Double.NaN; def last = IsNaN(close); # stoch(source, high, low, length) => script stoch { input src = close; input h = high; input l = low; input len = 14; def hh = Highest(h, len); def ll = Lowest(l, len); def stoch = 100 * (src - ll) / (hh - ll); plot return = stoch; } def stoch = stoch(close, high, low, periodK); def k = Average(stoch, smoothK); def d = Average(k, periodD); plot FullK = k; # "%K" plot FullD = d; # "%D" FullK.SetLineWeight(2); FullD.SetLineWeight(2); FullK.SetDefaultColor(CreateColor(33, 150, 243)); FullD.SetDefaultColor(GetColor(0)); plot ht = if last then na else TopLevel; # "Upper Band" plot hb = if last then na else BottomLevel; # "Lower Band" ht.SetDefaultColor(Color.GRAY); hb.SetDefaultColor(Color.GRAY); AddCloud(ht, hb, Color.DARK_GRAY); # "Background" def GC1 = (k >= d); def DC1 = (k <= d); def GC = Crosses(k, d, CrossingDirection.ABOVE); def DC = Crosses(k, d, CrossingDirection.BELOW); def counter;# = 0 def lastgc;# = 0 def lastdc;# = 0 def kh;# = 0.0 def kl;# = 100.0 def l1;# = 10000.0 def kl_ = if kl[1]==0 then 100 else kl[1]; def l1_ = if l1[1]==0 then 10000 else l1[1]; def h1;# = 0.0 def cnt = counter[1] + 1; if(GC1) { kh = if k < kh[1] then kh[1] else k; kl = 100.0; h1 = if high < h1[1] then h1[1] else high; l1 = 10000.0; } else if(DC1) { kl = if k > kl_ then kl_ else k; kh = 0.0; l1 = if low > l1_ then l1_ else low; h1 = 0.0; } else { kl = kl_; kh = kh[1]; l1 = l1_; h1 = h1[1]; } if (DC) { lastgc = cnt; lastdc = lastdc[1]; counter = 0; } else if (GC) { lastgc = lastgc[1]; lastdc = cnt; counter = 0; } else { lastgc = lastgc[1]; lastdc = lastdc[1]; counter = cnt; } def klValue = GetValue(kl, lastdc + lastgc + 1); def l1Value = GetValue(l1, lastdc + lastgc + 1); def khValue = GetValue(kh, lastdc + lastgc + 1); def h1Value = GetValue(h1, lastdc + lastgc + 1); def turnGreen = GC and kl[1] > klValue and l1[1] <= l1Value and klValue < BottomLevel; def turnRed = DC and kh[1] < khValue and h1[1] >= h1Value and khValue > TopLevel; def shapeGreen = if turnGreen then kl[1] - 5 else na;#Value - 5 else na; def shapeRed = if turnRed then kh[1] + 5 else na;#Value + 5 else na; plot greenLine = shapeGreen; plot redLine = shapeRed; greenLine.SetDefaultColor(Color.GREEN); redLine.SetDefaultColor(Color.RED); greenLine.SetPaintingStrategy(PaintingStrategy.ARROW_UP); redLine.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); #-- END of CODE
add the below at the end of the code:It is possible to add alerts to the arrows and aggregation time frames? I've tried multiple times but horrible at coding. Please and Thank you!
input sound = Sound.NoSound;
input alertType = Alert.BAR;
Alert(turnGreen, "Long", alertType, sound);
Alert(turnRed, "Short", alertType, sound);
use the belowCan you make the arrow show up on the chart upper?. thanks
#//@Jesse.Lau
#indicator(title="[JL] Stochastic Divergence Alert", shorttitle="StochD", format=format.price, precision=2
# -- Converted by Sam4Cok@Samer800 - 08/2023 - request form UseThinkScript.com member
# -- Update by Sam4Cok@Samer800 - 11/2023 - Upper study
input periodK = 9;
input smoothK = 3; # "%K Smoothing"
input periodD = 3; # "%D Smoothing"
input TopLevel = 70; # "Top Level"
input BottomLevel = 30; # "Bottom Level"
def na = Double.NaN;
def last = IsNaN(close);
# stoch(source, high, low, length) =>
script stoch {
input src = close;
input h = high;
input l = low;
input len = 14;
def hh = Highest(h, len);
def ll = Lowest(l, len);
def stoch = 100 * (src - ll) / (hh - ll);
plot return = stoch;
}
def stoch = stoch(close, high, low, periodK);
def k = Average(stoch, smoothK);
def d = Average(k, periodD);
def GC1 = (k >= d);
def DC1 = (k <= d);
def GC = Crosses(k, d, CrossingDirection.ABOVE);
def DC = Crosses(k, d, CrossingDirection.BELOW);
def counter;# = 0
def lastgc;# = 0
def lastdc;# = 0
def kh;# = 0.0
def kl;# = 100.0
def l1;# = 10000.0
def kl_ = if kl[1]==0 then 100 else kl[1];
def l1_ = if l1[1]==0 then 10000 else l1[1];
def h1;# = 0.0
def cnt = counter[1] + 1;
if(GC1) {
kh = if k < kh[1] then kh[1] else k;
kl = 100.0;
h1 = if high < h1[1] then h1[1] else high;
l1 = 10000.0;
} else
if(DC1) {
kl = if k > kl_ then kl_ else k;
kh = 0.0;
l1 = if low > l1_ then l1_ else low;
h1 = 0.0;
} else {
kl = kl_;
kh = kh[1];
l1 = l1_;
h1 = h1[1];
}
if (DC) {
lastgc = cnt;
lastdc = lastdc[1];
counter = 0;
} else
if (GC) {
lastgc = lastgc[1];
lastdc = cnt;
counter = 0;
} else {
lastgc = lastgc[1];
lastdc = lastdc[1];
counter = cnt;
}
def klValue = GetValue(kl, lastdc + lastgc + 1);
def l1Value = GetValue(l1, lastdc + lastgc + 1);
def khValue = GetValue(kh, lastdc + lastgc + 1);
def h1Value = GetValue(h1, lastdc + lastgc + 1);
def turnGreen = GC and kl[1] > klValue and l1[1] <= l1Value and klValue < BottomLevel;
def turnRed = DC and kh[1] < khValue and h1[1] >= h1Value and khValue > TopLevel;
def shapeGreen = if turnGreen then low else na;#Value - 5 else na;
def shapeRed = if turnRed then high else na;#Value + 5 else na;
plot greenLine = shapeGreen;
plot redLine = shapeRed;
greenLine.SetDefaultColor(Color.CYAN);
redLine.SetDefaultColor(Color.MAGENTA);
greenLine.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
redLine.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
input sound = Sound.NoSound;
input alertType = Alert.BAR;
Alert(turnGreen, "Long", alertType, sound);
Alert(turnRed, "Short", alertType, sound);
#-- END of CODE
#Stochastic Divergence Alert SCANNER ONLY
input periodK = 9;
input smoothK = 3; # "%K Smoothing"
input periodD = 3; # "%D Smoothing"
input TopLevel = 70; # "Top Level"
input BottomLevel = 30; # "Bottom Level"
def na = Double.NaN;
def last = IsNaN(close);
# stoch(source, high, low, length) =>
script stoch {
input src = close;
input h = high;
input l = low;
input len = 14;
def hh = Highest(h, len);
def ll = Lowest(l, len);
def stoch = 100 * (src - ll) / (hh - ll);
plot return = stoch;
}
def stoch = stoch(close, high, low, periodK);
def k = Average(stoch, smoothK);
def d = Average(k, periodD);
def GC1 = (k >= d);
def DC1 = (k <= d);
def GC = Crosses(k, d, CrossingDirection.ABOVE);
def DC = Crosses(k, d, CrossingDirection.BELOW);
def counter;# = 0
def lastgc;# = 0
def lastdc;# = 0
def kh;# = 0.0
def kl;# = 100.0
def l1;# = 10000.0
def kl_ = if kl[1]==0 then 100 else kl[1];
def l1_ = if l1[1]==0 then 10000 else l1[1];
def h1;# = 0.0
def cnt = counter[1] + 1;
if(GC1) {
kh = if k < kh[1] then kh[1] else k;
kl = 100.0;
h1 = if high < h1[1] then h1[1] else high;
l1 = 10000.0;
} else
if(DC1) {
kl = if k > kl_ then kl_ else k;
kh = 0.0;
l1 = if low > l1_ then l1_ else low;
h1 = 0.0;
} else {
kl = kl_;
kh = kh[1];
l1 = l1_;
h1 = h1[1];
}
if (DC) {
lastgc = cnt;
lastdc = lastdc[1];
counter = 0;
} else
if (GC) {
lastgc = lastgc[1];
lastdc = cnt;
counter = 0;
} else {
lastgc = lastgc[1];
lastdc = lastdc[1];
counter = cnt;
}
def klValue = GetValue(kl, lastdc + lastgc + 1);
def l1Value = GetValue(l1, lastdc + lastgc + 1);
def khValue = GetValue(kh, lastdc + lastgc + 1);
def h1Value = GetValue(h1, lastdc + lastgc + 1);
plot turnGreen = GC and kl[1] > klValue and l1[1] <= l1Value and klValue < BottomLevel;
#plot turnRed = DC and kh[1] < khValue and h1[1] >= h1Value and khValue > TopLevel;
to this:plot turnGreen = GC and kl[1] > klValue and l1[1] <= l1Value and klValue < BottomLevel;
#plot turnRed = DC and kh[1] < khValue and h1[1] >= h1Value and khValue > TopLevel;
#plot turnGreen = GC and kl[1] > klValue and l1[1] <= l1Value and klValue < BottomLevel;
plot turnRed = DC and kh[1] < khValue and h1[1] >= h1Value and khValue > TopLevel;
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Stochastic Oscillator Divergence Indicator For ThinkOrSwim | Custom | 2 | ||
S | Stochastic OTT For ThinkOrSwim | Custom | 6 | |
Exponential Stochastic For ThinkOrSwim | Custom | 6 | ||
Ehlers Stochastic CG Oscillator [LazyBear] For ThinkOrSwim | Custom | 7 | ||
P | RSI and Stochastic Probability Based Price Target For ThinkOrSwim | Custom | 1 |
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.