Ichimoku Oscillator [LonesomeTheBlue] For ThinkOrSwim

apdusp

Active member
VIP
The author states:
This is Ichimoku Oscillator that creates different oscillator layers, calculates the trend and possible entry/exit levels by using Ichimoku Cloud features.

There are four layer:
First layer is the distance between closing price and cloud (min or max, depending on the main trend)
Second layer is the distance between Lagging and Cloud X bars ago (X: the displacement)
Third layer is the distance between Conversion and Base lines
Fourth layer is the distance between both Leadlines
If all layers are visible maning that positive according to the main trend, you can take long/short position and when main trend changed then you should close the position. so it doesn't mean you can take position when main trend changed, you need to wait for all other conditions met (all layers(
there is take profit partially option. if Conversion and base lines cross then you can take profit partially. Optionally you can take profit partially when EMA line crosses Fourth layer.

Optionally ATR (average true range) is used for Conversion and baseline for protection from whipsaws. you can use it to stay on the trend longer time.
EnjkmwD.png


Would you consider converting this TV indicator, leaving to enough room to be able to set scanning filters?
As I see it adds an interesting quantification approach at the visual Ichimoku
thanks in advance

https://www.tradingview.com/script/ypZ7TSjN-Ichimoku-Oscillator/
 
Last edited by a moderator:

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

Would you consider converting this TV indicator, leaving to enough room to be able to set scanning filters?
As I see it adds an interesting quantification approach at the visual Ichimoku
thanks in advance

https://www.tradingview.com/script/ypZ7TSjN-Ichimoku-Oscillator/
check the below.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © LonesomeTheBlue
#indicator(title="Ichimoku Oscillator", shorttitle="IO", explicit_plot_zorder = true)
# Converted by Sam4Cok@Samer800    - 02/2024
declare lower;

input conversionPeriods = 8;    # "Conversion Line Length"
input basePeriods = 13;         # "Base Line Length"
input LeadingSpanBLength = 26;  # "Leading Span B Length"
input LaggingSpan = 13;         # "Lagging Span"
input useAtr = yes;             # "Use ATR", tooltip = "Protection from Whipsaw"
input atrLen = 9;               # "?Length"
input atrMul = 2.0;             # "?Mult",
input EnableBounceOff = no;     # "Bounce Off Support/Resistance"
input useEma = yes;             # "Show EMA"
input emaLen = 9;               # "?Length"
input TakePartialProfitByEma = yes;
input ColoredBackground = yes;  # "Colored Background"


def na = Double.NaN;
def last = isNaN(close);

#-- Colors
DefineGlobalColor("upcol1", CreateColor(0 , 250, 0)); # "Uptrend Colors"
DefineGlobalColor("upcol2", CreateColor(0 , 190, 0));
DefineGlobalColor("upcol3", CreateColor(0 , 130, 0));
DefineGlobalColor("upcol4", CreateColor(0 , 70, 0));
DefineGlobalColor("dbcol1", CreateColor(250, 0, 0)); # "Downtrend Colors"
DefineGlobalColor("dbcol2", CreateColor(190, 0, 0));
DefineGlobalColor("dbcol3", CreateColor(130, 0, 0));
DefineGlobalColor("dbcol4", CreateColor(70, 0, 0));
DefineGlobalColor("inSRcol", CreateColor(209,212,220));
DefineGlobalColor("emacol", CreateColor(209,196,233));

#// ichimoku calculation
script donchian {
    input len = 9;
    def hh = Highest(high, len);
    def ll = Lowest(low, len);
    def donchian = (ll + hh) / 2;
    plot out = donchian;
}
def conversionLine = donchian(conversionPeriods);
def baseLine = donchian(basePeriods);
def leadLine1 = (conversionLine + baseLine) / 2;
def leadLine2 = donchian(LeadingSpanBLength);
#// Oscillator calculation
def cloudup = leadLine1 >= leadLine2;
def clouddn = leadLine1 <= leadLine2;
def CloudMin = Min(leadLine1[LaggingSpan - 1], leadLine2[LaggingSpan - 1]);
def CloudMax = Max(leadLine1[LaggingSpan - 1], leadLine2[LaggingSpan - 1]);
def inthecloud = close >= CloudMin and close <= CloudMax;
def mtrd = if close > CloudMax then 1 else if close < CloudMin then -1 else mtrd[1];
def mTrend = if isNaN(mtrd) then 0 else mtrd;

#// first layer
def Oscline = if mtrend == 1 then (close - CloudMin) else (close - CloudMax);

#//second layer
def Lagging = Oscline + (if mtrend == 1 then Max(close - CloudMax[LaggingSpan - 1], 0) else
                                             Min(close - CloudMin[LaggingSpan - 1], 0));
#//third layer
def ConvBase = Lagging + (if mtrend == 1 then Max((conversionLine - baseLine), 0) else Min((conversionLine - baseLine), 0));
#// fourth layer
def cloud = ConvBase + (if mtrend == 1 then Max(leadLine1 - leadLine2, 0) else Min(leadLine1 - leadLine2, 0));

def anyofthemrising  = (conversionLine - conversionLine[1]) > 0 or (baseLine - baseLine[1]) > 0;
def anyofthemfalling = (conversionLine - conversionLine[1]) < 0 or (baseLine - baseLine[1]) < 0;
def convoverbase = conversionLine >= baseLine;
def baseoverconv = conversionLine <= baseLine;
#// little Protection from whipsaw
def tole = if useatr then ATR(Length = atrlen) * atrmul else 0;

#// calculation of the trend and getting entry level if trend appears
def entrylevel;
def preTrend;
def trend;
if mtrend == 1 {
    preTrend = if mtrend[1] == -1 then 0 else trend[1];
    if preTrend < 4 and close > CloudMax {
        trend = (if Lagging > Oscline then 1 else 0) +
                 (if convoverbase and anyofthemrising then 1 else 0) +
                 (if cloudup then 1 else 0) + 1;
        entrylevel = if trend == 4 then close else entrylevel[1];
    } else {
        trend = (if conversionLine < baseLine - tole then 0 else  preTrend);
        entrylevel = entrylevel[1];
    }
} else if mtrend == -1 {
    preTrend = if mtrend[1] == 1 then 0 else trend[1];
    if preTrend > - 4 and close < CloudMin {
        trend = (if Lagging < Oscline then -1 else 0) -
                (if baseoverconv and anyofthemfalling then 1 else 0) -
                (if clouddn then 1 else 0) - 1;
        entrylevel = if trend == -4 then close else entrylevel[1];
    } else {
        trend = (if conversionLine > baseLine + tole then 0 else preTrend);
        entrylevel = entrylevel[1];
    }
} else {
    preTrend = preTrend[1];
    trend    = if last then na else preTrend;
    entrylevel = entrylevel[1];
}

#// Background coloring if Enabled
def dir = if !isNaN(trend) then trend else 0;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def uptmult = 159 + power(trend, 3);
def dntmult = 159 - power(trend, 3);

def trendExtUp = (dir > 2) or (dir[1] > 2);
def trendExtDn = (dir <-2) or (dir[1] <-2);
def trendUp = (dir > 0) or (dir[1] > 0);
def trendDn = (dir < 0) or (dir[1] < 0);

AddCloud(if ColoredBackground then if trendExtUp then pos else na else na, neg, Color.DARK_GREEN);
AddCloud(if ColoredBackground then if trendExtDn then pos else na else na, neg, Color.DARK_RED);
AddCloud(if ColoredBackground then if trendUp then pos else na else na, neg, GlobalColor("upcol4"));
AddCloud(if ColoredBackground then if trendDn then pos else na else na, neg, GlobalColor("dbcol4"));

#/ ploting layers
def area = cloud;
def baseArea = ConvBase;
def lagLine = Lagging;
def oscArea = Oscline;

def ConvBaseCol = if conversionLine >= baseLine then 1 else - 1;#? upcol3 : dbcol3
def lagCol = if close > CloudMax then 1 else if close < CloudMin then -1 else 0;
def Osccolor = if inthecloud then 0 else if close > CloudMax then 1 else -1;#? upcol1 : dbcol1

AddCloud(if Osccolor==0 or Osccolor[1] == 0 then oscArea else na, 0, GlobalColor("inSRcol"), GlobalColor("inSRcol"), yes);
AddCloud(if Osccolor > 0 or Osccolor[1] > 0 then oscArea else na, 0, GlobalColor("upcol1"), GlobalColor("upcol1"), yes);
AddCloud(if Osccolor < 0 or Osccolor[1] < 0 then oscArea else na, 0, GlobalColor("dbcol1"), GlobalColor("dbcol1"), yes);

AddCloud(if lagCol > 0 or lagCol[1] > 0 then lagLine else na, 0, GlobalColor("upcol2"), GlobalColor("upcol2"), yes);
AddCloud(if lagCol < 0 or lagCol[1] < 0 then lagLine else na, 0, GlobalColor("dbcol2"), GlobalColor("dbcol2"), yes);
AddCloud(if ConvBaseCol > 0 or ConvBaseCol[1] > 0 then baseArea else na, 0, GlobalColor("upcol3"), GlobalColor("upcol3"), yes);
AddCloud(if ConvBaseCol < 0 or ConvBaseCol[1] < 0 then baseArea else na, 0, GlobalColor("dbcol3"), GlobalColor("dbcol3"), yes);
AddCloud(area, 0, GlobalColor("upcol4"), GlobalColor("dbcol4"));

#// closing main position
def closetrade = (trend-trend[1]) != 0 and AbsValue(trend[1]) == 4;
plot closeShape = if closetrade then cloud else na;
closeShape.SetPaintingStrategy(PaintingStrategy.SQUARES);
closeShape.AssignValueColor(if trend[1] > 0 then Color.WHITE else Color.YELLOW);

#// take long position
def uptrend = trend == 4 and (trend-trend[1]) != 0;
plot LongShape = if uptrend then 0 else na;
LongShape.SetLineWeight(2);
LongShape.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LongShape.SetDefaultColor(Color.CYAN);

def bouncbackup = EnableBounceOff and trend == 4 and close > CloudMax and inthecloud[1];
plot bounceUp = if bouncbackup then 0 else na;
bounceUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bounceUp.SetDefaultColor(Color.VIOLET);

#// take short position
def downtrend = trend == -4 and (trend-trend[1]) != 0;
plot shortShape = if downtrend then 0 else na;
shortShape.SetLineWeight(2);
shortShape.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
shortShape.SetDefaultColor(Color.MAGENTA);

def bouncbackdn = EnableBounceOff and trend == -4 and close < CloudMin  and inthecloud[1];
plot bounceDn = if bouncbackdn then 0 else na;
bounceDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bounceDn.SetDefaultColor(Color.PLUM);

#/ plot ema line if enabled
def emaline = ExpAverage(cloud, emalen);
plot ema = if useema then emaline else na;
ema.SetDefaultColor(GlobalColor("emacol"));
#// possible/partially take profit if profitable
def convcrossbase = Crosses(conversionLine, baseLine, CrossingDirection.ABOVE);
def basecrosscons = Crosses(baseLine, conversionLine, CrossingDirection.ABOVE);
def emacrosscloud = Crosses(emaline, cloud, CrossingDirection.ABOVE);
def cloudcrossema = Crosses(cloud, emaline, CrossingDirection.ABOVE);

def profitable = trend == 4 and close > entrylevel or trend == -4 and close < entrylevel;
def posexitcol = if profitable then
             if trend == 4 and basecrosscons then 1 else
             if trend == 4 and emacrosscloud and TakePartialProfitByEma then 0 else
             if trend ==-4 and convcrossbase then -1 else
             if trend ==-4 and cloudcrossema and TakePartialProfitByEma then 0 else na else na;

plot profit = posexitcol;
profit.SetPaintingStrategy(PaintingStrategy.POINTS);
profit.AssignValueColor(if posexitcol > 0 then Color.WHITE else
                        if posexitcol < 0 then Color.YELLOW else GlobalColor("emacol"));


#-- END of CODE
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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