Ichimoku, MACD, and PSar Dashboard For ThinkOrSwim

TOS007

New member
Is it possible to have these criterias?
1. Close crosses above/below Tenkan (from Ichimoku cloud)
2. Close crosses above/below Parabolic SAR
3. MACD Histogram crosses above/below zero line
4. Awesome Oscillator crosses above/below zero line
I am extremely appreciated if anyone can code this.
 

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

Is it possible to have these criterias?
1. Close crosses above/below Tenkan (from Ichimoku cloud)
2. Close crosses above/below Parabolic SAR
3. MACD Histogram crosses above/below zero line
4. Awesome Oscillator crosses above/below zero line
I am extremely appreciated if anyone can code this.

This is a lower indicator that will plot green or red dots for each of the 4 conditions if above or below constraint.

Line 6 is the summary of ALL. If all are the same color green or red, the dots will remain that color until all are the opposite color.

Screenshot-2023-03-22-152944.png
Code:
#Tenkan_SAR_MACD_AwesomeOsc_Green_Red

declare lower;

def tenkan = if close crosses above reference Ichimoku()
             then 1
             else if close crosses below Ichimoku()
             then 0
             else tenkan[1];
def sar    = if close crosses above reference ParabolicSAR()
             then 1
             else if close crosses below reference ParabolicSAR()
             then 0
             else sar[1];
def macd   = if reference MACD().Diff crosses above 0
             then 1
             else if reference MACD().Diff crosses below 0
             then 0
             else macd[1] ;
def aweosc = if reference AwesomeOscillator() crosses above 0
             then 1
             else if reference AwesomeOscillator() crosses below 0
             then 0
             else aweosc[1];

plot line1  = if IsNaN(close) then Double.NaN else 1;
line1.AssignValueColor(if tenkan == 1 then Color.GREEN else Color.RED);
line1.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line2  = if IsNaN(close) then Double.NaN else 2;
line2.AssignValueColor(if sar == 1 then Color.GREEN else Color.RED);
line2.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line3  = if IsNaN(close) then Double.NaN else 3;
line3.AssignValueColor(if macd == 1 then Color.GREEN else Color.RED);
line3.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line4  = if IsNaN(close) then Double.NaN else 4;
line4.AssignValueColor(if aweosc == 1 then Color.GREEN else Color.RED);
line4.SetPaintingStrategy(PaintingStrategy.POINTS);

plot line5 = 5;
line5.SetDefaultColor(Color.WHITE);

def sum = if tenkan + sar + macd + aweosc == 4 then 1
          else if tenkan + sar + macd + aweosc == 0 then 0
          else sum[1];

plot line6 = if IsNaN(close) then Double.NaN else 6;
line6.AssignValueColor(if sum == 1 then Color.GREEN else if sum == 0 then Color.RED else Color.WHITE);
line6.SetPaintingStrategy(PaintingStrategy.POINTS);

plot line7 = if IsNaN(close) then Double.NaN else 7;
line7.SetDefaultColor(Color.BLACK);

input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
def mover = showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]);

AddChartBubble(mover, line1[b1], "Tenkan", line1.TakeValueColor());
AddChartBubble(mover, line2[b1], "SAR", line2.TakeValueColor());
AddChartBubble(mover, line3[b1], "MACD", line3.TakeValueColor());
AddChartBubble(mover, line4[b1], "AweOsc", line4.TakeValueColor());
AddChartBubble(mover, line6[b1], "All", line6.TakeValueColor());
 
Last edited by a moderator:
With bar coloring

Code:
#Tenkan_SAR_MACD_AwesomeOsc_Green_Red
# v2.0 - tradingnumbers - added candle coloring

declare lower;

def tenkan = if close crosses above reference Ichimoku()
             then 1
             else if close crosses below Ichimoku()
             then 0
             else tenkan[1];
def sar    = if close crosses above reference ParabolicSAR()
             then 1
             else if close crosses below reference ParabolicSAR()
             then 0
             else sar[1];
def macd   = if reference MACD().Diff crosses above 0
             then 1
             else if reference MACD().Diff crosses below 0
             then 0
             else macd[1] ;
def aweosc = if reference AwesomeOscillator() crosses above 0
             then 1
             else if reference AwesomeOscillator() crosses below 0
             then 0
             else aweosc[1];

plot line1  = if IsNaN(close) then Double.NaN else 1;
line1.AssignValueColor(if tenkan == 1 then Color.GREEN else Color.RED);
line1.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line2  = if IsNaN(close) then Double.NaN else 2;
line2.AssignValueColor(if sar == 1 then Color.GREEN else Color.RED);
line2.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line3  = if IsNaN(close) then Double.NaN else 3;
line3.AssignValueColor(if macd == 1 then Color.GREEN else Color.RED);
line3.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line4  = if IsNaN(close) then Double.NaN else 4;
line4.AssignValueColor(if aweosc == 1 then Color.GREEN else Color.RED);
line4.SetPaintingStrategy(PaintingStrategy.POINTS);

plot line5 = 5;
line5.SetDefaultColor(Color.WHITE);

def sum = if tenkan + sar + macd + aweosc == 4 then 1
          else if tenkan + sar + macd + aweosc == 0 then 0
          else sum[1];

plot line6 = if IsNaN(close) then Double.NaN else 6;
line6.AssignValueColor(if sum == 1 then Color.GREEN else if sum == 0 then Color.RED else Color.WHITE);
line6.SetPaintingStrategy(PaintingStrategy.POINTS);

plot line7 = if IsNaN(close) then Double.NaN else 7;
line7.SetDefaultColor(Color.BLACK);

input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
def mover = showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]);

AddChartBubble(mover, line1[b1], "Tenkan", line1.TakeValueColor());
AddChartBubble(mover, line2[b1], "SAR", line2.TakeValueColor());
AddChartBubble(mover, line3[b1], "MACD", line3.TakeValueColor());
AddChartBubble(mover, line4[b1], "AweOsc", line4.TakeValueColor());
AddChartBubble(mover, line6[b1], "All", line6.TakeValueColor());

input colorBars = yes;

AssignPriceColor(if colorBars then if sum == 1 then Color.GREEN else if sum == 0 then Color.RED else Color.WHITE else Color.CURRENT);
 
I wanted to consider a slightly different criteria for trend and entry as well as well as to include the ability to scan for bullish or bearish entry, so added a few lines to the original smart code from SleepyZ


Code:
# Lower Indicator

# This indicator shows individually the following requirements:
# 1. Close crosses above/below Tenkan (from Ichimoku cloud)
# 2. Close crosses above/below Parabolic SAR
# 3. MACD Histogram crosses above/below zero line
# 4. Awesome Oscillator crosses above/below zero line
# 5. EMA21 as a trend master

#based on a code from SleepyZ =>
#            => https://usethinkscript.com/threads/ichimoku-macd-and-psar-dashboard-for-thinkorswim.14928/

declare lower;

def tenkan = if close crosses above reference Ichimoku()
             then 1
             else if close crosses below Ichimoku()
             then 0
             else tenkan[1];
def sar    = if close crosses above reference ParabolicSAR()
             then 1
             else if close crosses below reference ParabolicSAR()
             then 0
             else sar[1];
def macd   = if reference MACD().Diff crosses above 0
             then 1
             else if reference MACD().Diff crosses below 0
             then 0
             else macd[1] ;
def aweosc = if reference AwesomeOscillator() crosses above 0
             then 1
             else if reference AwesomeOscillator() crosses below 0
             then 0
             else aweosc[1];

# though AO is originally used for trend, I decided to use em21 as master trend indicator to allow for bullish or bearish signals
def trend = if close > expAverage(close,21) then 1 else 0;

plot line1  = if IsNaN(close) then Double.NaN else 1;
line1.AssignValueColor(if tenkan == 1 then Color.GREEN else Color.RED);
line1.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line2  = if IsNaN(close) then Double.NaN else 2;
line2.AssignValueColor(if sar == 1 then Color.GREEN else Color.RED);
line2.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line3  = if IsNaN(close) then Double.NaN else 3;
line3.AssignValueColor(if macd == 1 then Color.GREEN else Color.RED);
line3.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line4  = if IsNaN(close) then Double.NaN else 4;
line4.AssignValueColor(if aweosc == 1 then Color.GREEN else Color.RED);
line4.SetPaintingStrategy(PaintingStrategy.POINTS);

plot line5 = if IsNaN(close) then Double.NaN else 5;
line5.AssignValueColor(if trend == 1 then Color.GREEN else Color.RED);
line5.SetPaintingStrategy(PaintingStrategy.POINTS);



#changed the purpose of the ALL plot to show bullish, bearish and undefined status by requiaring a 75% agreement of the original indicators and the new trend criteria
def subtot = tenkan + sar + macd + aweosc;
def sum = if subtot >= 3 and trend ==1 then 1 else if subtot <= 1 and trend == 0 then 0 else 8;

#original calculation
#def sum = if tenkan + sar + macd + aweosc == 4 then 1
#          else if tenkan + sar + macd + aweosc == 0 then 0
#          else sum[1];

plot line6 = if IsNaN(close) then Double.NaN else 6;
#line6.AssignValueColor(if sum == 1 then Color.GREEN else if sum == 0 then Color.RED else Color.WHITE);
line6.AssignValueColor(if sum == 1 then Color.GREEN else if sum == 0 then Color.RED else Color.BLaCK);
line6.SetPaintingStrategy(PaintingStrategy.POINTS);

plot line7 = if IsNaN(close) then Double.NaN else 7;
line7.SetDefaultColor(Color.BLACK);

input showbubbles = yes;
input bubblemover = 2;
def b  = bubblemover;
def b1 = b + 1;
def mover = showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]);

AddChartBubble(mover, line1[b1], "Tenkan", line1.TakeValueColor());
AddChartBubble(mover, line2[b1], "SAR", line2.TakeValueColor());
AddChartBubble(mover, line3[b1], "MACD", line3.TakeValueColor());
AddChartBubble(mover, line4[b1], "AweOsc", line4.TakeValueColor());
AddChartBubble(mover, line5[b1], "Trend", line5.TakeValueColor());
AddChartBubble(mover, line6[b1], "All", line6.TakeValueColor());


plot zeroline = if IsNaN(close) then Double.NaN else 0;
zeroline.SetDefaultColor(Color.BLACK);

#mainly for scanning purposes
plot trendo = if sum == 1 then 0.5 else if sum == 0 then -0.5 else Double.NaN;
trendo.SetPaintingStrategy(PaintingStrategy.POINTS);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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