MTF CCI Dashboard

gravityflyer

New member
Hi all,

I created a MTF lower indicator for the CCI.

hHnWHee.png


It works exactly as intended, but kindly requesting assistance with two slight modifications to the existing code:
  1. How can I condense the spacing between each row of dots? Even if I resize the lower window in ToS there still seems to be a limit of how closely I can squish the dots together.
  2. I'd like the indicator title (circled in blue) to be red if all three lines of dots are red, and green if all three lines of dots are green.
Any help would be greatly appreciated! 🙏

Code:
#MTF_CCI_LowerStudy_Dots
# gravityflyer
# v1.0 - 2021.09.23

declare lower;

input timeFrameOne = AggregationPeriod.TWO_MIN;
input timeFrameTwo = AggregationPeriod.FIVE_MIN;
input timeFrameThree = AggregationPeriod.FIFTEEN_MIN;

input length = 14;

#CCI Two Minutes
def priceTWO_MIN = close(period = timeFrameOne) + low(period = timeFrameOne) + high(period = timeFrameOne);
def linDev2 = lindev(priceTWO_MIN, length);
def CCI_2 = if linDev2 == 0 then 0 else (priceTWO_MIN - Average(priceTWO_MIN, length)) / linDev2 / 0.015;

#CCI Five Minutes
def priceFIVE_MIN = close(period = timeFrameTwo) + low(period = timeFrameTwo) + high(period = timeFrameTwo);
def linDev5 = lindev(priceFIVE_MIN, length);
def CCI_5 = if linDev5 == 0 then 0 else (priceFIVE_MIN - Average(priceFIVE_MIN, length)) / linDev5 / 0.015;

#CCI Fifteen Minutes
def priceFIFTEEN_MIN = close(period = timeFrameThree) + low(period = timeFrameThree) + high(period = timeFrameThree);
def linDev15 = lindev(priceFIFTEEN_MIN, length);
def CCI_15 = if linDev15 == 0 then 0 else (priceFIFTEEN_MIN - Average(priceFIFTEEN_MIN, length)) / linDev15 / 0.015;

#Row 1
plot rowOne = if IsNaN(close) then Double.NaN else 1;
rowOne.SetPaintingStrategy(PaintingStrategy.POINTS);
rowOne.AssignValueColor(if CCI_2 > 0 then Color.GREEN else Color.RED);
rowOne.SetLineWeight(3);

#Row 2
plot rowTwo = if IsNaN(close) then Double.NaN else 2;
rowTwo.SetPaintingStrategy(PaintingStrategy.POINTS);
rowTwo.AssignValueColor(if CCI_5 > 0 then Color.GREEN else Color.RED);
rowTwo.SetLineWeight(3);

#Row 3
plot rowThree = if IsNaN(close) then Double.NaN else 3;
rowThree.SetPaintingStrategy(PaintingStrategy.POINTS);
rowThree.AssignValueColor(if CCI_15 > 0 then Color.GREEN else Color.RED);
rowThree.SetLineWeight(3);
 
@gravityflyer
Your dashboard is a graph.
You are graphing each set of dots on row 1, 2, and 3.
If you wanted them closer on the graph you could try plotting them closer together. row: 0.5, 1.0, 1.5 You can go even closer.
There is a minimum size that each lower chart takes up though. You can't make the lower study smaller than the min.size
 
Last edited:
@gravityflyer I forgot. Important: to push the lines closer together you need to add a top and bottom plot.
Otherwise, the plots will always attempt to be equidistant to the size of the minimum lower chart size.
For example the top and bottom plots of:
plot nine = nine ;
plot minus3 = -3.0 ;
Will push all your rows close together in the middle of the graph.
plot six = six;
plot zero= -5 ;
Will push your dashboard to the top of the lower chart.

You might be able to get away with something closer together depending on the values of your plots. You have to play with it until you get the look you want.
 
I made several revisions to my indicator including an overbought/oversold line and a buy/sell trigger.

Two follow-up questions/issues,
  1. For my buy/sell trigger I'd like the first instance to print a triangle, with each subsequent instance printing a dot. Unfortunately it appears that the first two instances print a triangle. See image. I'm assuming there is an error in my script? I'd obviously just like the first triangle only.
  2. I'm not sure if created the spacers correctly as you suggested? Created lines at 2 and -2 with Hide() since it otherwise plotted a line, but it seems to have quite literally hide the line rather than transparent? I experimented with hideBubble() but that didn't seem to work either?
Thank you!

DeTQrvH.png


Code:
# MTF_CCI_LowerStudy_Dots
# gravityflyer
# v1.0 - 2021.09.23
# v1.1 - 2021.09.25

declare lower;

input timeFrameOne = AggregationPeriod.TWO_MIN;
input timeFrameTwo = AggregationPeriod.FIVE_MIN;
input timeFrameThree = AggregationPeriod.FIFTEEN_MIN;

input length = 14;

#CCI Two Minutes
def priceTWO_MIN = close(period = timeFrameOne) + low(period = timeFrameOne) + high(period = timeFrameOne);
def linDev2 = lindev(priceTWO_MIN, length);
def CCI_2 = if linDev2 == 0 then 0 else (priceTWO_MIN - Average(priceTWO_MIN, length)) / linDev2 / 0.015;

plot rowOne = if IsNaN(close) then Double.NaN else .5;
rowOne.SetPaintingStrategy(PaintingStrategy.POINTS);
rowOne.AssignValueColor(if CCI_2 > 0 then Color.GREEN else Color.RED);
rowOne.SetLineWeight(1);

#CCI Five Minutes
def priceFIVE_MIN = close(period = timeFrameTwo) + low(period = timeFrameTwo) + high(period = timeFrameTwo);
def linDev5 = lindev(priceFIVE_MIN, length);
def CCI_5 = if linDev5 == 0 then 0 else (priceFIVE_MIN - Average(priceFIVE_MIN, length)) / linDev5 / 0.015;

plot rowTwo = if IsNaN(close) then Double.NaN else 0;
rowTwo.SetPaintingStrategy(PaintingStrategy.POINTS);
rowTwo.AssignValueColor(if CCI_5 > 0 then Color.GREEN else Color.RED);
rowTwo.SetLineWeight(1);

#CCI Fifteen Minutes
def priceFIFTEEN_MIN = close(period = timeFrameThree) + low(period = timeFrameThree) + high(period = timeFrameThree);
def linDev15 = lindev(priceFIFTEEN_MIN, length);
def CCI_15 = if linDev15 == 0 then 0 else (priceFIFTEEN_MIN - Average(priceFIFTEEN_MIN, length)) / linDev15 / 0.015;

plot rowThree = if IsNaN(close) then Double.NaN else -.5;
rowThree.SetPaintingStrategy(PaintingStrategy.POINTS);
rowThree.AssignValueColor(if CCI_15 > 0 then Color.GREEN else Color.RED);
rowThree.SetLineWeight(1);

#Over Bought / Over Sold
def OverBought2 = if CCI_2 >= 150 then 1 else 0;
def OverBought5 = if CCI_5 >= 150 then 1 else 0;
def OverBought15 = if CCI_15 >= 150 then 1 else 0;
plot OverBought = if (OverBought2 + OverBought5 + OverBought15) >= 2 then 1 else double.nan;
OverBought.setPaintingStrategy(PaintingStrategy.DASHES);
OverBought.setDefaultColor(color.red);
OverBought.setLineWeight(2);

plot NotOverBought = if (OverBought2 + OverBought5 + OverBought15) < 2 then 1 else double.nan;
NotOverBought.setPaintingStrategy(PaintingStrategy.DASHES);
NotOverBought.setDefaultColor(color.gray);
NotOverBought.setLineWeight(1);

def OverSold2 = if CCI_2 <= -150 then 1 else 0;
def OverSold5 = if CCI_5 <= -150 then 1 else 0;
def OverSold15 = if CCI_15 <= -150 then 1 else 0;
plot OverSold = if (OverSold2 + OverSold5 + OverSold15) >= 2 then -1 else double.nan;
OverSold.setPaintingStrategy(PaintingStrategy.DASHES);
OverSold.setDefaultColor(color.red);
OverSold.setLineWeight(2);

plot NotOverSold = if (OverSold2 + OverSold5 + OverSold15) < 2 then -1 else double.nan;
NotOverSold.setPaintingStrategy(PaintingStrategy.DASHES);
NotOverSold.setDefaultColor(color.gray);
NotOverSold.setLineWeight(1);

#Buy Indicator
def up2 = if CCI_2 > 0 then 1 else 0;
def up5 = if CCI_5 > 0 then 1 else 0;
def up15 = if CCI_15 > 0 then 1 else 0;

plot Up = if (up2+up5+up15) == 3 then -1.5 else double.nan;
Up.setPaintingStrategy(paintingStrategy.POINTS);
Up.setDefaultColor(color.green);
Up.setLineWeight(1);

def BuySig = if (up2+up5+up15) == 3 then 1 else 0;
def a = if BuySig == 1 and BuySig[1] == 0 then 1 else 0;
plot b = if a == 1 then -1.5 else double.nan;
b.setPaintingStrategy(paintingStrategy.TRIANGLES);
b.setDefaultColor(color.green);
b.setLineWeight(3);

#Sell Indicator
def dn2 = if CCI_2 < 0 then 1 else 0;
def dn5 = if CCI_5 < 0 then 1 else 0;
def dn15 = if CCI_15 < 0 then 1 else 0;

plot Down = if (dn2+dn5+dn15) == 3 then 1.5 else double.nan;
Down.setPaintingStrategy(paintingStrategy.POINTS);
Down.setDefaultColor(color.red);
Down.setLineWeight(1);

def SellSig = if (dn2+dn5+dn15) == 3 then 1 else 0;
def c = if SellSig == 1 and SellSig[1] == 0 then 1 else 0;
plot d = if c == 1 then 1.5 else double.nan;
d.setPaintingStrategy(paintingStrategy.TRIANGLES);
d.setDefaultColor(color.red);
d.setLineWeight(3);

#Spacers
plot two = 2.0 ;
two.hideBubble();
two.setDefaultColor(color.gray);
plot minustwo = -2.0 ;
minustwo.hideBubble();
minustwo.setDefaultColor(color.gray);
 
Last edited by a moderator:
I made several revisions to my indicator including an overbought/oversold line and a buy/sell trigger.

Two follow-up questions/issues,
  1. For my buy/sell trigger I'd like the first instance to print a triangle, with each subsequent instance printing a dot. Unfortunately it appears that the first two instances print a triangle. See image. I'm assuming there is an error in my script? I'd obviously just like the first triangle only.
  2. I'm not sure if created the spacers correctly as you suggested? Created lines at 2 and -2 with Hide() since it otherwise plotted a line, but it seems to have quite literally hide the line rather than transparent? I experimented with hideBubble() but that didn't seem to work either?
Thank you!

DeTQrvH.png

It looks like you must be using a 1m chart, because a 2m chart only prints 1 triangle. The problem of the 2 triangles is that your lowest agg is 2m for your dots/triangles causing TOS to print 2 triangles on a 1m chart, as both values being assigned were the same, one (1).

To workaround that, here is one way that should work hopefully. Basically you need to give the first instance of the 2 triangles a value on the 1m chart that is different than the second, which was done with barnumber() in the code below.

Also, note the black background used in the picture is then used as the color for the spacer lines. That method of coloring the lines the same color as the background is about the only way I know to hide those lines as you need them to plot to be used as spacers.

Capture.jpg
Ruby:
# MTF_CCI_LowerStudy_Dots
# gravityflyer
# v1.0 - 2021.09.23
# v1.1 - 2021.09.25

declare lower;

input timeFrameOne = AggregationPeriod.TWO_MIN;
input timeFrameTwo = AggregationPeriod.FIVE_MIN;
input timeFrameThree = AggregationPeriod.FIFTEEN_MIN;

input length = 14;

#CCI Two Minutes
def priceTWO_MIN = close(period = timeFrameOne) + low(period = timeFrameOne) + high(period = timeFrameOne);
def linDev2 = lindev(priceTWO_MIN, length);
def CCI_2 = if linDev2 == 0 then 0 else (priceTWO_MIN - Average(priceTWO_MIN, length)) / linDev2 / 0.015;

plot rowOne = if IsNaN(close) then Double.NaN else .5;
rowOne.SetPaintingStrategy(PaintingStrategy.POINTS);
rowOne.AssignValueColor(if CCI_2 > 0 then Color.GREEN else Color.RED);
rowOne.SetLineWeight(1);

#CCI Five Minutes
def priceFIVE_MIN = close(period = timeFrameTwo) + low(period = timeFrameTwo) + high(period = timeFrameTwo);
def linDev5 = lindev(priceFIVE_MIN, length);
def CCI_5 = if linDev5 == 0 then 0 else (priceFIVE_MIN - Average(priceFIVE_MIN, length)) / linDev5 / 0.015;

plot rowTwo = if IsNaN(close) then Double.NaN else 0;
rowTwo.SetPaintingStrategy(PaintingStrategy.POINTS);
rowTwo.AssignValueColor(if CCI_5 > 0 then Color.GREEN else Color.RED);
rowTwo.SetLineWeight(1);

#CCI Fifteen Minutes
def priceFIFTEEN_MIN = close(period = timeFrameThree) + low(period = timeFrameThree) + high(period = timeFrameThree);
def linDev15 = lindev(priceFIFTEEN_MIN, length);
def CCI_15 = if linDev15 == 0 then 0 else (priceFIFTEEN_MIN - Average(priceFIFTEEN_MIN, length)) / linDev15 / 0.015;

plot rowThree = if IsNaN(close) then Double.NaN else -.5;
rowThree.SetPaintingStrategy(PaintingStrategy.POINTS);
rowThree.AssignValueColor(if CCI_15 > 0 then Color.GREEN else Color.RED);
rowThree.SetLineWeight(1);

#Over Bought / Over Sold
def OverBought2 = if CCI_2 >= 150 then 1 else 0;
def OverBought5 = if CCI_5 >= 150 then 1 else 0;
def OverBought15 = if CCI_15 >= 150 then 1 else 0;
plot OverBought = if (OverBought2 + OverBought5 + OverBought15) >= 2 then 1 else double.nan;
OverBought.setPaintingStrategy(PaintingStrategy.DASHES);
OverBought.setDefaultColor(color.red);
OverBought.setLineWeight(2);

plot NotOverBought = if (OverBought2 + OverBought5 + OverBought15) < 2 then 1 else double.nan;
NotOverBought.setPaintingStrategy(PaintingStrategy.DASHES);
NotOverBought.setDefaultColor(color.gray);
NotOverBought.setLineWeight(1);

def OverSold2 = if CCI_2 <= -150 then 1 else 0;
def OverSold5 = if CCI_5 <= -150 then 1 else 0;
def OverSold15 = if CCI_15 <= -150 then 1 else 0;
plot OverSold = if (OverSold2 + OverSold5 + OverSold15) >= 2 then -1 else double.nan;
OverSold.setPaintingStrategy(PaintingStrategy.DASHES);
OverSold.setDefaultColor(color.red);
OverSold.setLineWeight(2);

plot NotOverSold = if (OverSold2 + OverSold5 + OverSold15) < 2 then -1 else double.nan;
NotOverSold.setPaintingStrategy(PaintingStrategy.DASHES);
NotOverSold.setDefaultColor(color.gray);
NotOverSold.setLineWeight(1);

#Buy Indicator
def up2 = if CCI_2 > 0 then 1 else 0;
def up5 = if CCI_5 > 0 then 1 else 0;
def up15 = if CCI_15 > 0 then 1 else 0;

plot Up = if (up2+up5+up15) == 3 then -1.5 else double.nan;
Up.setPaintingStrategy(paintingStrategy.POINTS);
Up.setDefaultColor(color.green);
Up.setLineWeight(1);

def BuySig = if !isnan(up) then barnumber() else double.nan;
def a = if isnan(up[1]) and buysig then 1 else 0;
plot b = if  a == 1 then -1.5 else double.nan;
b.setPaintingStrategy(paintingStrategy.TRIANGLES);
b.setDefaultColor(color.green);
b.setLineWeight(3);

#Sell Indicator
def dn2 = if CCI_2 < 0 then 1 else 0;
def dn5 = if CCI_5 < 0 then 1 else 0;
def dn15 = if CCI_15 < 0 then 1 else 0;

plot Down = if (dn2+dn5+dn15) == 3 then 1.5 else double.nan;
Down.setPaintingStrategy(paintingStrategy.POINTS);
Down.setDefaultColor(color.red);
Down.setLineWeight(1);

def SellSig = if !isnan(down) then barnumber() else double.nan;
def c = if isnan(down[1]) and  sellsig  then 1 else 0;
plot d = if c == 1 then 1.5 else double.nan;
d.setPaintingStrategy(paintingStrategy.TRIANGLES);
d.setDefaultColor(color.red);
d.setLineWeight(3);

#Spacers
plot two = 2.0 ;
two.hideBubble();
two.setDefaultColor(color.black);
plot minustwo = -2.0 ;
minustwo.hideBubble();
minustwo.setDefaultColor(color.black);
 
Can an alert sound be added?
Add this to the bottom of your script:
# Alert
Alert(b, "mtfCCI", Alert.Bar, Sound.ding);

Can this me made to a watchlist?
No, this can not be made into a watchlist. It also can't be used in a scanner or conditional order or any other ToS widget.

On the ToS platform, MTF scripts can only be to create plots on a chart.
 
Last edited:

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

Thread starter Similar threads Forum Replies Date
I MTF Average Daily Close Line Questions 2
D MTF Stoch Signals Questions 0
B MTF Previous Week Open / Close Questions 1
P MTF Stacked Averages? Questions 0
S MTF Shaded EMA Questions 4

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