Need help extending lines on Ichimoku Cloud

Intriquality

New member
Hello!

I'm trying to make an Ichimoku Cloud (SPAN B) support/resistance line drawer, but I'm unsure how to extend the lines to the right.

The indicator looks for flat areas (flat over at least a 20-bar period) on the SPAN B portion of the Ichimoku Cloud and draws the line there.

My amazing, unparalleled display of scripting prowess (sarcasm) is displayed below.

This is what the indicator is trying to do:

lines1.png

This is what I have it looking like so far:

lines2.png


This is what I'm trying to turn it into:

lines3.png



I also have a secondary, less important issue of this indicator not working on any timeframe higher than the 1D. Not sure why.

Here's the script:

declare upper;
def kijun_period = 26;

def dP = aggregationPeriod.DAY;
def wP = aggregationPeriod.WEEK;
def mP = aggregationPeriod.MONTH;

def dKijun = (Highest(high (period=dP), kijun_period) + Lowest(low (period=dP), kijun_period)) / 2;
def span_B = (Highest(high (period=dP)[kijun_period], 2 * kijun_period) + Lowest(low (period=dP)[kijun_period], 2 * kijun_period)) / 2;

def dailyCloudLineB = if span_B[-16] == span_B[-17] and
span_B[-17] == span_B[-18] and
span_B[-18] == span_B[-19] and
span_B[-19] == span_B[-20] and
span_B[-20] == span_B[-21] and
span_B[-21] == span_B[-22] and
span_B[-22] == span_B[-23] and
span_B[-23] == span_B[-24] and
span_B[-24] == span_B[-25] and
span_B[-25] == span_B[-26]
then span_B[-26] else double.NAN;

plot daily = dailyCloudLineB[16];

#----------------------------WEEKLY CLOUDLINES
def wKijun = (Highest(high (period=wP), kijun_period) + Lowest(low (period=wP), kijun_period)) / 2;
def wSpan_B = (Highest(high (period=wP)[kijun_period], 2 * kijun_period) + Lowest(low (period=wP)[kijun_period], 2 * kijun_period)) / 2;

def weeklyCloudLineB = if wSpan_B[-16] == wSpan_B[-17] and
wSpan_B[-17] == wSpan_B[-18] and
wSpan_B[-18] == wSpan_B[-19] and
wSpan_B[-19] == wSpan_B[-20] and
wSpan_B[-20] == wSpan_B[-21] and
wSpan_B[-21] == wSpan_B[-22] and
wSpan_B[-22] == wSpan_B[-23] and
wSpan_B[-23] == wSpan_B[-24] and
wSpan_B[-24] == wSpan_B[-25] and
wSpan_B[-25] == wSpan_B[-26]
then wSpan_B[-26] else double.NAN;

plot weekly = weeklyCloudLineB[16];

#----------------------------MONTHLY CLOUDLINES
def mKijun = (Highest(high (period=mP), kijun_period) + Lowest(low (period=mP), kijun_period)) / 2;
def mSpan_B = (Highest(high (period=mP)[kijun_period], 2 * kijun_period) + Lowest(low (period=mP)[kijun_period], 2 * kijun_period)) / 2;

def monthlyCloudLineB = if mSpan_B[-20] == mSpan_B[-21] and
mSpan_B[-21] == mSpan_B[-22] and
mSpan_B[-22] == mSpan_B[-23] and
mSpan_B[-23] == mSpan_B[-24] and
mSpan_B[-24] == mSpan_B[-25] and
mSpan_B[-25] == mSpan_B[-26]
then mSpan_B[-26] else double.NAN;

plot monthly = monthlyCloudLineB[16];
 
Solution
Hello!

I'm trying to make an Ichimoku Cloud (SPAN B) support/resistance line drawer, but I'm unsure how to extend the lines to the right.

The indicator looks for flat areas (flat over at least a 20-bar period) on the SPAN B portion of the Ichimoku Cloud and draws the line there.

My amazing, unparalleled display of scripting prowess (sarcasm) is displayed below.

This is what the indicator is trying to do:

View attachment 20686
This is what I have it looking like so far:

View attachment 20687

This is what I'm trying to turn it into:

View attachment 20688


I also have a secondary, less important issue of this indicator not working on any timeframe higher than the 1D. Not sure why.

Here's the script:

Here are 3 versions, one for each timeframe.
Each...
Hello!

I'm trying to make an Ichimoku Cloud (SPAN B) support/resistance line drawer, but I'm unsure how to extend the lines to the right.

The indicator looks for flat areas (flat over at least a 20-bar period) on the SPAN B portion of the Ichimoku Cloud and draws the line there.

My amazing, unparalleled display of scripting prowess (sarcasm) is displayed below.

This is what the indicator is trying to do:

View attachment 20686
This is what I have it looking like so far:

View attachment 20687

This is what I'm trying to turn it into:

View attachment 20688


I also have a secondary, less important issue of this indicator not working on any timeframe higher than the 1D. Not sure why.

Here's the script:

Here are 3 versions, one for each timeframe.
Each has a minimum flat line length that you can change at the input screen.
The lines will plot from the point when the minimum length is met to the right edge. This was done with the script() function, as a plot is necessary for each line when the condition is met. I
This has 4 plots for each version, with bubbles. You can create more using the logic of he 4 lines.

You can load all 3 versions on a Daily chart.
The reason you did not get any plots when going to timeframes higher than a Daily is because your loaded studies can not include any lower timeframes than the chart timeframe. So the Daily chart being loaded on a Weekly or Monthly chart will cause none of the scripts to plot.

The image shows all 3 versions in the upper pane. The middle and lower have the individual Weekly and Monthly loaded.

You weee very creative and did nice work in your scrript. These scripts use a little different method. Hope this helps.

Screenshot 2024-01-27 162225.png
Code:
#SpanB_Daily

script db {
    input back = 1;
    input dP   = AggregationPeriod.DAY;
    input dlength     = 20;
    def kijun_period = 26;
    def B = CompoundValue(1, (Highest(high(period = dP)[kijun_period], 2 * kijun_period) + Lowest(low(period = dP)[kijun_period], 2 * kijun_period)) / 2, high(period = dP));
    def count = if B != B[1] then 0 else if B == B[-1] or B == B[1] then count[1] + 1 else count[1];
    def basis = if count == dlength and B then basis[1] + 1 else basis[1];
    def cond  = HighestAll(basis) - basis + 1;
    def output = if IsNaN(close) then output[1] else if cond[1] == back + 1 and cond == back then GetValue(B, 1) else output[1];
    plot dx = output;
}

DefineGlobalColor("D", Color.CYAN);

input dlength = 20;
plot d1 = db(1, dlength = dlength);
plot d2 = db(2, dlength = dlength);
plot d3 = db(3, dlength = dlength);
plot d4 = db(4, dlength = dlength);

d1.SetPaintingStrategy(PaintingStrategy.DASHES);
d2.SetPaintingStrategy(PaintingStrategy.DASHES);
d3.SetPaintingStrategy(PaintingStrategy.DASHES);
d4.SetPaintingStrategy(PaintingStrategy.DASHES);

d1.SetDefaultColor(GlobalColor("D"));
d2.SetDefaultColor(GlobalColor("D"));
d3.SetDefaultColor(GlobalColor("D"));
d4.SetDefaultColor(GlobalColor("D"));

input bubbles     = yes;
input bubblemover = 1;
def   mover  = bubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);


AddChartBubble(mover, d1[bubblemover], "D1", d1.TakeValueColor());
AddChartBubble(mover, d2[bubblemover], "D2", d2.TakeValueColor());
AddChartBubble(mover, d3[bubblemover], "D3", d3.TakeValueColor());
AddChartBubble(mover, d4[bubblemover], "D4", d4.TakeValueColor());

#

Code:
#SpanB_Weekly

script wb {
    input wback = 1;
    input  wP    = AggregationPeriod.WEEK;
    input wlength  = 10;
    def kijun_period = 26;
    def Bw = CompoundValue(1, (Highest(high(period = wP)[kijun_period], 2 * kijun_period) + Lowest(low(period = wP)[kijun_period], 2 * kijun_period)) / 2, high(period = wP));
    def wcount = if Bw != Bw[1] then 0 else if Bw == Bw[-1] or Bw == Bw[1] then wcount[1] + 1 else wcount[1];
    def wbasis = if wcount == wlength then wbasis[1] + 1 else wbasis[1];
    def wcond  = HighestAll(wbasis) - wbasis + 1;
    def woutput = if IsNaN(close) then woutput[1] else if wcond[1] == wback + 1 and wcond == wback then Bw else woutput[1];
    plot wx = woutput;
}

DefineGlobalColor("W", Color.MAGENTA);
input wlength = 10;
plot w1 = wb(1, wlength = wlength);
plot w2 = wb(2, wlength = wlength);
plot w3 = wb(3, wlength = wlength);
plot w4 = wb(4, wlength = wlength);

w1.SetPaintingStrategy(PaintingStrategy.DASHES);
w2.SetPaintingStrategy(PaintingStrategy.DASHES);
w3.SetPaintingStrategy(PaintingStrategy.DASHES);
w4.SetPaintingStrategy(PaintingStrategy.DASHES);

w1.SetDefaultColor(GlobalColor("W"));
w2.SetDefaultColor(GlobalColor("W"));
w3.SetDefaultColor(GlobalColor("W"));
w4.SetDefaultColor(GlobalColor("W"));

input bubbles     = yes;
input bubblemover = 1;
def   mover  = bubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);


AddChartBubble(mover, w1[bubblemover], "W1", w1.TakeValueColor());
AddChartBubble(mover, w2[bubblemover], "W2", w2.TakeValueColor());
AddChartBubble(mover, w3[bubblemover], "W3", w3.TakeValueColor());
AddChartBubble(mover, w4[bubblemover], "W4", w4.TakeValueColor());

#

Code:
#SpanB_Monthly

script mb {
    input mback = 1;
    input  mP    = AggregationPeriod.month;
    input mlength  = 5;
    def kijun_period = 26;
    def Bm = CompoundValue(1, (Highest(high(period = mP)[kijun_period], 2 * kijun_period) + Lowest(low(period = mP)[kijun_period], 2 * kijun_period)) / 2, high(period = mP));
    def mcount = if Bm != Bm[1] then 0 else if Bm == Bm[-1] or Bm == Bm[1] then mcount[1] + 1 else mcount[1];
    def mbasis = if mcount == mlength then mbasis[1] + 1 else mbasis[1];
    def mcond  = HighestAll(mbasis) - mbasis + 1;
    def moutput = if IsNaN(close) then moutput[1] else if mcond[1] == mback + 1 and mcond == mback then Bm else moutput[1];
    plot mx = moutput;
}

DefineGlobalColor("M", Color.yellow);
input mlength = 5;
plot m1 = mb(1, mlength = mlength);
plot m2 = mb(2, mlength = mlength);
plot m3 = mb(3, mlength = mlength);
plot m4 = mb(4, mlength = mlength);

m1.SetPaintingStrategy(PaintingStrategy.DASHES);
m2.SetPaintingStrategy(PaintingStrategy.DASHES);
m3.SetPaintingStrategy(PaintingStrategy.DASHES);
m4.SetPaintingStrategy(PaintingStrategy.DASHES);

m1.SetDefaultColor(GlobalColor("M"));
m2.SetDefaultColor(GlobalColor("M"));
m3.SetDefaultColor(GlobalColor("M"));
m4.SetDefaultColor(GlobalColor("M"));

input bubbles     = yes;
input bubblemover = 1;
def   mover  = bubbles and IsNaN(close[bubblemover]) and !IsNaN(close[bubblemover + 1]);

AddChartBubble(mover, m1[bubblemover], "M1", m1.TakeValueColor());
AddChartBubble(mover, m2[bubblemover], "M2", m2.TakeValueColor());
AddChartBubble(mover, m3[bubblemover], "M3", m3.TakeValueColor());
AddChartBubble(mover, m4[bubblemover], "M4", m4.TakeValueColor());

#
 
Last edited:
Solution

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

Here are 3 versions, one for each timeframe.
Each has a minimum flat line length that you can change at the input screen.
The lines will plot from the point when the minimum length is met to the right edge. This was done with the script() function, as a plot is necessary for each line when the condition is met. I
This has 4 plots for each version, with bubbles. You can create more using the logic of he 4 lines.

You can load all 3 versions on a Daily chart.
The reason you did not get any plots when going to timeframes higher than a Daily is because your loaded studies can not include any lower timeframes than the chart timeframe. So the Daily chart being loaded on a Weekly or Monthly chart will cause none of the scripts to plot.

The image shows all 3 versions in the upper pane. The middle and lower have the individual Weekly and Monthly loaded.

You weee very creative and did nice work in your scrript. These scripts use a little different method. Hope this helps.
This is AMAZING. Thank you! I've been playing with it and it is VERY close to what I am looking for. It's a huge improvement from what I made - being able to see the lines extended across the chart.

I have noticed a couple of things that I need to try and figure out:

-The indicator doesn't seem to work if you use it on a timeframe that displays a timeframe longer than where the ichimoku cloud first started. For example, if you look at the ticker DRIP and display a timeframe of WEEKLY / 10 YEARS, then the indicator simply won't display.

-The indicator doesn't seem to plot the "forward-looking" portion of the Ichimoku cloud. Areas like the one in the image below don't seem to be accounted for in the code.

1706460435166.png


-This indicator doesn't seem to have much use on intraday timeframes like the 5M, because apparently, you need to have the timeframe showing as far back as the indicator is attempting to draw the line (so if you want to see a weekly line that is based on a datapoint from 4 years ago, you would need 4 years of 5M charts, which sadly ToS doesn't let you do. I'm not sure you'd want to do that anyway, since loading 4 years of 5M charts would make it super sluggish.

Not sure how difficult it would be to fix the first two issues. All that being said, this is still a SUPER nice tool for the daily chart. Without any changes, I already love the capability of this indicator. Hopefully, some improved iterations come out of this in the future!

Thanks again for your hard work!
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
274 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