Ribbon % OF stocks above 20/50/100/200 DayMA S&P500 For ThinkOrSwim

nirgalli

New member
mod note:
This study provides insights into market trends and helps gauge the overall health and direction of the stock market.

Interaction between these different moving averages, identifies potential entry and exit points for trades, and assesses the strength of market trends.

Additionally, the combination of multiple moving averages offers a broader perspective on market movements and can help smooth out short-term fluctuations, providing a clearer picture of long-term trends.

LJmn4Cy.png

Hi all,

I am completely new to Thinkorswim and thinkScript. I wonder if something like Ribbon % OF stocks above 20/50/100/200 DayMA S&P500
https://www.tradingview.com/script/RC1eyBAa-Ribbon-OF-stocks-above-20-50-100-200-DayMA-S-P500/
is available in the studies/strategies. I didn't see it, but maybe it is available but in a different name?

Thanks,
Nirgalli
 
Last edited by a moderator:
Hi all,

I am completely new to Thinkorswim and thinkScript. I wonder if something like Ribbon % OF stocks above 20/50/100/200 DayMA S&P500
https://www.tradingview.com/script/RC1eyBAa-Ribbon-OF-stocks-above-20-50-100-200-DayMA-S-P500/
is available in the studies/strategies. I didn't see it, but maybe it is available but in a different name? I tried to create one by using $SPXA50R, $SPXA100R, and $SPX200R but it didn't work. It's not done yet, but I don't see anything coming out at all from what I have so far. I am guessing it's because there's no volume data for any of these 3 indicators. Any suggestion?



Thanks,
Nirgalli
find below. I couldn't find index for stocks trading above 20-Day moving average in TOS. I found 50/100 and 200.

CSS:
#//@version=4

#study("Ribbon % OF stocks above 20/50/100/200 DayMA S&P500")
#converted by Sam4Cok@Samer800    - 04/2024, No SPX Above 20;

declare lower;

input timeframe = AggregationPeriod.DAY;
input above50 = "$SPXA50R"; #(title="ABOVE 50", type=input.symbol, defval="INDEX:S5FI")
input above100 = "$SPXA100R"; #(title="ABOVE 100", type=input.symbol, defval="INDEX:S5OH")
input above200 = "$SPXA200R"; #input(title="ABOVE 200", type=input.symbol, defval="INDEX:S5TH")
input movAvgLength = 20; #, minval=1)
input reaction = 3; #, minval=1, maxval=5)

def na = Double.NaN;
script rising{
    input src = close;
    input len = 20;
        def rising = fold i = 0 to len with p=1 while p do
                     GetValue(src, i) > GetValue(src, i + 1);
        plot out = rising;
}
script falling{
    input src = close;
    input len = 20;
        def falling = fold i = 0 to len with p=1 while p do
                      GetValue(src, i) < GetValue(src, i + 1);
        plot out = falling;
}
#vwma(source, length)
script VWMA {
input src = close;
input len = 14;
input vol = volume;
    def nom = Average(src * vol, len);
    def den = Average(vol, len);
    def VWMA = nom / den;
    Plot result = VWMA;
}
def P22 = close(Symbol = above50, Period = timeframe);
def P33 = close(Symbol = above100, Period = timeframe);
def P44 = close(Symbol = above200, Period = timeframe);

def p2 = if !isNaN(P22) then P22 else P2[1];
def p3 = if !isNaN(P33) then P33 else P3[1];
def p4 = if !isNaN(P44) then P44 else P4[1];

def MA2 = vwma(P2, movAvgLength);
def MA3 = vwma(P3, movAvgLength);
def MA4 = vwma(P4, movAvgLength);


def direction2 = if rising(MA2, reaction) then 1 else
                 if falling(MA2, reaction) then -1 else direction2[1];

def direction3 = if rising(MA3, reaction) then 1 else
                 if falling(MA3, reaction) then -1 else direction3[1];

def direction4 = if rising(MA4, reaction) then 1 else
                 if falling(MA4, reaction) then -1 else direction4[1];

plot index2 = if MA2 then MA2 else na; #, linewidth=2, color=pcol2)
plot index3 = if MA3 then MA3 else na; #,linewidth=3, color=pcol3)
plot index4 = if MA4 then MA4 else na; #,linewidth=4, color=pcol4)

plot h0 = 0.65; #, "Upper Band", color=color.red, linestyle=hline.style_solid, linewidth=2 )
plot h1 = 0.35; #, "Lower Band", color=color.green, linestyle=hline.style_solid, linewidth=2)

index3.SetLineWeight(2);
index4.SetLineWeight(3);
index2.AssignValueColor(if direction2 > 0 then Color.GREEN else Color.RED);
index3.AssignValueColor(if direction3 > 0 then Color.GREEN else Color.RED);
index4.AssignValueColor(if direction4 > 0 then Color.GREEN else Color.RED);
h0.SetDefaultColor(Color.DARK_GREEN);
h1.SetDefaultColor(Color.DARK_RED);

#-- 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
227 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