Tenkan and Kijun Candle Painting

Gv27347

New member
VIP
Can someone help me with this?
Have a candle coloring strategy
There should be an input on whether to color the candles yes/no
1) Candles are green if it closes above Tenkan and Kijun is below the Tenkan
2) Candles are orange if it closes in between Kijun and Tenkan
3) Candles are red if it closes below Tenkan and the Kijun is above the Tenkan

@samer800 or anyone else on this forum
https://usethinkscript.com/threads/superichi-lux-for-thinkorswim.17454/
Code:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0
#// © LuxAlgo
#indicator("SuperIchi [LUX]",'SuperIchi [LUX]',overlay=true,max_lines_count=500)
# Converted by Sam4Cok@Samer800 - 06/2022

input tenkan_len   = 9;    #'Tenkan????????
input kijun_len    = 26;   #'Kijun???????????
input spanB_len    = 52;   #'Senkou Span B?',inline='span')
input Displacement = 26;   #'Displacement')
input tenkan_mult  = 2.0;  # tenkan
input kijun_mult   = 4.0;  #' kijun
input spanB_mult   = 6.0;  #'span')
input UseSmooth    = no;
input TenkanLine   = yes;
input KijunLine    = yes;
input ChikouLine   = no;
input Cloud        = yes;

def na = Double.NaN;

#//------------------------------------------------------------------------------
DefineGlobalColor("tenkan",  CreateColor(33 , 87 , 243));
DefineGlobalColor("kijun",   CreateColor(255, 93 , 0  ));
DefineGlobalColor("cloudUP", CreateColor(0  , 128, 128));
DefineGlobalColor("cloudDN", CreateColor(239, 83 , 80 ));
DefineGlobalColor("chikou",  CreateColor(123, 31 , 162));
#//------------------------------------------------------------------------------

script avg {
  input src = close;
  input length = 9;
  input mult   = 2;
    def atr = ATR(LENGTH = length) * mult;
    def up = hl2 + atr;
    def dn = hl2 - atr;
    def upper = if src[1] < upper[1] then Min(up, upper[1]) else up;
    def lower = if src[1] > lower[1] then Max(dn, lower[1]) else dn;
    def os  = if src > upper then 1 else if src < lower then 0 else os[1];
    def spt = if os == 1 then lower else upper;
    def max = if Crosses(src, spt) then Max(src, max[1]) else if os == 1 then Max(src, max[1]) else spt;
    def min = if Crosses(src, spt) then Min(src, min[1]) else if os == 0 then Min(src, min[1]) else spt;
    def value = (max + min) / 2;
    plot return = value;
}
#//------------------------------------------------------------------------------

def tenkan = avg(close, tenkan_len, tenkan_mult);
def kijun  = avg(close, kijun_len , kijun_mult );

plot tenkan1 = if TenkanLine then tenkan else Na;
plot kijun1  = if KijunLine  then kijun  else Na;
plot Chikou  = if ChikouLine and UseSmooth then EhlersSuperSmootherFilter(close[-Displacement + 1]) else
               if ChikouLine then close[-Displacement + 1] else Na;

def senkouA1 = (kijun + tenkan) / 2 ;
def senkouB1 = avg(close, spanB_len, spanB_mult);

def senkouA = senkouA1[Displacement - 1];
def senkouB = senkouB1[Displacement - 1];

#//------------------------------------------------------------------------------

tenkan1.SetPaintingStrategy(PaintingStrategy.LINE);
tenkan1.SetLineWeight(2);
tenkan1.SetDefaultColor(GlobalColor("tenkan"));

kijun1.SetPaintingStrategy(PaintingStrategy.LINE);
kijun1.SetLineWeight(2);
kijun1.SetDefaultColor(GlobalColor("kijun"));

Chikou.SetPaintingStrategy(PaintingStrategy.LINE);
Chikou.SetLineWeight(1);
Chikou.SetDefaultColor(GlobalColor("Chikou"));

plot DotUP = if tenkan crosses above kijun then kijun else Na;
DotUP.SetPaintingStrategy(PaintingStrategy.SQUARES);
DotUP.SetDefaultColor(GlobalColor("tenkan"));
DotUP.SetLineWeight(3);

plot DotDN = if tenkan crosses below kijun then kijun else Na;
DotDN.SetPaintingStrategy(PaintingStrategy.SQUARES);
DotDN.SetDefaultColor(GlobalColor("kijun"));
DotDN.SetLineWeight(3);

AddCloud (if Cloud then senkouA else Na, senkouB, GlobalColor("cloudUP"), GlobalColor("cloudDN"));

#-- END of CODE
 
Last edited by a moderator:
Solution
Add this to the bottom of your script:
Ruby:
# ==== Candle Coloring Add-On ====
input paintCandles = yes;  # Toggle candle coloring on/off

def isGreen = close > tenkan and kijun < tenkan;
def isOrange = (close > Min(tenkan, kijun)) and (close < Max(tenkan, kijun));
def isRed = close < tenkan and kijun > tenkan;

AssignPriceColor(if !paintCandles then Color.CURRENT else if isGreen then Color.GREEN else if isOrange then Color.ORANGE else if isRed then Color.RED else Color.GRAY);
Add this to the bottom of your script:
Ruby:
# ==== Candle Coloring Add-On ====
input paintCandles = yes;  # Toggle candle coloring on/off

def isGreen = close > tenkan and kijun < tenkan;
def isOrange = (close > Min(tenkan, kijun)) and (close < Max(tenkan, kijun));
def isRed = close < tenkan and kijun > tenkan;

AssignPriceColor(if !paintCandles then Color.CURRENT else if isGreen then Color.GREEN else if isOrange then Color.ORANGE else if isRed then Color.RED else Color.GRAY);
 
Solution

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
294 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