Ichimoku For ThinkOrSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Not sure how many people on here use the Ichimoku indicator, but I thought I share this list just in case. Here are a few different Ichimoku scanners for ThinkorSwim.

Ichimoku Cloud Scan by Linus

Code:
# Ichimoku cloud scan

input nTe = 9;  # Tenkan length
input nKi = 26; # Kijun length
input nSp = 52; # SpanB length
def Tenkan = (Highest(high, nTe) + Lowest(low, nTe)) / 2;
def Kijun = (Highest(high, nKi) + Lowest(low, nKi)) / 2;
def SpanA = (Tenkan[nKi] + Kijun[nKi]) / 2;
def SpanB = (Highest(high[nKi], nSp) + Lowest(low[nKi], nSp)) / 2;

# The cloud is made up of SpanA and SpanB, so use Max and Min to scan above and below the cloud.  Only one plot can be active in the scan, so comment out the plot not being used with #.

#plot IsAboveCloud = low > Max(SpanA, SpanB);
plot IsBelowCloud = high < Min(SpanA, SpanB);

A compilation of other related scanners:
https://tos.mx/wq9kYL – Ichimoku Break Above the Cloud – 5 Minute Chart
https://tos.mx/d7340d – Ichimoku Break Below the Cloud – 5 Minute Chart
https://tos.mx/30fZt5 – Ichimoku Chikou Line Crosses Above The Cloud
https://tos.mx/uOwZmL – Ichimoku Chiko Line Crosses Below The Cloud
https://tos.mx/GSfZab – Ichimoku 3 candles above the cloud
https://tos.mx/HnAeox – Ichimoku 3 candles above the cloud
https://tos.mx/0WReVp – Ichimoku 2 candles below the cloud
https://tos.mx/yGwahs – Ichimoku 3 candles below the cloud – click for the thinkorswim downloads
https://tos.mx/QZU8Rn – Ichimoku inside the cloud daily
https://tos.mx/iFlKxM – Ichimoku inside the cloud houry
https://tos.mx/CP91iY – Ichimoku inside the cloud 10 min
https://tos.mx/WZBbqo – Ichimoku T crossabove K Daily
https://tos.mx/PlVCiY – Ichimoku – Ichimoku T crossabove K 10 min
https://tos.mx/rkGFAn – Ichimoku T crossabove K 1 hour
 
Hi Ben, How do you read these in terms of bullish vs. bearish?

Code:
# Ichimoku Tenkan/Kijun an early exit warning study_StanL
#the preferred version is version 2 because the arrows accurately show the START of a HA dowtrend
#Now version 2.1

#hint:This is a Ichimoku Tenkan/Kijun an early exit warning study that plots the difference between the tenkan and kijun in histogram format. A YELLOW down warning arrow plots when a Heikin Ashi downtrend starts.
#Background:The difference of the Tenkan and the Kijun indicate the strength of this bullish signal as shown by the histogram above zero values. When this strength difference weakens a downward trend may(often?) start. Heikin Ashi candles are adept at showing trend development. The plotted YELLOW arrows are points to consider exiting even though the entity may be in buillsh territory(i.e. above the cloud). In summary, this is an early warning signal that is productive and calls your attention to it to consider exiting.
#USAGE:When YELLOW down arrows are present, watch the Heikin Ashi style candles to see the extent of the downtrend.(Configure your Heikin Ashi for 'Red Fill' when down. The DMI_Oscillator, MACD and ADX are good complementary studies
#SUMMARY: The histograqm shows  the change in strength of the bullish T/K signal while the YELLOW arrows call your attention to a possible start of a downtrend.

#TOS Title = Ichi_TK_Exit_Warning
# Version date = 5/17/14 by StanL, version 2
# Revision 2.1, added dots at the zero line 5/18/14

declare lower;
input Show_HA_Down = YES;#hint HA_Down:Toggles (ON/OFF) HA-Down-candle arrows showing the start of a HA-Down series. View the HA chart style to see the length of the down series.
#input Show_HA_Up = YES;#hint HA_Up:Toggles (ON/OFF) HA-Up-candle arrows showing the start of a HA-Up series. View the HA chart style to see the length of the up series.
plot Diff = Ichimoku().tenkan - Ichimoku().kijun;
plot ZeroLine = 0;

Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up") else Diff.Color("Positive and Down") else if Diff < Diff[1] then Diff.Color("Negative and Down") else Diff.Color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
plot HistoLiner = Diff;
HistoLiner.SetDefaultColor(Color.WHITE);
HistoLiner.SetPaintingStrategy(PaintingStrategy.LINE);
HistoLiner.SetLineWeight(1);
#################################################
#def HAopen = (open[1] + close[1]) / 2;
#def HAhigh = Max(high, close[1]);
#def HAlow = Min(low, close[1]);
#def HAclose = (open + high + low + close) / 4;


AddLabel(1, "Plot of Tenkan - Kijun early warning of T/K strength weakening", Color.WHITE);
AddLabel(1, "A YELLOW down arrow plots at the start of a HA downtrend.Watch the HA style chart candles to see the length of the downtrend", Color.YELLOW);

#######################################
### Extracted Mobius Heikin Ashi code #
#######################################
input Begin = 0000;

# Higher Aggregation
def barSeq = if SecondsTillTime(Begin) == 0 and
                   SecondsFromTime(Begin) == 0
                then 0
                else barSeq[1] + 1;
def agg = GetAggregationPeriod();
def BarsPerHour = 60 / (agg / 1000 / 60);
def bar = barSeq;
def barCount = if bar % BarsPerHour == 0
                  then bar
                  else Double.NaN;
def barCountOpen  = if !IsNaN(barCount)
                       then open
                       else barCountOpen[1];
def barCountHigh  = if IsNaN(barCount) and
                          high > barCountHigh[1]
                       then high
                       else if !IsNaN(barCount)
                       then high
                       else barCountHigh[1];
def barCountLow   = if IsNaN(barCount) and
                          low < barCountLow[1]
                       then low
                       else if !IsNaN(barCount)
                       then low
                       else barCountLow[1];
def barCountClose = if !IsNaN(barCount)
                       then close[1]
                       else barCountClose[1];
def HAopen_EV = Round(if HAopen_EV[1] == 0
                      then barCountOpen
                      else (HAopen_EV[1] + barCountClose[1]) / 2 /
                            TickSize(), 0) * TickSize();
def HAclose_EV = Round(if HAopen_EV[1] == 0
                        then OHLC4
                        else (barCountOpen + barCountHigh + barCountLow + HAopen_EV[1])
                              / 4 / TickSize(), 0) * TickSize();
def HAhigh_EV = Round(Max(barCountHigh, barCountClose[1]) /
                      TickSize(), 0) * TickSize();
def HAlow_EV = Round(Min(barCountLow, barCountClose[1]) /
                     TickSize(), 0) * TickSize();
# Color Block For Higher Aggregation
def Size = AbsValue(HAopen_EV - HAopen_EV);
def Block = CompoundValue(1, if HAopen_EV > Block[1] + Size[1]
                                then Block[1] + Size
                                else if HAopen_EV < Block[1] - Size[1]
                                then Block[1] - Size
                                else Block[1] , barCountClose);

plot cond1_EV = Block;
cond1_EV.Hide();
def cond2_EV = if Block != Block[1]
               then Block[1]
               else cond2_EV[1];

plot Block2 = cond2_EV;
Block2.Hide();

#  AssignPriceColor(if HAclose < HAopen
#                   then Color.Red
#                   else Color.Green);

# Trade Management Conditions
def Bcond = CompoundValue(1, if HAclose_EV crosses above HAopen_EV
               then Bcond[1] + 1
               else if HAclose_EV crosses below HAopen_EV
               then 0
               else Bcond[1], 0);

#UP arrow is the start of an HA-up series.  Need to view HA Chart style to see the extent & end
#plot ArrowUp = if Bcond crosses above 0 && Show_HA_Up && Diff < 0 then HistoLiner[0] else Double.NaN;# this line used when up HA arrows are implemented
plot ArrowUp = if Bcond crosses above 0 && Diff < 0 then HistoLiner[0] else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetLineWeight(5);
ArrowUp.SetDefaultColor(Color.YELLOW);

def Scond = CompoundValue(1, if HAclose_EV crosses below HAopen_EV
               then Scond[1] + 1
               else if barCountClose crosses above HAopen_EV
               then 0
               else Scond[1], 0);

#DOWN arrow is the start of an HA-down series. Need to view HA Chart style to see the extent & end
plot ArrowDn = if Scond crosses above 0 && Show_HA_Down && Diff > 0
                 then HistoLiner[0]
                 else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetLineWeight(5);
ArrowDn.SetDefaultColor(Color.YELLOW);

def lineCond = if ArrowUp < ArrowDn
               then 1
               else if ArrowDn > ArrowUp
               then 1
               else -1;

plot line = if IsNaN(ArrowUp)
              then ArrowDn - (TickSize() * 2)
              else ArrowUp + (TickSize() * 2);
line.EnableApproximation();
line.SetLineWeight(2);
line.SetStyle(Curve.SHORT_DASH);
line.AssignValueColor(if lineCond == 1                   
                             then Color.GREEN
                             else if lineCond == -1
                             then Color.RED
                             else Color.WHITE);

######## define dot on zero line when above the cloud ######
def IsAboveCloud = if close > Ichimoku()."Span A" && close > Ichimoku()."Span B" then 1 else 0; # close is above the cloud
def IsBelowCloud = if close < Ichimoku()."Span A" && close < Ichimoku()."Span B" then 1 else 0; # close is below the cloud
Plot AboveCloudDot = if IsAboveCloud then 0 else double.nan;
AboveCloudDot.SetPaintingStrategy(PaintingStrategy.POINTS);
AboveCloudDot.SetLineWeight(3);
AboveCloudDot.SetDefaultColor(Color.GREEN);

Plot BelowCloudDot = if IsBelowCloud then 0 else double.nan;
BelowCloudDot.SetPaintingStrategy(PaintingStrategy.POINTS);
BelowCloudDot.SetLineWeight(3);
BelowCloudDot.SetDefaultColor(Color.RED);

#Define variables used to place a bubble
#========================================
def barNum = BarNumber();
def FirstBar = if barNum == 1 then 1 else 0;
#==========================================
AddChartBubble(FirstBar, 0, "GREEN dot = close IS ABOVE CLOUD\nRED dot = close IS BELOW CLOUD", Color.PINK,no);
#---- End Of Code ---
 
Thanks!! @BenTen

Code:
input nTe = 9;  # Tenkan length
input nKi = 26; # Kijun length
input nSp = 52; # SpanB length
def Tenkan = (Highest(high, nTe) + Lowest(low, nTe)) / 2;
def Kijun = (Highest(high, nKi) + Lowest(low, nKi)) / 2;
def SpanA = (Tenkan[nKi] + Kijun[nKi]) / 2;
def SpanB = (Highest(high[nKi], nSp) + Lowest(low[nKi], nSp)) / 2;

def X = Tenkan * .10;
plot scan = absvalue(close - Tenkan) is less than or equal to X ;

HAHAHA, YAS. Decided to give it another shot and play around with the original code you gave me. I FINALLY got it to work for the specific thing I had in mind. I know it's elementary but I am a complete noob when it comes to this. I can't stress how happy I was when I finally executed the code with no problem!

Will backtest and share a strategy for y'all soon!
 
Hey Ben, great Ichimoku Cloud Scanner!!! Plugged into TOS and works good! Quick question: can you modify it to show only those results with 3 bars ago. In other words, this will limit it to those breakouts that have recently happened and will allow you to quickly jump in the trade from the beginning. The other scanner scripts that have been posted don't work...Thanks in advance!
 
Does anyone know how to tweak the code for the Ichimoku Cloud so that I can change the colors of the cloud? Not the lines outlining the cloud, but the cloud itself which is red and yellow by default. Thanks very much in advance!
 
Last edited:
Think ToS ichimoku is a locked study. So first copy the whole code to a new study. Then change colors here.

Code:
DefineGlobalColor("Bullish", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);
 
Hey @BenTen ! I have a couple quick questions. is there a difference between the two "3 candles above the cloud" scans? Also for those scans TOS says "Add label" must be taken out so does that make the scan miss anything important?
 
Think ToS ichimoku is a locked study. So first copy the whole code to a new study. Then change colors here.
DefineGlobalColor("Bullish", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);
Thank you horserider! This worked perfectly!
 
I think the biggest problem is coming from that Chikou line. It doesn't seem to like to scan for the negative number in code that looks like close[-displace].
 
Hello Everyone, I'm trying to add a custom alert (other than bell, chime, ding or chimes) to this script I found in the thinkscript Onedrive. Any help would be greatly appreciated. Thank you.

Code:
# Adaptation of Ichimoku Strategy
# Mobius
# Revised Tenkan and Kijun
# V01.12.2013

input nA = 8;
input nB = 21;

#math
def Tenkan = (Highest(high, nA) + Lowest(low, nA)) / 2;
def Kijun = (Highest(high, nB) + Lowest(low, nB)) / 2;
def "Span A" = (Tenkan[nA] + Kijun[nA]) / 2;
def "Span B" = (Highest(high[nA], nB) + Lowest(low[nA], nB)) / 2;

plot Chikou = Inertia(close[-nA], nB);

# Color Config
#"Span A".SetDefaultColor(Color.PLUM);
#"Span B".SetDefaultColor(Color.YELLOW);
Chikou.SetDefaultColor(Color.WHITE);
DefineGlobalColor("Bullish", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);

#AddCloud("Span A", "Span B", GlobalColor("Bullish"), GlobalColor("Bearish"));
##Arrows on Chikou Crossover
# changed from crosses above to >
plot ArrowUp = Chikou crosses above Max("Span A", "Span B");
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetLineWeight(1);
ArrowUp.SetDefaultColor(Color.WHITE);

# changed from crosses below to <
plot ArrowDn = Chikou crosses below Min("Span A", "Span B");
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDn.SetLineWeight(1);
ArrowDn.SetDefaultColor(Color.YELLOW);
 
Add this to the end of your script:

Code:
# Alerts
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDn, " ", Alert.Bar, Sound.Bell);
 
@british43 Yes, but that is using a different setting/method. I don't know if it is compatible with this sort of indicator, though. If anything, you can go to MarketWatch > Alerts and see if you can find anything.

wPd4v25.png
 
Hi guys, need help in code the following 2 ichimoku scans

Bullish Scan

Conditions:
  • Current closing price breaks above Kumo
  • Current closing price above Tenkan and Tenkan above Kijun
  • Chikou free or clear from any price interaction (meaning the chikou is not within the interference of any candles)
  • Future kumo is bullish
Bearish Scan

Conditions:
  • Current closing price breaks below Kumo
  • Current closing price below Tenkan and Tenkan below Kijun
  • Chikou free or clear from any price interaction (meaning the chikou is not within the interference of any candles)
  • Future kumo is bearish
Thank you so much
 
I am testing this study out and so far I have not seen the arrows re-paint. This is on a one minute chart. Just curious, is anyone aware of a similar scan?

--Correcting myself, in watching this more today I have seen a signal fire and then more than one price bar later disappear from the chart. To me that is a re-paint, but that is just me.
 
Last edited:

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