KDJ from pinescript to thinkscript

Status
Not open for further replies.

Chaomane

New member

The Converted KDJ Indicator for ThinkOrSwim can be found: https://usethinkscript.com/threads/kdj-indicator-for-thinkorswim.9501/ Fill free to continue discussion there. This thead is locked.


I'd love if someone with more experience could convert this script for me, I'd even be willing to pay a bit. KDJ indicator.

Code:
study("KDJ Indicator")
// KDJ Indicator, Rev 03
//
// Rewrite for Tradingview "Pine Script" by Kocurekc, April 2014
// https://getsatisfaction.com/tradingview/
// https://www.tradingview.com/u/kocurekc/
// Code is provided as public domain, no warranty
 
lenL = input(title="Lookback Period, Long", type=integer, defval=14, minval=2)
lenS = input(title="Lookback Period, Short", type=integer, defval=5, minval=2)
bE = input(title="Use EMA?", type=bool, defval=true)
bJ = input(title="Smooth the %J?", type=bool, defval=false)
lenJ = input(title="%J Smoothing", type=integer, defval=5, minval=1)
 
s = stoch(close, high, low, lenL)
pK = bE ? ema(s,5) : sma(s,5)
pD = bE ? ema(pK, lenS) : sma(pK, lenS)
pJ = (3 * pD) - (2 * pK)
 
plot(pK, color=blue)
plot(pD, color=red)
plot(bJ ? sma(pJ,lenJ) : pJ, color=green)
 
Last edited by a moderator:
Solution
@Chaomane This is most likely similiar to your trading view one. Thought I had seen it before and had it in my records.

Code:
# 

declare lower;

input overBot       = 80;
input overSld       = 20;
input kPeriod       = 9;
input dPeriod       = 3;
input slowingPeriod = 3;
input averageType   = AverageType.SIMPLE;

def rsv             = StochasticFull( overBot, overSld, kPeriod, dPeriod, high, low, close, slowingPeriod, averageType ).FastK;

plot K              = MovingAverage( averageType, rsv, slowingPeriod );
plot D              = MovingAverage( averageType, K, dPeriod );
plot J              = ( 3 * D ) - ( 2 * K );

plot OverBought     = overBot;
plot OverSold       = overSld;

K.SetDefaultColor( GetColor( 1 ) )...
hi diazlaz, thank you for sharing this very nice scripts, can i ask you for a favor, do you think is possible to add a buy and sell arrow on the top of the chart, as soon the candle changes color from red tu green then a green arrow appear on the bottom of the candles and viceversas. thank yo and advance.
 
@FOTM_8888 No problem at all.

The plot command is used to PRINT stuff on a chart. When we change 'plot' to 'def'. We are telling it to NOT print those lines because we only want arrows. BUT along with the plot command, there are other formatting commands for the ppJ, ppD, ppK which need to be removed. Delete the "SetDefaultColor" lines for each of those variables. Seeing as you are not printing them, they don't need color.

If you edit other indicators in the future watch for: SetLineWeight and PrintingStrategy as other lines that would need to be removed.
 
Congratulations!

As you didn't provide your modified script, I can't know for sure where the problem is. I have to guess.
Most likely your plot command for the arrows have not been changed to point to a place on your upper chart.

Code:
#your code
plot ppJ_crossUP = if ppJ crosses above OverSold then OverSold else double.NaN ;
plot ppJ_crossDN = if ppJ crosses below OverBought then OverBought else double.NaN ;

You don't have an Oversold or Overbought on the upper chart so no arrow.

You can do pretty formatting like is shown in the example you are following or just change it to point to the low and high parts of the candle
like this:

Code:
#changed to this:
plot ppJ_crossUP = if ppJ crosses above OverSold then low else double.NaN ;
plot ppJ_crossDN = if ppJ crosses below OverBought then high else double.NaN ;

Do you see?
 
I still have the same problem doesn't give me any chooses for scan I think the code need to add something more to allow for the scan. Also it is not working on mobile application. Please can you make it available for mobile application as well
 
Hi @wtf_dude . First off, I want to thank you for this code. I use very few indicators, however this is one that I have made part of my go-to setup. Thank you! I note that in the code it looks like you have added functionality for "buy" / "sell" signals (up arrows / down arrows), but that they are disabled. Would you be willing to post a version that includes those signals? As always, I am happy to pay for work done. Keep well.
 
Is this what you are looking for:

aaa2.png


Code:
# To Add CrossOver Signals to KDJ indicator
# paste the following code into the end of your study:

plot ppJ_crossUP = if ppJ crosses above OverSold then OverSold else double.NaN ;
plot ppJ_crossDN = if ppJ crosses below OverBought then OverBought else double.NaN ;

ppJ_crossUP.SetPaintingStrategy(PaintingStrategy.ARROW_up);
ppJ_crossUP.SetLineWeight(2);
ppJ_crossUP.SetDefaultColor(color.green) ;
ppJ_crossDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ppJ_crossDN.SetLineWeight(2);
ppJ_crossDN.SetDefaultColor(color.red) ;
Hi, does anyone know if a Chime/Bell can be added to this indicator, when the line is above 100 & when the line is under 0? Not sure if this is possible or not, but thought I'd ask as someone just recently shared this indicator through a discord channel. Here's a link to their TOS Script: http://tos.mx/3fN3VQb
 
@MerryDay I think I'll just stick to the Updated script with the arrows that you've added. It seems to work much smoother without the Bell/Chimes as those chimes are triggering based on EMA crossings & I don't believe that this is what the KDJ Indicator was created for
 
@MerryDay I think I'll just stick to the Updated script with the arrows that you've added. It seems to work much smoother without the Bell/Chimes as those chimes are triggering based on EMA crossings & I don't believe that this is what the KDJ Indicator was created for
Ahhhh... I see. You got some upper chart script from somewhere and then tried to add your lower chart plots to it.
Yeah, that was never going to work.

If you want alerts, you need to use the original script and then add:
Ruby:
# To Add CrossOver Alerts to KDJ indicator
# paste the following code into the end of your study:

Alert(ppJ_crossUP , "ppJ_crossUP ", Alert.Bar, Sound.Chimes);
Alert(ppJ_crossDN  , "ppJ_crossDN ", Alert.Bar, Sound.bell);
 
Ahhhh... I see. You got some upper chart script from somewhere and then tried to add your lower chart plots to it.
Yeah, that was never going to work.

If you want alerts, you need to use the original script and then add:
Ruby:
# To Add CrossOver Alerts to KDJ indicator
# paste the following code into the end of your study:

Alert(ppJ_crossUP , "ppJ_crossUP ", Alert.Bar, Sound.Chimes);
Alert(ppJ_crossDN  , "ppJ_crossDN ", Alert.Bar, Sound.bell);
Thanks @MerryDay....this has definitely corrected the Script & I'm back testing it now to see if the alerts are triggered correctly which I expect it will be. Thanks again as you've been #AWESOME :)
 
Status
Not open for further replies.

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
118 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top