Double Ribbon [ChartPrime] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
UoxgCv3.png


The Double Ribbon - indicator is a powerful tool that combines two sets of Moving Averages (MAs) into a visually intuitive ribbon, which helps traders assess market trends and momentum. This indicator features two distinct ribbons: one with a fixed length but changing offset (displayed in gray) and another with varying lengths (displayed in colors). The relationship between these ribbons forms the basis of a trend score, which is visualized as an oscillator. This comprehensive approach provides traders with a clear view of market direction and strength.

Upper Study:

CSS:
#// Indicator for TOS
#// © ChartPrime
#indicator("Double Ribbon [ChartPrime]")
# Converted by Sam4Cok@Samer800 - 09/2024

input timeframe = AggregationPeriod.MIN;
input colorBars = yes;
input showLabel = yes;
input movAvgType = AverageType.SIMPLE;
input Source = FundamentalType.CLOSE;     # "Source"
input Length = 25;     # "Length"

def na = Double.NaN;
def last = IsNaN(close);
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
def src = Fundamental(FundamentalType = Source, Period = tf);
#// Initialize variables
def sma1 = MovingAverage(movAvgType, src, Length); #  // Primary SMA for comparison
def mva0 = MovingAverage(movAvgType, src, Length + 1 + 0);
def mva1 = MovingAverage(movAvgType, src, Length + 1 + 1);
def mva2 = MovingAverage(movAvgType, src, Length + 1 + 2);
def mva3 = MovingAverage(movAvgType, src, Length + 1 + 3);
def mva4 = MovingAverage(movAvgType, src, Length + 1 + 4);
def mva5 = MovingAverage(movAvgType, src, Length + 1 + 5);
def mva6 = MovingAverage(movAvgType, src, Length + 1 + 6);
def mva7 = MovingAverage(movAvgType, src, Length + 1 + 7);
def mva8 = MovingAverage(movAvgType, src, Length + 1 + 8);
def mva9 = MovingAverage(movAvgType, src, Length + 1 + 9);
def mva10 = MovingAverage(movAvgType, src, Length + 1 + 10);
def mva11 = MovingAverage(movAvgType, src, Length + 1 + 11);

def score0 = if sma1[0] < mva0 then 1 else -1;
def score1 = score0 + if sma1[1] < mva1 then 1 else -1;
def score2 = score1 + if sma1[2] < mva2 then 1 else -1;
def score3 = score2 + if sma1[3] < mva3 then 1 else -1;
def score4 = score3 + if sma1[4] < mva4 then 1 else -1;
def score5 = score4 + if sma1[5] < mva5 then 1 else -1;
def score6 = score5 + if sma1[6] < mva6 then 1 else -1;
def score7 = score6 + if sma1[7] < mva7 then 1 else -1;
def score8 = score7 + if sma1[8] < mva8 then 1 else -1;
def score9 = score8 + if sma1[9] < mva9 then 1 else -1;
def score10 = score9 + if sma1[10] < mva10 then 1 else -1;
def score11 = score10 + if sma1[11] < mva11 then 1 else -1;

def score = if isNaN(score11) then 0 else score11;
def col = (score + 12) * 10.6;

#// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎

plot movAvgLine = if last then na else sma1;
plot m1a0 = if last then na else mva0;
plot m1a1 = if last then na else mva1;
plot m1a2 = if last then na else mva2;
plot m1a3 = if last then na else mva3;
plot m1a4 = if last then na else mva4;
plot m1a5 = if last then na else mva5;
plot m1a6 = if last then na else mva6;
plot m1a7 = if last then na else mva7;
plot m1a8 = if last then na else mva8;
plot m1a9 = if last then na else mva9;
plot m1a10 = if last then na else mva10;

plot ma0 = if last then na else sma1[0];
plot ma1 = if last then na else sma1[1];
plot ma2 = if last then na else sma1[2];
plot ma3 = if last then na else sma1[3];
plot ma4 = if last then na else sma1[4];
plot ma5 = if last then na else sma1[5];
plot ma6 = if last then na else sma1[6];
plot ma7 = if last then na else sma1[7];
plot ma8 = if last then na else sma1[8];
plot ma9 = if last then na else sma1[9];
plot ma10 = if last then na else sma1[10];

movAvgLine.SetDefaultColor(Color.WHiTE);
m1a0.setLineWeight(2);
m1a1.setLineWeight(2);
m1a2.setLineWeight(2);
m1a3.setLineWeight(2);
m1a4.setLineWeight(2);
m1a5.setLineWeight(2);
m1a6.setLineWeight(2);
m1a7.setLineWeight(2);
m1a8.setLineWeight(2);
m1a9.setLineWeight(2);
m1a10.setLineWeight(2);
m1a0.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a1.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a2.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a3.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a4.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a5.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a6.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a7.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a8.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a9.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));
m1a10.AssignValueColor(if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));

ma0.SetDefaultColor(Color.DARK_GRAY);
ma1.SetDefaultColor(Color.DARK_GRAY);
ma2.SetDefaultColor(Color.DARK_GRAY);
ma3.SetDefaultColor(Color.DARK_GRAY);
ma4.SetDefaultColor(Color.DARK_GRAY);
ma5.SetDefaultColor(Color.DARK_GRAY);
ma6.SetDefaultColor(Color.DARK_GRAY);
ma7.SetDefaultColor(Color.DARK_GRAY);
ma8.SetDefaultColor(Color.DARK_GRAY);
ma9.SetDefaultColor(Color.DARK_GRAY);
ma10.SetDefaultColor(Color.DARK_GRAY);

#-- bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else CreateColor(255-col,col,0));
#-- Labels
AddLabel(showLabel,(if score > 0 then "Trend Up (" else "Trend Down (") + score + ")",
                    if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));

#-- END of CODe

Lower Study :

CSS:
#// Indicator for TOS
#// © ChartPrime
#indicator("Double Ribbon [ChartPrime]")
# Converted by Sam4Cok@Samer800    - 09/2024

Declare lower;
input timeframe = AggregationPeriod.MIN;
input colorBars = yes;
input showLabel = yes;
input movAvgType = AverageType.SIMPLE;
input Source = FundamentalType.CLOSE;     # "Source"
input Length = 25;     # "Length"

def na = Double.NaN;
def last = IsNaN(close);
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
def src = Fundamental(FundamentalType = Source, Period = tf);
#// Initialize variables
def sma1 = MovingAverage(movAvgType, src, Length); #  // Primary SMA for comparison
def mva0 = MovingAverage(movAvgType, src, Length + 1 + 0);
def mva1 = MovingAverage(movAvgType, src, Length + 1 + 1);
def mva2 = MovingAverage(movAvgType, src, Length + 1 + 2);
def mva3 = MovingAverage(movAvgType, src, Length + 1 + 3);
def mva4 = MovingAverage(movAvgType, src, Length + 1 + 4);
def mva5 = MovingAverage(movAvgType, src, Length + 1 + 5);
def mva6 = MovingAverage(movAvgType, src, Length + 1 + 6);
def mva7 = MovingAverage(movAvgType, src, Length + 1 + 7);
def mva8 = MovingAverage(movAvgType, src, Length + 1 + 8);
def mva9 = MovingAverage(movAvgType, src, Length + 1 + 9);
def mva10 = MovingAverage(movAvgType, src, Length + 1 + 10);
def mva11 = MovingAverage(movAvgType, src, Length + 1 + 11);

def score0 = if sma1[0] < mva0 then 1 else -1;
def score1 = score0 + if sma1[1] < mva1 then 1 else -1;
def score2 = score1 + if sma1[2] < mva2 then 1 else -1;
def score3 = score2 + if sma1[3] < mva3 then 1 else -1;
def score4 = score3 + if sma1[4] < mva4 then 1 else -1;
def score5 = score4 + if sma1[5] < mva5 then 1 else -1;
def score6 = score5 + if sma1[6] < mva6 then 1 else -1;
def score7 = score6 + if sma1[7] < mva7 then 1 else -1;
def score8 = score7 + if sma1[8] < mva8 then 1 else -1;
def score9 = score8 + if sma1[9] < mva9 then 1 else -1;
def score10 = score9 + if sma1[10] < mva10 then 1 else -1;
def score11 = score10 + if sma1[11] < mva11 then 1 else -1;

def score = if isNaN(score11) then 0 else score11;
def avgScr = Average(score, 2);
def col = (score + 12) * 10.6;

#// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
#// Plot the trend score as a line
def scoreUp = score > 2;
def scoreDn = score <-2;
def scoreUp1 = score > 6;
def scoreDn1 = score <-6;
def scoreUp2 = score > 10;
def scoreDn2 = score <-10;
plot p1 = if last then na else avgScr; # Smoothed score line
plot p2 = if last then na else 0;      # Zero line for reference
p1.AssignValueColor(if scoreUp[1] then Color.CYAN else
                    if scoreDn[1] then Color.MAGENTA else Color.GRAY);
p2.SetDefaultColor(Color.GRAY);
AddCloud(if (scoreUp2 or scoreUp2[1]) then p1 else na, 10, CreateColor(0, 118, 118));
AddCloud(if (scoreDn2 or scoreDn2[1]) then -10 else na, p1, Color.PLUM);
AddCloud(if (scoreUp1 or scoreUp1[1]) then p1 else na, 6, CreateColor(0, 118, 118));
AddCloud(if (scoreDn1 or scoreDn1[1]) then -6 else na, p1, Color.PLUM);
AddCloud(if (scoreUp or scoreUp[1]) then p1 else na, 2, CreateColor(0, 118, 118));
AddCloud(if (scoreDn or scoreDn[1]) then -2 else na, p1, Color.PLUM);


#-- bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else CreateColor(255-col,col,0));
#-- Labels
AddLabel(showLabel,(if score > 0 then "Trend Up (" else "Trend Down (") + score + ")",
                    if score > 0 then CreateColor(255-col,col,col) else CreateColor(255-col,col,255-col));

#-- END of CODe
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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