# MTF Ichimoku and Donchian Indicators

#### tangodino

##### New member
VIP
Code:
``````#MTF Ichi Cloud
#Code by mangomick

input agg = AggregationPeriod.DAY;
input h = FundamentalType.HIGH;
input l = FundamentalType.LOW;
input tPeriod = 9;

def htenkan = highest(Fundamental(h, period = agg), tPeriod);
def ltenkan = lowest(Fundamental(l, period = agg), tPeriod);
plot tenkan = (htenkan+ltenkan)/2;

input kPeriod=26;
def hkijun = highest(Fundamental(h, period = agg), kPeriod);
def lkijun = lowest(Fundamental(l, period = agg), kPeriod);
plot kijun = (hkijun+lkijun)/2;

def Atenkan=(htenkan[26]+ltenkan[26])/2;
def Akijun=(hkijun[26]+lkijun[26])/2;
plot SpanA=(Atenkan+Akijun)/2;

input bPeriod=52;
def bhigh=highest(Fundamental(h,period=agg),bPeriod)[26];
def blow=lowest(Fundamental(l,period=agg),bPeriod)[26];
plot SpanB=(bhigh+blow)/2;

## End

## Donchian Channels
# Code by john2000

input displace = 0;
input length = 20;

plot LowerBand = Lowest(low[-displace + 0], length);
LowerBand.SetDefaultColor(GetColor(8));

plot UpperBand = Highest(high[-displace + 0], length);
UpperBand.SetDefaultColor(GetColor(8));

plot MidBand = ((UpperBand+LowerBand)/2) ;
MidBand.SetDefaultColor(GetColor(1));

## End``````

#### tangodino

##### New member
VIP
It took a few weeks of future testing but I found out the 5m Ichi Base line set at 20 equals the 5m Donchian Middle Band set at 20. Using two Donchian Channels at 10 and 20 plus a MTF at 15m Ichi cloud I've found very strong indicators if one considers the 10, 20, Tenkan and Kijun as a sort of Ribbon Mov Avg. I'm inclined to turn the clouds grey as they might throw some false signals, I want to consider them just "magnet zones of turbulence". Note RSI oversold / overbought areas as well as the 50 level crossing. Note MACD crossing on considerate level away from zero line. Note setting at 10-20-(40) across the board (ichi 9-26 and EMA 200 are not being shown).

Note Donchian upper and lower levels are NOT being shown. The Purple line is the Donchian 20 Mid channel, Blue Donchian 10 mid channel, Green 15m Tenkan, Red 15m Kijun. Consider entry at Donchian 10 Donchian 20 cross, price action donchian 10 breakout, cloud breakout, MACD cross away from zero line opposite momentum and confirm with RSI 50 cross over. Consider Stop Loss / Take Profit at swing low / high, ATR Multiple, MACD Crossing, Price Action Donchian 10 Cross or Cloud level crossing. Always at 2% and 1/1.5 RR or manually trail. Draw support and resistance at 1 hour and consider their influence on the trend. Note Chikou is not turned on either. Above code does not include Chikou for reference so I'm stuck with the 9-26, 10-20.

Any feedback would be awesome.

#### blackbeard12

##### New member
Found this script, just a regular Donchian Channel, but I was curious if anyone knew how to add an MTF option. Thank you for any help!

Code:
``````#Name:             DonchianChannel
#Programmed By:    Chris Ball ([email protected]) on 10/23/08
#Posted At:        http://chartingwithchris.blogspot.com

input length = 20;

plot upperBand = Highest(high[1], length);
plot lowerBand = Lowest(low[1], length);
plot middleBand = (upperBand + lowerBand) / 2;

upperBand.SetDefaultColor(Color.Cyan);
lowerBand.SetDefaultColor(Color.Cyan);
middleBand.SetDefaultColor(Color.Cyan);``````

##### Well-known member
VIP
@blackbeard12 TOS comes with DonchianChannels code as a standard Study already... I don't recall anyone ever attempting to make them MTF, however...

#### disturbinglymellow

##### New member
I have been following the Ichimoku study for some time now, and have decided to create an MTF study to aid in picking what I believe to be decent plays. It is currently coded to do Weekly, Daily, Hourly, and 10min, however while it displays correctly for the current chart time frame, all the higher timeframes seem to just copy the indication of the current one. In this case I am using basic 'traffic signal' labels at the top of the chart. Can someone please review my code to possibly tell me what I am doing wrong?
Thank you in advance for any assistance you may be able to provide and please, if there are any other details you need, ask away!!
Code:
``````input turning_period = 9;
input standard_period = 26;

#Ichimoku for displayed period
plot Turning = (Highest(high, turning_period) + Lowest(low, turning_period)) / 2;
plot Standard = (Highest(high, standard_period) + Lowest(low, standard_period)) / 2;
def "Span A" = (Turning[standard_period] + Standard[standard_period]) / 2;
def "Span B" = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
plot Lagging = close[-standard_period];
DefineGlobalColor("Turning", Color.GREEN);
DefineGlobalColor("Standard", Color.RED);
DefineGlobalColor("Lagging", CreateColor(102, 0, 102));
Turning.SetDefaultColor(GlobalColor("Turning"));
Standard.SetDefaultColor(GlobalColor("Standard"));
Lagging.SetLineWeight(2);
Lagging.SetDefaultColor(GlobalColor("Lagging"));
Lagging.SetLineWeight(3);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
AddCloud("Span A", "Span B", globalColor("Bullish"), globalColor("Bearish"));

# WEEK LABELS
def IC_week_close;
def IC_week_Turning;
def IC_week_Standard;
def IC_week_Lagging;
def IC_week_SpanA;
def IC_week_SpanB;
def IC_week_AboveCloud;
def IC_week_InCloud;
def IC_week_BelowCloud;
def IC_week_AggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
IC_week_AggregationPeriod = AggregationPeriod.WEEK;
IC_week_close = close(period = IC_week_AggregationPeriod);
IC_week_Turning = (Highest(high(period = IC_week_AggregationPeriod), turning_period) + Lowest(low(period = IC_week_AggregationPeriod), turning_period)) / 2;
IC_week_Standard = (Highest(high(period = IC_week_AggregationPeriod), standard_period) + Lowest(low(period = IC_week_AggregationPeriod), standard_period)) / 2;
IC_week_SpanA = (Turning[standard_period] + Standard[standard_period]) / 2;
IC_week_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_week_Lagging = close[-standard_period];

IC_week_InCloud = if ((IC_week_SpanA > IC_week_close) and (IC_week_close > IC_week_SpanB)) or ((IC_week_SpanB > IC_week_close) and (IC_week_close > IC_week_SpanA)) then 1 else Double.NaN;
IC_week_AboveCloud = if IC_week_close > IC_week_SpanA and IC_week_close > IC_week_SpanB then 1 else Double.NaN;
IC_week_BelowCloud = if IC_week_close < IC_week_SpanA and IC_week_close < IC_week_SpanB then 1 else Double.NaN;

} else {
IC_week_close = 0;
IC_week_SpanA = 0;
IC_week_SpanB = 0;
IC_week_Turning = 0;
IC_week_Standard = 0;
IC_week_Lagging = 0;
IC_week_InCloud = Double.NaN;
IC_week_AboveCloud = Double.NaN;
IC_week_BelowCloud = Double.NaN;
IC_week_AggregationPeriod = Double.NaN;
}

# DAY LABELS
def IC_day_close;
def IC_day_Turning;
def IC_day_Standard;
def IC_day_Lagging;
def IC_day_SpanA;
def IC_day_SpanB;
def IC_day_AboveCloud;
def IC_day_InCloud;
def IC_day_BelowCloud;
def IC_day_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
IC_day_AggregationPeriod = AggregationPeriod.DAY;
IC_day_close = close(period = IC_day_AggregationPeriod);
IC_day_Turning = (Highest(high(period = IC_day_AggregationPeriod), turning_period) + Lowest(low(period = IC_day_AggregationPeriod), turning_period)) / 2;
IC_day_Standard = (Highest(high(period = IC_day_AggregationPeriod), standard_period) + Lowest(low(period = IC_day_AggregationPeriod), standard_period)) / 2;
IC_day_SpanA = (Turning[standard_period] + Standard[standard_period]) / 2;
IC_day_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_day_Lagging = close[-standard_period];

IC_day_InCloud = if ((IC_day_SpanA > IC_day_close) and (IC_day_close > IC_day_SpanB)) or ((IC_day_SpanB > IC_day_close) and (IC_day_close > IC_day_SpanA)) then 1 else Double.NaN;
IC_day_AboveCloud = if IC_day_close > IC_day_SpanA and IC_day_close > IC_day_SpanB then 1 else Double.NaN;
IC_day_BelowCloud = if IC_day_close < IC_day_SpanA and IC_day_close < IC_day_SpanB then 1 else Double.NaN;

} else {
IC_day_close = 0;
IC_day_SpanA = 0;
IC_day_SpanB = 0;
IC_day_Turning = 0;
IC_day_Standard = 0;
IC_day_Lagging = 0;
IC_day_InCloud = Double.NaN;
IC_day_AboveCloud = Double.NaN;
IC_day_BelowCloud = Double.NaN;
IC_day_AggregationPeriod = Double.NaN;
}

# HOUR LABELS
def IC_hour_close;
def IC_hour_Turning;
def IC_hour_Standard;
def IC_hour_Lagging;
def IC_hour_SpanA;
def IC_hour_SpanB;
def IC_hour_AboveCloud;
def IC_hour_InCloud;
def IC_hour_BelowCloud;
def IC_hour_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
IC_hour_AggregationPeriod = AggregationPeriod.HOUR;
IC_hour_close = close(period = IC_hour_AggregationPeriod);
IC_hour_Turning = (Highest(high(period = IC_hour_AggregationPeriod), turning_period) + Lowest(low(period = IC_hour_AggregationPeriod), turning_period)) / 2;
IC_hour_Standard = (Highest(high(period = IC_hour_AggregationPeriod), standard_period) + Lowest(low(period = IC_hour_AggregationPeriod), standard_period)) / 2;
IC_hour_SpanA = (Turning[standard_period] + Standard[standard_period]) / 2;
IC_hour_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_hour_Lagging = close[-standard_period];

IC_hour_InCloud = if ((IC_hour_SpanA > IC_hour_close) and (IC_hour_close > IC_hour_SpanB)) or ((IC_hour_SpanB > IC_hour_close) and (IC_hour_close > IC_hour_SpanA)) then 1 else Double.NaN;
IC_hour_AboveCloud = if IC_hour_close > IC_hour_SpanA and IC_hour_close > IC_hour_SpanB then 1 else Double.NaN;
IC_hour_BelowCloud = if IC_hour_close < IC_hour_SpanA and IC_hour_close < IC_hour_SpanB then 1 else Double.NaN;

} else {
IC_hour_close = 0;
IC_hour_SpanA = 0;
IC_hour_SpanB = 0;
IC_hour_Turning = 0;
IC_hour_Standard = 0;
IC_hour_Lagging = 0;
IC_hour_InCloud = Double.NaN;
IC_hour_AboveCloud = Double.NaN;
IC_hour_BelowCloud = Double.NaN;
IC_hour_AggregationPeriod = Double.NaN;
}

# TEN_MIN LABELS
def IC_ten_min_close;
def IC_ten_min_Turning;
def IC_ten_min_Standard;
def IC_ten_min_Lagging;
def IC_ten_min_SpanA;
def IC_ten_min_SpanB;
def IC_ten_min_AboveCloud;
def IC_ten_min_InCloud;
def IC_ten_min_BelowCloud;
def IC_ten_min_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
IC_ten_min_AggregationPeriod = AggregationPeriod.TEN_MIN;
IC_ten_min_close = close(period = IC_ten_min_AggregationPeriod);
IC_ten_min_Turning = (Highest(high(period = IC_ten_min_AggregationPeriod), turning_period) + Lowest(low(period = IC_ten_min_AggregationPeriod), turning_period)) / 2;
IC_ten_min_Standard = (Highest(high(period = IC_ten_min_AggregationPeriod), standard_period) + Lowest(low(period = IC_ten_min_AggregationPeriod), standard_period)) / 2;
IC_ten_min_SpanA = (Turning[standard_period] + Standard[standard_period]) / 2;
IC_ten_min_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_ten_min_Lagging = close[-standard_period];

IC_ten_min_InCloud = if ((IC_ten_min_SpanA > IC_ten_min_close) and (IC_ten_min_close > IC_ten_min_SpanB)) or ((IC_ten_min_SpanB > IC_ten_min_close) and (IC_ten_min_close > IC_ten_min_SpanA)) then 1 else Double.NaN;
IC_ten_min_AboveCloud = if IC_ten_min_close > IC_ten_min_SpanA and IC_ten_min_close > IC_ten_min_SpanB then 1 else Double.NaN;
IC_ten_min_BelowCloud = if IC_ten_min_close < IC_ten_min_SpanA and IC_ten_min_close < IC_ten_min_SpanB then 1 else Double.NaN;

} else {
IC_ten_min_close = 0;
IC_ten_min_SpanA = 0;
IC_ten_min_SpanB = 0;
IC_ten_min_Turning = 0;
IC_ten_min_Standard = 0;
IC_ten_min_Lagging = 0;
IC_ten_min_InCloud = Double.NaN;
IC_ten_min_AboveCloud = Double.NaN;
IC_ten_min_BelowCloud = Double.NaN;
IC_ten_min_AggregationPeriod = Double.NaN;
}

#### disturbinglymellow

##### New member
After beating my head against the keyboard for a couple hours, I finally figured out my error. The error was in the calculation for SpanA and SpanB of each of the different time frames. Updated and working code follows:
Code:
``````input turning_period = 9;
input standard_period = 26;

#Ichimoku for displayed period
plot Turning = (Highest(high, turning_period) + Lowest(low, turning_period)) / 2;
plot Standard = (Highest(high, standard_period) + Lowest(low, standard_period)) / 2;
def "Span A" = (Turning[standard_period] + Standard[standard_period]) / 2;
def "Span B" = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
plot Lagging = close[-standard_period];
DefineGlobalColor("Turning", Color.GREEN);
DefineGlobalColor("Standard", Color.RED);
DefineGlobalColor("Lagging", CreateColor(102, 0, 102));
Turning.SetDefaultColor(GlobalColor("Turning"));
Standard.SetDefaultColor(GlobalColor("Standard"));
Lagging.SetLineWeight(2);
Lagging.SetDefaultColor(GlobalColor("Lagging"));
Lagging.SetLineWeight(3);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
AddCloud("Span A", "Span B", globalColor("Bullish"), globalColor("Bearish"));

# WEEK LABELS
def IC_week_close;
def IC_week_Turning;
def IC_week_Standard;
def IC_week_Lagging;
def IC_week_SpanA;
def IC_week_SpanB;
def IC_week_AboveCloud;
def IC_week_InCloud;
def IC_week_BelowCloud;
def IC_week_AggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
IC_week_AggregationPeriod = AggregationPeriod.WEEK;
IC_week_close = close(period = IC_week_AggregationPeriod);
IC_week_Turning = (Highest(high(period = IC_week_AggregationPeriod), turning_period) + Lowest(low(period = IC_week_AggregationPeriod), turning_period)) / 2;
IC_week_Standard = (Highest(high(period = IC_week_AggregationPeriod), standard_period) + Lowest(low(period = IC_week_AggregationPeriod), standard_period)) / 2;
IC_week_SpanA = (IC_week_Turning[standard_period] + IC_week_Standard[standard_period]) / 2;
IC_week_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_week_Lagging = close[-standard_period];

IC_week_InCloud = if ((IC_week_SpanA > IC_week_close) and (IC_week_close > IC_week_SpanB)) or ((IC_week_SpanB > IC_week_close) and (IC_week_close > IC_week_SpanA)) then 1 else Double.NaN;
IC_week_AboveCloud = if IC_week_close > IC_week_SpanA and IC_week_close > IC_week_SpanB then 1 else Double.NaN;
IC_week_BelowCloud = if IC_week_close < IC_week_SpanA and IC_week_close < IC_week_SpanB then 1 else Double.NaN;

} else {
IC_week_close = 0;
IC_week_SpanA = 0;
IC_week_SpanB = 0;
IC_week_Turning = 0;
IC_week_Standard = 0;
IC_week_Lagging = 0;
IC_week_InCloud = Double.NaN;
IC_week_AboveCloud = Double.NaN;
IC_week_BelowCloud = Double.NaN;
IC_week_AggregationPeriod = Double.NaN;
}

# DAY LABELS
def IC_day_close;
def IC_day_Turning;
def IC_day_Standard;
def IC_day_Lagging;
def IC_day_SpanA;
def IC_day_SpanB;
def IC_day_AboveCloud;
def IC_day_InCloud;
def IC_day_BelowCloud;
def IC_day_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
IC_day_AggregationPeriod = AggregationPeriod.DAY;
IC_day_close = close(period = IC_day_AggregationPeriod);
IC_day_Turning = (Highest(high(period = IC_day_AggregationPeriod), turning_period) + Lowest(low(period = IC_day_AggregationPeriod), turning_period)) / 2;
IC_day_Standard = (Highest(high(period = IC_day_AggregationPeriod), standard_period) + Lowest(low(period = IC_day_AggregationPeriod), standard_period)) / 2;
IC_day_SpanA = (IC_day_Turning[standard_period] + IC_day_Standard[standard_period]) / 2;
IC_day_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_day_Lagging = close[-standard_period];

IC_day_InCloud = if ((IC_day_SpanA > IC_day_close) and (IC_day_close > IC_day_SpanB)) or ((IC_day_SpanB > IC_day_close) and (IC_day_close > IC_day_SpanA)) then 1 else Double.NaN;
IC_day_AboveCloud = if IC_day_close > IC_day_SpanA and IC_day_close > IC_day_SpanB then 1 else Double.NaN;
IC_day_BelowCloud = if IC_day_close < IC_day_SpanA and IC_day_close < IC_day_SpanB then 1 else Double.NaN;

} else {
IC_day_close = 0;
IC_day_SpanA = 0;
IC_day_SpanB = 0;
IC_day_Turning = 0;
IC_day_Standard = 0;
IC_day_Lagging = 0;
IC_day_InCloud = Double.NaN;
IC_day_AboveCloud = Double.NaN;
IC_day_BelowCloud = Double.NaN;
IC_day_AggregationPeriod = Double.NaN;
}

# HOUR LABELS
def IC_hour_close;
def IC_hour_Turning;
def IC_hour_Standard;
def IC_hour_Lagging;
def IC_hour_SpanA;
def IC_hour_SpanB;
def IC_hour_AboveCloud;
def IC_hour_InCloud;
def IC_hour_BelowCloud;
def IC_hour_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
IC_hour_AggregationPeriod = AggregationPeriod.HOUR;
IC_hour_close = close(period = IC_hour_AggregationPeriod);
IC_hour_Turning = (Highest(high(period = IC_hour_AggregationPeriod), turning_period) + Lowest(low(period = IC_hour_AggregationPeriod), turning_period)) / 2;
IC_hour_Standard = (Highest(high(period = IC_hour_AggregationPeriod), standard_period) + Lowest(low(period = IC_hour_AggregationPeriod), standard_period)) / 2;
IC_hour_SpanA = (IC_hour_Standard[standard_period] + IC_hour_Standard[standard_period]) / 2;
IC_hour_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_hour_Lagging = close[-standard_period];

IC_hour_InCloud = if ((IC_hour_SpanA > IC_hour_close) and (IC_hour_close > IC_hour_SpanB)) or ((IC_hour_SpanB > IC_hour_close) and (IC_hour_close > IC_hour_SpanA)) then 1 else Double.NaN;
IC_hour_AboveCloud = if IC_hour_close > IC_hour_SpanA and IC_hour_close > IC_hour_SpanB then 1 else Double.NaN;
IC_hour_BelowCloud = if IC_hour_close < IC_hour_SpanA and IC_hour_close < IC_hour_SpanB then 1 else Double.NaN;

} else {
IC_hour_close = 0;
IC_hour_SpanA = 0;
IC_hour_SpanB = 0;
IC_hour_Turning = 0;
IC_hour_Standard = 0;
IC_hour_Lagging = 0;
IC_hour_InCloud = Double.NaN;
IC_hour_AboveCloud = Double.NaN;
IC_hour_BelowCloud = Double.NaN;
IC_hour_AggregationPeriod = Double.NaN;
}

# TEN_MIN LABELS
def IC_ten_min_close;
def IC_ten_min_Turning;
def IC_ten_min_Standard;
def IC_ten_min_Lagging;
def IC_ten_min_SpanA;
def IC_ten_min_SpanB;
def IC_ten_min_AboveCloud;
def IC_ten_min_InCloud;
def IC_ten_min_BelowCloud;
def IC_ten_min_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
IC_ten_min_AggregationPeriod = AggregationPeriod.TEN_MIN;
IC_ten_min_close = close(period = IC_ten_min_AggregationPeriod);
IC_ten_min_Turning = (Highest(high(period = IC_ten_min_AggregationPeriod), turning_period) + Lowest(low(period = IC_ten_min_AggregationPeriod), turning_period)) / 2;
IC_ten_min_Standard = (Highest(high(period = IC_ten_min_AggregationPeriod), standard_period) + Lowest(low(period = IC_ten_min_AggregationPeriod), standard_period)) / 2;
IC_ten_min_SpanA = (IC_ten_min_Turning[standard_period] + IC_ten_min_Standard[standard_period]) / 2;
IC_ten_min_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_ten_min_Lagging = close[-standard_period];

IC_ten_min_InCloud = if ((IC_ten_min_SpanA > IC_ten_min_close) and (IC_ten_min_close > IC_ten_min_SpanB)) or ((IC_ten_min_SpanB > IC_ten_min_close) and (IC_ten_min_close > IC_ten_min_SpanA)) then 1 else Double.NaN;
IC_ten_min_AboveCloud = if IC_ten_min_close > IC_ten_min_SpanA and IC_ten_min_close > IC_ten_min_SpanB then 1 else Double.NaN;
IC_ten_min_BelowCloud = if IC_ten_min_close < IC_ten_min_SpanA and IC_ten_min_close < IC_ten_min_SpanB then 1 else Double.NaN;

} else {
IC_ten_min_close = 0;
IC_ten_min_SpanA = 0;
IC_ten_min_SpanB = 0;
IC_ten_min_Turning = 0;
IC_ten_min_Standard = 0;
IC_ten_min_Lagging = 0;
IC_ten_min_InCloud = Double.NaN;
IC_ten_min_AboveCloud = Double.NaN;
IC_ten_min_BelowCloud = Double.NaN;
IC_ten_min_AggregationPeriod = Double.NaN;
}

#### royalrock

##### New member
Can i use this on 5 or 1 min chart?

i am on D chart and W label is in yellow..but when I go to W chart, then W becomes green which is correct.

#### Mkirk

##### New member
VIP
After beating my head against the keyboard for a couple hours, I finally figured out my error. The error was in the calculation for SpanA and SpanB of each of the different time frames. Updated and working code follows:
Code:
``````input turning_period = 9;
input standard_period = 26;

#Ichimoku for displayed period
plot Turning = (Highest(high, turning_period) + Lowest(low, turning_period)) / 2;
plot Standard = (Highest(high, standard_period) + Lowest(low, standard_period)) / 2;
def "Span A" = (Turning[standard_period] + Standard[standard_period]) / 2;
def "Span B" = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
plot Lagging = close[-standard_period];
DefineGlobalColor("Turning", Color.GREEN);
DefineGlobalColor("Standard", Color.RED);
DefineGlobalColor("Lagging", CreateColor(102, 0, 102));
Turning.SetDefaultColor(GlobalColor("Turning"));
Standard.SetDefaultColor(GlobalColor("Standard"));
Lagging.SetLineWeight(2);
Lagging.SetDefaultColor(GlobalColor("Lagging"));
Lagging.SetLineWeight(3);
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
AddCloud("Span A", "Span B", globalColor("Bullish"), globalColor("Bearish"));

# WEEK LABELS
def IC_week_close;
def IC_week_Turning;
def IC_week_Standard;
def IC_week_Lagging;
def IC_week_SpanA;
def IC_week_SpanB;
def IC_week_AboveCloud;
def IC_week_InCloud;
def IC_week_BelowCloud;
def IC_week_AggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
IC_week_AggregationPeriod = AggregationPeriod.WEEK;
IC_week_close = close(period = IC_week_AggregationPeriod);
IC_week_Turning = (Highest(high(period = IC_week_AggregationPeriod), turning_period) + Lowest(low(period = IC_week_AggregationPeriod), turning_period)) / 2;
IC_week_Standard = (Highest(high(period = IC_week_AggregationPeriod), standard_period) + Lowest(low(period = IC_week_AggregationPeriod), standard_period)) / 2;
IC_week_SpanA = (IC_week_Turning[standard_period] + IC_week_Standard[standard_period]) / 2;
IC_week_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_week_Lagging = close[-standard_period];

IC_week_InCloud = if ((IC_week_SpanA > IC_week_close) and (IC_week_close > IC_week_SpanB)) or ((IC_week_SpanB > IC_week_close) and (IC_week_close > IC_week_SpanA)) then 1 else Double.NaN;
IC_week_AboveCloud = if IC_week_close > IC_week_SpanA and IC_week_close > IC_week_SpanB then 1 else Double.NaN;
IC_week_BelowCloud = if IC_week_close < IC_week_SpanA and IC_week_close < IC_week_SpanB then 1 else Double.NaN;

} else {
IC_week_close = 0;
IC_week_SpanA = 0;
IC_week_SpanB = 0;
IC_week_Turning = 0;
IC_week_Standard = 0;
IC_week_Lagging = 0;
IC_week_InCloud = Double.NaN;
IC_week_AboveCloud = Double.NaN;
IC_week_BelowCloud = Double.NaN;
IC_week_AggregationPeriod = Double.NaN;
}

# DAY LABELS
def IC_day_close;
def IC_day_Turning;
def IC_day_Standard;
def IC_day_Lagging;
def IC_day_SpanA;
def IC_day_SpanB;
def IC_day_AboveCloud;
def IC_day_InCloud;
def IC_day_BelowCloud;
def IC_day_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.DAY {
IC_day_AggregationPeriod = AggregationPeriod.DAY;
IC_day_close = close(period = IC_day_AggregationPeriod);
IC_day_Turning = (Highest(high(period = IC_day_AggregationPeriod), turning_period) + Lowest(low(period = IC_day_AggregationPeriod), turning_period)) / 2;
IC_day_Standard = (Highest(high(period = IC_day_AggregationPeriod), standard_period) + Lowest(low(period = IC_day_AggregationPeriod), standard_period)) / 2;
IC_day_SpanA = (IC_day_Turning[standard_period] + IC_day_Standard[standard_period]) / 2;
IC_day_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_day_Lagging = close[-standard_period];

IC_day_InCloud = if ((IC_day_SpanA > IC_day_close) and (IC_day_close > IC_day_SpanB)) or ((IC_day_SpanB > IC_day_close) and (IC_day_close > IC_day_SpanA)) then 1 else Double.NaN;
IC_day_AboveCloud = if IC_day_close > IC_day_SpanA and IC_day_close > IC_day_SpanB then 1 else Double.NaN;
IC_day_BelowCloud = if IC_day_close < IC_day_SpanA and IC_day_close < IC_day_SpanB then 1 else Double.NaN;

} else {
IC_day_close = 0;
IC_day_SpanA = 0;
IC_day_SpanB = 0;
IC_day_Turning = 0;
IC_day_Standard = 0;
IC_day_Lagging = 0;
IC_day_InCloud = Double.NaN;
IC_day_AboveCloud = Double.NaN;
IC_day_BelowCloud = Double.NaN;
IC_day_AggregationPeriod = Double.NaN;
}

# HOUR LABELS
def IC_hour_close;
def IC_hour_Turning;
def IC_hour_Standard;
def IC_hour_Lagging;
def IC_hour_SpanA;
def IC_hour_SpanB;
def IC_hour_AboveCloud;
def IC_hour_InCloud;
def IC_hour_BelowCloud;
def IC_hour_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.HOUR {
IC_hour_AggregationPeriod = AggregationPeriod.HOUR;
IC_hour_close = close(period = IC_hour_AggregationPeriod);
IC_hour_Turning = (Highest(high(period = IC_hour_AggregationPeriod), turning_period) + Lowest(low(period = IC_hour_AggregationPeriod), turning_period)) / 2;
IC_hour_Standard = (Highest(high(period = IC_hour_AggregationPeriod), standard_period) + Lowest(low(period = IC_hour_AggregationPeriod), standard_period)) / 2;
IC_hour_SpanA = (IC_hour_Standard[standard_period] + IC_hour_Standard[standard_period]) / 2;
IC_hour_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_hour_Lagging = close[-standard_period];

IC_hour_InCloud = if ((IC_hour_SpanA > IC_hour_close) and (IC_hour_close > IC_hour_SpanB)) or ((IC_hour_SpanB > IC_hour_close) and (IC_hour_close > IC_hour_SpanA)) then 1 else Double.NaN;
IC_hour_AboveCloud = if IC_hour_close > IC_hour_SpanA and IC_hour_close > IC_hour_SpanB then 1 else Double.NaN;
IC_hour_BelowCloud = if IC_hour_close < IC_hour_SpanA and IC_hour_close < IC_hour_SpanB then 1 else Double.NaN;

} else {
IC_hour_close = 0;
IC_hour_SpanA = 0;
IC_hour_SpanB = 0;
IC_hour_Turning = 0;
IC_hour_Standard = 0;
IC_hour_Lagging = 0;
IC_hour_InCloud = Double.NaN;
IC_hour_AboveCloud = Double.NaN;
IC_hour_BelowCloud = Double.NaN;
IC_hour_AggregationPeriod = Double.NaN;
}

# TEN_MIN LABELS
def IC_ten_min_close;
def IC_ten_min_Turning;
def IC_ten_min_Standard;
def IC_ten_min_Lagging;
def IC_ten_min_SpanA;
def IC_ten_min_SpanB;
def IC_ten_min_AboveCloud;
def IC_ten_min_InCloud;
def IC_ten_min_BelowCloud;
def IC_ten_min_AggregationPeriod;
if GetAggregationPeriod() <= AggregationPeriod.TEN_MIN {
IC_ten_min_AggregationPeriod = AggregationPeriod.TEN_MIN;
IC_ten_min_close = close(period = IC_ten_min_AggregationPeriod);
IC_ten_min_Turning = (Highest(high(period = IC_ten_min_AggregationPeriod), turning_period) + Lowest(low(period = IC_ten_min_AggregationPeriod), turning_period)) / 2;
IC_ten_min_Standard = (Highest(high(period = IC_ten_min_AggregationPeriod), standard_period) + Lowest(low(period = IC_ten_min_AggregationPeriod), standard_period)) / 2;
IC_ten_min_SpanA = (IC_ten_min_Turning[standard_period] + IC_ten_min_Standard[standard_period]) / 2;
IC_ten_min_SpanB = (Highest(high[standard_period], 2 * standard_period) + Lowest(low[standard_period], 2 * standard_period)) / 2;
IC_ten_min_Lagging = close[-standard_period];

IC_ten_min_InCloud = if ((IC_ten_min_SpanA > IC_ten_min_close) and (IC_ten_min_close > IC_ten_min_SpanB)) or ((IC_ten_min_SpanB > IC_ten_min_close) and (IC_ten_min_close > IC_ten_min_SpanA)) then 1 else Double.NaN;
IC_ten_min_AboveCloud = if IC_ten_min_close > IC_ten_min_SpanA and IC_ten_min_close > IC_ten_min_SpanB then 1 else Double.NaN;
IC_ten_min_BelowCloud = if IC_ten_min_close < IC_ten_min_SpanA and IC_ten_min_close < IC_ten_min_SpanB then 1 else Double.NaN;

} else {
IC_ten_min_close = 0;
IC_ten_min_SpanA = 0;
IC_ten_min_SpanB = 0;
IC_ten_min_Turning = 0;
IC_ten_min_Standard = 0;
IC_ten_min_Lagging = 0;
IC_ten_min_InCloud = Double.NaN;
IC_ten_min_AboveCloud = Double.NaN;
IC_ten_min_BelowCloud = Double.NaN;
IC_ten_min_AggregationPeriod = Double.NaN;
}
I'm getting a couple errors on this, could you supply tos share, please. Thank You.

##### Well-known member
VIP
@Mkirk What errors are you getting and in what timeframes...??? I Copied and Pasted the code in your post and it works as expected until the timeframe is beyond HOUR but that is how the script is written... It is intended to be able to display HOUR, DAY, and WEEK, meaning it will throw an error on timeframes beyond 1H...

#### Mkirk

##### New member
VIP
@Mkirk What errors are you getting and in what timeframes...??? I Copied and Pasted the code in your post and it works as expected until the timeframe is beyond HOUR but that is how the script is written... It is intended to be able to display HOUR, DAY, and WEEK, meaning it will throw an error on timeframes beyond 1H...
It was just a couple minor errors that turned red in code so I never got to put it on chart. I recopied it and it is working. Thanks.

#### disturbinglymellow

##### New member
I'm getting a couple errors on this, could you supply tos share, please. Thank You.
@Mkirk Very sorry but I just saw this. It seems you got it to work though.

#### disturbinglymellow

##### New member
Can i use this on 5 or 1 min chart?

i am on D chart and W label is in yellow..but when I go to W chart, then W becomes green which is correct.
@royalrock I have not found a way to resolve this issue. What is happening is the Week dots extend off to the right under the cloud and I have not figured out a way to stop this. Also, as there is no price action there since it hasn't happened yet, the script simply outputs a yellow dot. Yes, I could code it to do something different, but when the nuances are understood, I didn't feel it was that big if an issue. But to answer your main question, yes you can use all the way down to the TICK chart if you wanted, but IMO not much value is added as Ichimoku is considered to be more of a longer term indicator. Some would argue that you shouldn't use it on TF less than 1H.

#### Investingtogive

##### New member
VIP
Does anyone have code that will display the Ichimoku Clouds from Multiple Time Frames on one chart ? For example, on a 2 min chart, display the Ichimoku Clouds from the 10 min, 1 hour and Daily charts.
Just wanted to check in before I tackle this task.

Thanks,

##### Well-known member
VIP
@Investingtogive Did you use the search feature to look for "mtf ichimoku"...??? Please make it a habit to do so before asking questions...

#### Investingtogive

##### New member
VIP
@rad14733 I did search first and found this thread, but I was looking to actually plot the clouds from different time frames onto one chart. I was able to write the code and get it to work. Thanks.