B4 ATR Ichimoku

Chuck

Moderator
Staff member
Platform
  1. Thinkorswim
  2. TradingView
Ichimoku on smaller timeframes often gives less reliable signals due to spikes in the market. In order to increase the ratio of winning signals on lower timeframes as well as on larger timeframes, one needs to filter only the zones of the volatile market. There are a number of indicators for this, but the Average True Range is considered to be one of the simplest and most effective.

ATR shows the change in asset volatility without taking into account the direction of price movement. If the market is in a flat state, the indicator shows low values, and the indicator begins to grow sharply at the beginning of a trend. Oftentimes, the ATR is at its maximum values at the end of the trend, which is associated with panic on the exchange.

To combat lower timeframe ichimoku inefficiency we have combined it with ATR to help filter out false signals by utilizing volatility.
Combining ATR with Ichimoku allows us to harness areas of volatility and obtain trend direction in a very effective manner.

In short, combining ATR and the Ichimoku begets high efficiency.

Enjoy!

Code:
# B4 ATR Ichimoku
#
# Join us at: https://discord.gg/TveydqPWDF
# v1.0 - barbaros

input tenkan_period = 9;
input tenkan_mult = 2.0;
input kijun_period = 26;
input kijun_mult = 4.0;
input spanB_period = 52;
input spanB_mult = 6.0;
input showCloud = yes;

script _avg {
    input src = close;
    input length = 9;
    input mult = 2;

    def _atr = ATR(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 src crosses spt then Max(src, _max[1]) else if os == 1 then Max(src, _max[1]) else spt;
    def _min = if src crosses spt then Min(src, _min[1]) else if os == 0 then Min(src, _min[1]) else spt;

    plot return = (_max + _min) / 2;
}


plot Tenkan = _avg(close, tenkan_period, tenkan_mult);
plot Kijun = _avg(close, kijun_period, kijun_mult);
#plot TKCrossUp = if Tenkan crosses above Kijun then Kijun else Double.NaN;
#plot TKCrossDown = if Tenkan crosses below Kijun then Kijun else Double.NaN;
plot TKCrossUp = Tenkan crosses above Kijun;
plot TKCrossDown = Tenkan crosses below Kijun;

def senkouA = (kijun + tenkan) / 2;
def senkouB = _avg(close,spanB_period,spanB_mult);

Tenkan.SetDefaultColor(Color.CYAN);
Tenkan.SetLineWeight(2);
Tenkan.HideBubble();
Tenkan.HideTitle();

Kijun.SetDefaultColor(Color.MAGENTA);
Kijun.SetLineWeight(2);
Kijun.HideBubble();
Kijun.HideTitle();

TKCrossUp.SetDefaultColor(Color.CYAN);
TKCrossUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
TKCrossUp.SetLineWeight(3);
TKCrossUp.HideBubble();
TKCrossUp.HideTitle();

TKCrossDown.SetDefaultColor(Color.MAGENTA);
TKCrossDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
TKCrossDown.SetLineWeight(3);
TKCrossDown.HideBubble();
TKCrossDown.HideTitle();

AddCloud(if showCloud then senkouA[spanB_period] else Double.NaN, if showCloud then senkouB[spanB_period] else Double.NaN, color.GREEN, color.RED);
UByNcHS.png
 
Last edited:

barbaros

Administrator
Staff member
Added candle colors.

Code:
# B4 ATR Ichimoku
#
# Join us at: https://discord.gg/TveydqPWDF
#
# v1.0 - barbaros
# v1.1 - barbaros - candle colors

input tenkan_period = 9;
input tenkan_mult = 2.0;
input kijun_period = 26;
input kijun_mult = 4.0;
input spanB_period = 52;
input spanB_mult = 6.0;
input showCloud = yes;
input colorBars = yes;

DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);

script _avg {
    input src = close;
    input length = 9;
    input mult = 2;

    def _atr = ATR(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 src crosses spt then Max(src, _max[1]) else if os == 1 then Max(src, _max[1]) else spt;
    def _min = if src crosses spt then Min(src, _min[1]) else if os == 0 then Min(src, _min[1]) else spt;

    plot return = (_max + _min) / 2;
}


plot Tenkan = _avg(close, tenkan_period, tenkan_mult);
plot Kijun = _avg(close, kijun_period, kijun_mult);
plot TKCrossUp = Tenkan crosses above Kijun;
plot TKCrossDown = Tenkan crosses below Kijun;

def Direction = if TKCrossUp then 1 else if TKCrossDown then -1 else Direction[1];

def senkouA = (kijun + tenkan) / 2;
def senkouB = _avg(close,spanB_period,spanB_mult);

Tenkan.SetDefaultColor(Color.CYAN);
Tenkan.SetLineWeight(2);
Tenkan.HideBubble();
Tenkan.HideTitle();

Kijun.SetDefaultColor(Color.MAGENTA);
Kijun.SetLineWeight(2);
Kijun.HideBubble();
Kijun.HideTitle();

TKCrossUp.SetDefaultColor(Color.CYAN);
TKCrossUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
TKCrossUp.SetLineWeight(3);
TKCrossUp.HideBubble();
TKCrossUp.HideTitle();

TKCrossDown.SetDefaultColor(Color.MAGENTA);
TKCrossDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
TKCrossDown.SetLineWeight(3);
TKCrossDown.HideBubble();
TKCrossDown.HideTitle();

AddCloud(if showCloud then senkouA[spanB_period] else Double.NaN, if showCloud then senkouB[spanB_period] else Double.NaN, GlobalColor("Bullish"), GlobalColor("Bearish"));

AssignPriceColor(if !colorBars then Color.CURRENT
    else if Direction == 1 then GlobalColor("Bullish")
    else if Direction == -1 then GlobalColor("Bearish")
    else Color.GRAY);
 
Last edited:

barbaros

Administrator
Staff member
Here it is for TradingView.

Code:
//@version=5
indicator("B4 ATR Ichimoku",'B4 ATR Ichimoku', overlay=true, max_lines_count=500)

tenkan_len  = input(9,'Tenkan',inline='tenkan')
tenkan_mult = input(2.,'',inline='tenkan')

kijun_len   = input(26,'Kijun',inline='kijun')
kijun_mult  = input(4.,'',inline='kijun')

spanB_len   = input(52,'Senkou Span B ',inline='span')
spanB_mult  = input(6.,'',inline='span')

offset      = input(26,'Displacement')

avg(src,length,mult)=>
    atr = ta.atr(length)*mult
    up = hl2 + atr
    dn = hl2 - atr
    upper = 0.,lower = 0.
    upper := src[1] < upper[1] ? math.min(up,upper[1]) : up
    lower := src[1] > lower[1] ? math.max(dn,lower[1]) : dn
    
    os = 0,max = 0.,min = 0.
    os := src > upper ? 1 : src < lower ? 0 : os[1]
    spt = os == 1 ? lower : upper
    max := ta.cross(src,spt) ? math.max(src,max[1]) : os == 1 ? math.max(src,max[1]) : spt
    min := ta.cross(src,spt) ? math.min(src,min[1]) : os == 0 ? math.min(src,min[1]) : spt
    math.avg(max,min)


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

senkouA = math.avg(kijun,tenkan)
senkouB = avg(close,spanB_len,spanB_mult)

TKCrossUp = ta.crossover(tenkan,kijun)
TKCrossDown = ta.crossunder(tenkan,kijun)

Direction = 0
Direction := TKCrossUp ? 1 : TKCrossDown ? -1 : Direction[1]

plot(tenkan, 'Tenkan', #2157f3)
plot(kijun, 'Kijun', #ff5d00)

plotshape(TKCrossUp, title="Buy Signal", text="Buy", style=shape.labelup, location=location.belowbar, color=#00FF00, textcolor=#000000, size=size.normal)
plotshape(TKCrossDown, title="Sell Signal", text="Sell", style=shape.labeldown, location=location.abovebar, color=#FF0000, textcolor=#FFFFFF, size=size.normal)

A = plot(senkouA, 'Span A', na, offset=offset-1)
B = plot(senkouB, 'Span B', na, offset=offset-1)

fill(A, B, senkouA > senkouB ? color.new(#00FF00, 80) : color.new(#FF0000, 80))

barcolor(Direction == 1 ? #00FF00 : Direction == -1 ? #FF0000 : color.gray)
 

barbaros

Administrator
Staff member
Update to ToS

Code:
# B4 ATR Ichimoku
#
# # This software is licensed for individual use only.
# NOT FOR REDISTRIBUTION PRIVATE/CONFIDENTIAL
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
#
# v1.0 - barbaros
# v1.1 - barbaros - candle colors

input tenkan_period = 9;
input tenkan_mult = 2.0;
input kijun_period = 26;
input kijun_mult = 4.0;
input spanB_period = 52;
input spanB_mult = 6.0;
input showCloud = yes;
input colorBars = yes;

DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);

script _avg {
    input src = close;
    input length = 9;
    input mult = 2;

    def _atr = ATR(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 src crosses spt then Max(src, _max[1]) else if os == 1 then Max(src, _max[1]) else spt;
    def _min = if src crosses spt then Min(src, _min[1]) else if os == 0 then Min(src, _min[1]) else spt;

    plot return = (_max + _min) / 2;
}


plot Tenkan = _avg(close, tenkan_period, tenkan_mult);
plot Kijun = _avg(close, kijun_period, kijun_mult);
plot TKCrossUp = Tenkan crosses above Kijun;
plot TKCrossDown = Tenkan crosses below Kijun;

def Direction = if TKCrossUp then 1 else if TKCrossDown then -1 else Direction[1];

def senkouA = (kijun + tenkan) / 2;
def senkouB = _avg(close,spanB_period,spanB_mult);

Tenkan.SetDefaultColor(Color.CYAN);
Tenkan.SetLineWeight(2);
Tenkan.HideBubble();
Tenkan.HideTitle();

Kijun.SetDefaultColor(Color.MAGENTA);
Kijun.SetLineWeight(2);
Kijun.HideBubble();
Kijun.HideTitle();

TKCrossUp.SetDefaultColor(Color.CYAN);
TKCrossUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
TKCrossUp.SetLineWeight(3);
TKCrossUp.HideBubble();
TKCrossUp.HideTitle();

TKCrossDown.SetDefaultColor(Color.MAGENTA);
TKCrossDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
TKCrossDown.SetLineWeight(3);
TKCrossDown.HideBubble();
TKCrossDown.HideTitle();

AddCloud(if showCloud then senkouA[spanB_period] else Double.NaN, if showCloud then senkouB[spanB_period] else Double.NaN, GlobalColor("Bullish"), GlobalColor("Bearish"));

AssignPriceColor(if !colorBars then Color.CURRENT
    else if Direction == 1 and close > Kijun then GlobalColor("Bullish")
    else if Direction == -1 and close < Kijun then GlobalColor("Bearish")
    else Color.GRAY);
 

lovetotrade

New member
Update to ToS

Code:
# B4 ATR Ichimoku
#
# # This software is licensed for individual use only.
# NOT FOR REDISTRIBUTION PRIVATE/CONFIDENTIAL
# Copyright (c) 2021 B4 Signals
#
# Get support at: https://b4signals.com
#
# v1.0 - barbaros
# v1.1 - barbaros - candle colors

input tenkan_period = 9;
input tenkan_mult = 2.0;
input kijun_period = 26;
input kijun_mult = 4.0;
input spanB_period = 52;
input spanB_mult = 6.0;
input showCloud = yes;
input colorBars = yes;

DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);

script _avg {
    input src = close;
    input length = 9;
    input mult = 2;

    def _atr = ATR(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 src crosses spt then Max(src, _max[1]) else if os == 1 then Max(src, _max[1]) else spt;
    def _min = if src crosses spt then Min(src, _min[1]) else if os == 0 then Min(src, _min[1]) else spt;

    plot return = (_max + _min) / 2;
}


plot Tenkan = _avg(close, tenkan_period, tenkan_mult);
plot Kijun = _avg(close, kijun_period, kijun_mult);
plot TKCrossUp = Tenkan crosses above Kijun;
plot TKCrossDown = Tenkan crosses below Kijun;

def Direction = if TKCrossUp then 1 else if TKCrossDown then -1 else Direction[1];

def senkouA = (kijun + tenkan) / 2;
def senkouB = _avg(close,spanB_period,spanB_mult);

Tenkan.SetDefaultColor(Color.CYAN);
Tenkan.SetLineWeight(2);
Tenkan.HideBubble();
Tenkan.HideTitle();

Kijun.SetDefaultColor(Color.MAGENTA);
Kijun.SetLineWeight(2);
Kijun.HideBubble();
Kijun.HideTitle();

TKCrossUp.SetDefaultColor(Color.CYAN);
TKCrossUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
TKCrossUp.SetLineWeight(3);
TKCrossUp.HideBubble();
TKCrossUp.HideTitle();

TKCrossDown.SetDefaultColor(Color.MAGENTA);
TKCrossDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
TKCrossDown.SetLineWeight(3);
TKCrossDown.HideBubble();
TKCrossDown.HideTitle();

AddCloud(if showCloud then senkouA[spanB_period] else Double.NaN, if showCloud then senkouB[spanB_period] else Double.NaN, GlobalColor("Bullish"), GlobalColor("Bearish"));

AssignPriceColor(if !colorBars then Color.CURRENT
    else if Direction == 1 and close > Kijun then GlobalColor("Bullish")
    else if Direction == -1 and close < Kijun then GlobalColor("Bearish")
    else Color.GRAY);
 

lovetotrade

New member
Great job @barbaros , this system look amazing, i tested for swing and day trading, do you think is possible to make MTF? multi time frame? also the scan? thank you in advance..
 

barbaros

Administrator
Staff member
The one here doesn’t repaint. Whenever you do any MTF reference, it will repaint in ToS when you are looking at it live. However, the severity of repaint depends on the indicator. This one is easy to make MTF. May be I’ll post a beta later today so you can test.
 

lovetotrade

New member
The one here doesn’t repaint. Whenever you do any MTF reference, it will repaint in ToS when you are looking at it live. However, the severity of repaint depends on the indicator. This one is easy to make MTF. May be I’ll post a beta later today so you can test.
thank you @barbaros .. will be nice if you use red/green dot on the lower study. you are so great!
 

lovetotrade

New member
Thanks buddy. Hat do you mean by lower study?
thank you for your response... what i mean is the multi time frame indicator should be in the bottom of the charts, just like the one you did it for me the supertrend... just like that look. thanks in advance.
 

barbaros

Administrator
Staff member
thank you for your response... what i mean is the multi time frame indicator should be in the bottom of the charts, just like the one you did it for me the supertrend... just like that look. thanks in advance.
Got it. When I switch the sources to another timeframe, it won’t plot. Will need more time to debug.
 
Top