SectorsThis script attempts to show the relative strength of the 11 sectors in the SPX, which can be accomplished in three ways:
1. Sectors - displays all sector indices as they appear normally
2. Sector Relativity - displays each sector divided by the sum of the other 10 sectors
3. Sector Alpha - displays the alpha of each sector as compared to the sum of the other 10 sectors
I have seen some other iterations of this script that compare each sector to the SPX as a whole, a couple problems with that:
1. SPX sector weightings are unequal and change quarterly, meaning you will get an inaccurate depiction of relative sector strength across time.
2. Even if using an equal-weight SPX, you would be comparing a sector to itself as all 11 sectors are included in the SPX, not just the complementary 10 you are looking to compare one sector to.
For more information on the sectors in the SPX or the calculation of Alpha, visit the links at the top of the script.
*Includes an option for repainting -- default value is true, meaning the script will repaint the current bar.
False = Not Repainting = Value for the current bar is not repainted, but all past values are offset by 1 bar.
True = Repainting = Value for the current bar is repainted, but all past values are correct and not offset by 1 bar.
In both cases, all of the historical values are correct, it is just a matter of whether you prefer the current bar to be realistically painted and the historical bars offset by 1, or the current bar to be repainted and the historical data to match their respective price bars.
As explained by TradingView,`f_security()` is for coders who want to offer their users a repainting/no-repainting version of the HTF data.
Relative Strength Comparison
MAVERICKAMIT01-RELATIVE STRENGTHTHE SCRIPT SIMPLY DIVIDES THE STOCK PRICE BY NIFTY TO MEASURE UNDER PERFORMANCE AND OUT PERFORMANCE WITH NIFTY. YOU CAN CHANGE SETTINGS FROM NIFTY TO ANY OTHER SECTOR LIKE CNX FMCG TO MEASURE SECTOR PERFORMANCE AND UNDER PERFORMANCE !!!
RS.ROC | Relative Strength - Rate of Changes - 4CR CUPFor completeness of Relative Strength studies, the Relative Strength based on rate of changes (ROC) with weighting is coded and presented as well.
The RS.ROC is similar to the formulation of RS by IBD before rank among all the stocks in the market.
The lookback period is relaxed for customizing. Once you set the total lookback period, representing the 4Q, in the indicator, the other shorter lookback periods will be auto-calculated, namely, 1Q, 2Q, 3Q.
A simple moving average of the RS.ROC is also added for your easier analysis on the trend development of the strength.
To use it later at your charting later,
1. Favorite it;
2. Select from your favorite list.
Candlestick RSThis is a candlestick charted Relative Strength indicator. It compares the chosen stock's progress compared to that of the SPY ETF ... ( SPY is used so it should hopefully update intraday). I use this indicator to see which stocks are outperforming the market.
Input Variable Descriptions:
Ratio: this variable is a float (0 to 1) that is basically how close the Candlestick RS is to the actual price action of the chart. (1.0 being right on top of it, 0.0 being as far away as possible from it)
Ballpark SPY price: this variable has to be constant, and due to the way pinescript works, you have to manually put in a ballpark of what SPY is at.
Neither of these variables influences the actual data of the indicator, but rather how it is shown on screen. It's difficult to describe, so I recommend you messing around with the variables and see what changes.
Hope this helps, I find this useful, so I figured I'd publish this... This is my first pine script so forgive me for any errors, just want to help :)
CPR Width + MTF, Offset and BarcolorsDue to the request of some users and inspired by "5 Day ADR ICT Intraday Tracker" I updated "CPR Width" and added extra functionality for your convenience.
RS Line - Gauge Performance vs IndexOverview:
This implementation of the RS Line mimics how Investor's Business Daily and CANSLIM investors measure growth stock performance versus the S&P 500.
If you are looking at a weekly chart, the RS Line is the performance of the stock over the past week versus the S&P 500 over that same time frame. The same logic applies to the daily and monthly charts, only the time frames are different.
If a stock moves up for the day/week/month and the S&P 500 does not, the RS Line will move up. If a stock ends the day/week/month flat, yet the S&P 500 moves up, the RS Line will go down.
Usage:
- Look for an upward sloping line.
- The steeper the line, the better.
- Can be used for viewing long-term trend.
Exponential Regression Slope Annualized with R-squared HistogramMy other indicator shows the linear regression slope of the source. This one finds the exponential regression slope and optionally multiplies it by R-squared and optionally annualizes it. Multiplying by R-squared makes sure that the price movement was significant in order to avoid volatile movements that can throw off the slope value. Annualizing the exponential slope will let you see how much percentage you will make in a year if the price continues at its current pace.
The annualized number is the number of trading days in a year. This and the length might need adjusting for the extra bars that might be in futures or other markets. The number does not have to be a year. For example, it can be a month if you set the number to 20 or so trading days to find how much you would make in a month if price continues at its current pace, etc. This can also be used as an alternative to relative strength or rate of change.
Percentage Relative StrengthA relative strength indicator that compares your main symbol (one on your chart) strength to another symbol by percentage.
The result is plotted as a histogram showing which symbol is rising or falling more in percentage.
In case your chart symbol is TSLA (Tesla) and the indicator 'Symbol to compare' is SPX:
GREEN area (above zero) means TSLA is rising more than the SPX.
RED area (below zero) means TSLA is falling more than the SPX.
To these who wants to understand calculation, it's pretty straightforward.
For each asset we calculate everyday percentage change based on previous close and current close.
We take main asset (chart symbol) percentage and subtract it from percent of change of the symbol we want to compare to.
Result are smoothed by SMA (Simple Moving Average)
You can select different indexes or cfds such as S&P500 (SPX), NASDAQ 100 (NSX), RUSSELL 2000 (RUT) and NASDAQ (IXIC).
Default is S&P 500 (SPX).
Enjoy and Like if you like.
RelativeStrengthComparative_IBD_YRKI am publising Relative Strength Comparative.
It is be used to compare a Stock's Performance against another stock/index (Default NIFTY50)
I also devised a Plot RS Rating which is inspired from IBD's RS Rating and matches to some extent. You can turn off/on the RS Rating as per need.
Example: ITC vs NIFTY 50 it will be ITC / NIFTY
The Indicator can be used in Multiple ways:
1) Check Relative Strength
2) Check RS Rating (This is not Accurate as of now since IBD compares the ratings of all the stocks in an Exchange)
3) Can be used as a Spread Chart for the Division (We need to not divide every time we change Stocks)
4) Design a Template exactly as MarketSmith by using the TradingView feature of "Move to --> Existing Pane Above"
The Formula i used for RS Rating is below with more weightage on the 3 month performance and lesser on 12 month Performance. I am open to Modification of this Formula if a better suggestion
// relative strength IBD style
ThreeMthRS = 0.4*(close/close)
SixMthRS = 0.2*(close/(close*2))
NineMthRS = 0.2*(close/(close*3))
TwelveMthRS = 0.2*(close/(close*4))
Price Relative / Relative StrengthThe Price Relative indicator compares the performance of one security to another. This indicator can be used to compare the performance of a stock against a benchmark index, such as the S&P 500, or its sector/industry group. This makes it possible to determine if a stock is leading or lagging its peers.
The Price Relative is used to gauge relative strength, which is important when it comes to stock selection. Many portfolio managers compare their performance to a benchmark, such as the S&P 500. Their goal is to outperform that benchmark. In order to achieve this goal, managers often look for stocks that are showing relative strength. Enter the Price Relative. The Price Relative rises when a stock shows relative strength and is outperforming its benchmark. Conversely, the Price Relative falls when a stock shows relative weakness and is underperforming its benchmark.
Source: school.stockcharts.com
This script allows the user to
Add a new indicator pane for Price Relative (PR)
Edit the benchmark symbol (Comparative Symbol)
Edit or hide the moving average
Quickly determine if the symbol is outperforming or underperforming its benchmark
Quickly determine if the symbols is trending higher or lower based on a simple moving average
Relative Strength 4DimensionIn the S&C September 2020 article “Tracking Relative Strength In Four Dimensions”, James Garofallou presents a metric for evaluating a security’s strength relative to 11 major market sectors and over several time periods. All this information is squeezed into a single value. Maybe at cost of losing other important information? In this article we’ll look into how to program such a beast, and how it fares when we use it for rebalancing a stock portfolio.
This is a redesigned version for an european point of view.
I used 10 index for the comparison.
feel free to tip me ;-)
Periodic price change comparisonPeriodic price change.
Application:
Sector rotation analysis by comparing different tickers.
Simple statistical analysis (with lookback period) for knowing how good they were.
If you are a believer in sector rotation, you can add different sector stocks to see which of them are lagged behind and buy them.
In this example, you could see tesla periodically fall behind the market. You can buy it when it is on that zone.
And you can also refer to the sharpe ratio and the average gain rate on the chart to see how good the stocks were.
Relative Strength (Mansfield RS)This version of the Mansfield Relative Strength Indicator uses the unflattened version of the indicator recommended on the Stage Analysis website, as the slope angle of "Zero Line" (52 week MA of the stock / S&P 500) gives additional useful information that can't be seen on the traditional flattened version of the Mansfield Relative Strength Indicator.
Price Volume Strength ComparatorBollinger bands says whether price or any source is relatively high or low at any particular point of time. We can apply Bollinger bands on RSI and volume indicator Price Volume Trend to identify if RSI movement or PVT movement is relatively high or low.
By calculating Bollinger %B, we can define the variation in a range between 0 to 1. By applying Bollinger %B on price, volume and strength, we are trying to compare how much they differ relative to each other.
For example, if Bollinger %B of volume is higher than Bollinger %B of price, which may mean, we can still expect continuation of upward movement. If volume %B is lesser, we can interpret this as price has moved more than the volume and may retrace back.
Note: I tried adding multiple volume/strength indicators as input choice. But, if condition did not work with simple string. Have no idea why. I will try adding that later if more people show interest.
Relative Strength Auto ComparisonRelative Strength Comparison with automatic selection of relevant index
Added support for most european and north american exchanges.
SPY RelativeShows an instrument's sentiment in a day (or week) compared to the market (SPY default). The Red line shows bearish sentiment compared to the market and the green is bullish. Technically this works like a proxy for Alpha/Beta factor.
Smart Relative Strength Can Remove False SignalsRelative strength is one of the most useful indicators in the market, highlighting when stocks and sectors are outperforming or underperforming a broader index.
Traditional RS compares the percentage change of one symbol over a given time frame and subtracts the percentage change of the S&P 500 over the same period.
This is handy, but it can produce false signals at times of volatility. For example, when the broader market is crashing, certain sectors may “outperform” simply by falling less than the S&P 500.
Smart Relative Strength addresses this shortcoming by requiring that the symbol’s absolute AND relative returns both be positive. Otherwise a zero is returned.
This was useful last week on the Dow Jones Transportation Average . Using simple relative strength, it had its best one-week performance against the S&P 500 since October 2008. This was obviously a false signal because October 2008 was a time that everything else was crashing.
Smart Relative Strength showed that, excluding periods of overall decline, DJT had its best week since January 2008.
Note: This chart uses a 1-period interval, while the code defaults to 21 periods.
JSE Top 40 Comparative Relative Strength RSI OscillatorThis code is the result of an idea by @MarcoOlivano. The question was that if putting the comparative relative strength as an RSI oscillator would help in understanding the relative strength of the stock to the overall market? As we both trade the JSE I have made the JSE:J200 or Top 40 the basis for comparison. This can be changed in the settings dropdown if you want to compare with the All Share Index (JSE:J201) or other markets such as the S&P.
On the chart above I have included the Comparative Relative Strength as a reference together with the Comparative Relative Strength RSI.
If you use the indicator or adapt it please let me know if it works for you, how you use it and if it has any value.
natLogarithmicRegressionCurveThis is my attempt to rebuild the Momentum Strategy as read in the book "Stocks on the move".
Correlation MatrixIn financial terms, 'correlation' is the numerical measure of the relationship between two variables (in this case, the variables are Forex pairs).
The range of the correlation coefficient is between -1 and +1. A correlation of +1 indicates that two currency pairs will flow in the same direction.
A correlation of -1 indicates that two currency pairs will move in the opposite direction.
Here, I multiplied correlation coefficient by 100 so that it is easier to read. Range between 100 and -100.
Color Coding:-
The darker the color, the higher the correlation positively or negatively.
Extra Light Blue (up to +29) : Weak correlation. Positions on these symbols will tend to move independently.
Light Blue (up to +49) : There may be similarity between positions on these symbols.
Medium Blue (up to +75) : Medium positive correlation.
Navy Blue (up to +100) : Strong positive correlation.
Extra Light Red (up to -30) : Weak correlation. Positions on these symbols will tend to move independently
Light Red (up to -49) : There may be similarity between positions on these symbols.
Dark Red: (up to -75) : Medium negative correlation.
Maroon: (up to -100) : Strong negative correlation.
FX Currency Strength IndicatorFX Currency strength indicator is a visual guide that demonstrates which currencies are currently strong, and which ones are weak.
FX Currency strength indicators include multiple calculation to choose from
1. Relative Strength Index (RSI)
2. True Strength Index (TSI)
3. Absolute Strength Index (ASI)
4. Linear Regression Slope (LRS)
5. Rate of Change (ROC)
6. Z-Score
Three display modes
1. Lines
2. Columns
3. Areas
Function Highest/Lowest by PeterONo matter how much I like PineScript, there are still things missing in the language. One of the most annoying issues is that you cannot set dynamic length value for highest/lowest functions. This length must be fixed integer. But it doesn't make sense in a lot of cases, when you'd like to know what was the highest/lowest value of a series SINCE EVENT in the past, but you don't know WHEN this event exactly happened.
Us, coders would like to do this: `highest(series,barssince(...))`
But it is not working.
Numerous coders are using RicardoSantos' f_highest/f_lowest script (), probably the most often copy/pasted snippet of PineScript code out there. It is doing more-less what `highest(series,barssince(...))` would be doing, but with hardcoded max bars back.
Ricardo is my idol by the way, but that didn't stop me from creating my own version of Highest/Lowest functions. They are fast, simple, effective and very light for Pine engine.
Please treat this as an OPEN SOURCE snippet of code, which can be used in variety of ways.
I have implemented a simple use-case myself, to demonstrate what can be done. The example shows what was the highest/lowest value of RSI since the previous cross of Stochastic. So that you don't enter SHORT on Stochastic crossunder, if RSI didn't reach oversold (<30) since the previous Stochastic crossunder = aka maybe the downtrend has exhausted.
I'm sure you'll find plenty of use cases for it in your studies and strategies as well. If you create your own code using my Highest/Lowest functions, don't hesitate to put a link down here in comments.
P.S. This is not a strategy in any way, so don't ask me "does it backtest well?".
P.S.2 This code doesn't repaint as well ;)