Symbols Correlation, built for pair tradingOverview:
This script is designed for pairs trading. If you are not familiar with pairs trading, I suggest learning about it, as it can be a profitable strategy in neutral markets (or neutral trends between two assets). The correlation between two assets is the foundation of pairs trading, and without it, the chances of making a profit are low.
Correlation can be described in two opposite ways:
1: Absolute positive correlation (meaning the asset prices move together).
-1: Absolute negative correlation (meaning the asset prices move in opposite directions).
Any value between 1 and -1 indicates some degree of correlation, but generally, values higher than 0.7 or lower than -0.7 are considered significant.
Features:
Typically, correlation is measured using the closing prices. This script adds three more correlation studies based on open, high, and low prices. By using all four lines, we can get a better understanding of the pair's correlation.
How to Read This Indicator:
To use this indicator effectively, you need to input your pair as a ratio. For example, if your pair is TSN and ZBH, enter it in the symbol search as: TSN/ZBH
Gray Area : This area indicates "no high correlation" (default is between -0.8 and 0.8, adjustable in the settings).
Gray Line : This represents the close correlation within the "no high correlation" range.
Green Line : This represents the close correlation within the "high correlation" range.
Dot Lines : These represent the open, high, and low correlations.
Example Interpretations:
A : All four lines are close together & the line is green – very good correlation!
B : The line is gray, and the dot lines are apart – not a strong correlation.
C : When the close correlation remains green for a long time, it signals a strong correlation.
Application in Pairs Trading:
In pairs trading, aim for the highest possible correlation, and it is important to have a sustained correlation over a long period. Pairs that correlate only part of the year but not consistently are less reliable for pairs trading.
This is an example for good correlation for pairs trading:
This is an example for bad correlation for pairs trading:
Here is a view of my full indicators when doing pairs trading:
Pairs
Trend Momentum Strength Indicator, Built for Pairs TradingOverview:
This script combines multiple indicators to provide a comprehensive analysis of both trend strength and trend momentum. It is tailored specifically for pairs trading strategies but can also be used for other trading strategies.
Benefit of Comprehensive Analysis:
Having an indicator that evaluates both trend strength and trend momentum is crucial for traders looking to make informed decisions. It allows traders to not only identify the direction and intensity of a trend but also gauge the momentum behind it. This dual capability helps in confirming potential trade opportunities, whether for entering trades with strong trends or considering reversals during overbought or oversold conditions. By integrating both aspects into one tool, traders can gain a holistic view of market dynamics, enhancing their ability to time entries and manage risk effectively.
Features:
* Trend Strength:
Enhanced ADX Formula: The script includes modifications to the standard ADX formula along with DI+ and DI- to provide more responsive trend strength readings.
Directional Indicators: DI+ (green line) indicates positive directional movement, while DI- (red line) indicates negative directional movement.
Trend Momentum:
Modified Stochastic Indicators: The script uses %K and %D indicators, modified and combined with ADX to give a clear indication of trend momentum.
Momentum Strength: This helps determine the strength and direction of the momentum.
Trading Signals:
Combining Indicators: The script combines ADX, DI+, DI-, %K, and %D to generate comprehensive trading signals.
Optimal Entry Points: Designed to identify optimal entry points for trades, particularly in pairs trading.
Colored Area at Bottom:
This area provides two easy-to-read functions:
Color:
Green: Upward momentum (ratio above 1)
Red: Downward momentum (ratio below 1)
Height:
Higher in green: Stronger upward momentum
Lower in red: Stronger downward momentum
Legend:
Green Line: DI+ (Positive)
Red Line: DI- (Negative)
Black Line: ADX
How to Read This Indicator:
1) Trend Direction:
DI+ above DI-: Indicates an upward trend.
DI- above DI+: Indicates a downward trend.
2) Trend Strength:
ADX below 20: Indicates a neutral trend.
ADX between 20 and 25: Indicates a weak trend.
ADX above 25: Indicates a strong trend.
Trading Signals in Pairs Trading:
Neutral Trend: Ideal for pairs trading when no strong trend is detected.
Overbought/Oversold: Uses %K and %D to identify overbought/oversold conditions that support trade decisions.
Entry Signals: Green signals for long positions, red signals for short positions, based on combined criteria of neutral trend strength and supportive momentum.
Application in Pairs Trading:
Neutral trend: In pairs trading strategies, where neutral movement is often sought, this indicator provides signals that are especially relevant during periods of neutral trend strength and supportive momentum, aiding traders in identifying optimal entry
Risk Management: Combining signals from ADX, DI+, DI-, %K, and %D helps traders make more informed decisions regarding entry points, enhancing risk management.
Example Chart (The indicator is on the upper right corner):
Clean Presentation: The chart only includes the necessary elements to demonstrate the indicator’s functionality.
Demonstrates: Overbought/oversold conditions, upward/downward/no momentum, and trading signals with/without specific scenarios.
two_leg_spread_diffThis script helps you discern the relative change of each leg in a two-legged spread over a given period. The main plot is a difference in log return over the number of bars identified by the "lag" parameter. E.g. if "lag" is 10 and leg one has increased 3% over the past ten bars, while leg two has only increased 1%, the plot value is 2%. The main plot is also colored blue when leg one increases while leg two decreases on a given bar, and red if the opposite is true. This feature identifies periods where the correlation between the two legs diminishes. The one and two standard deviation of the main plot is also plotted in faint background lines. Additionally, a table indicates the percentage in which the main plot is within one standard deviation (acc 1) and two standard deviations (acc 2). Note that the standard deviation updates on each bar, so the current standard deviation is not the one used to calculate the accuracy. Rather, if there are N bars, N different standard deviation readings have been used to compute the accuracy statistics.
The inputs are:
- timeframe: the timeframe of the chart
- leg1_sym: the symbol of the first leg
- leg2_sym: the symbol of the second leg
- lag: the number of bars back to reference for computing the log return of each leg
- anchor_to_session_start: for intraday charts only, this overwrites the "lag" input so that the "lag" always sets the point of comparison to the session start. This setting is used to compute the relative change over a single session.
Bollinger Pair TradeNYSE:MA-1.6*NYSE:V
Revision: 1
Author: @ozdemirtrading
Revision 2 Considerations :
- Simplify and clean up plotting
Disclaimer: This strategy is currently working on the 5M chart. Change the length input to accommodate your needs.
For the backtesting of more than 3 months, you may need to upgrade your membership.
Description:
The general idea of the strategy is very straightforward: it takes positions according to the lower and upper Bollinger bands.
But I am mainly using this strategy for pair trading stocks. Do not forget that you will get better results if you trade with cointegrated pairs.
Bollinger band: Moving average & standard deviation are calculated based on 20 bars on the 1H chart (approx 240 bars on a 5m chart). X-day moving averages (20 days as default) are also used in the background in some of the exit strategy choices.
You can define position entry levels as the multipliers of standard deviation (for exp: mult2 as 2 * standard deviation).
There are 4 choices for the exit strategy:
SMA: Exit when touches simple moving average (SMA)
SKP: Skip SMA and do not stop if moving towards 20D SMA, and exit if it touches the other side of the band
SKPXDSMA: Skip SMA if moving towards 20D SMA, and exit if it touches 20D SMA
NoExit: Exit if it touches the upper & lower band only.
Options:
- Strategy hard stop: if trade loss reaches a point defined as a percent of the initial capital. Stop taking new positions. (not recommended for pair trade)
- Loss per trade: close position if the loss is at a defined level but keeps watching for new positions.
- Enable expected profit for trade (expected profit is calculated as the distance to SMA) (recommended for pair trade)
- Enable VIX threshold for the following options: (recommended for volatile periods)
- Stop trading if VIX for the previous day closes above the threshold
- Reverse active trade direction if VIX for the previous day is above the threshold
- Take reverse positions (assuming the Bollinger band is going to expand) for all trades
Backtesting:
Close positions after a defined interval: mark this if you want the close the final trade for backtesting purposes. Unmark it to get live signals.
Use custom interval: Backtest specific time periods.
Other Options:
- Use EMA: use an exponential moving average for the calculations instead of simple moving average
- Not against XDSMA: do not take a position against 20D SMA (if X is selected as 20) (recommended for pairs with a clear trend)
- Not in XDSMA 1 DEV: do not take a position in 20D SMA 1*standart deviation band (recommended if you need to decrease # of trades and increase profit for trade)
- Not in XDSMA 2 DEV: do not take a position in 20D SMA 2*standart deviation band
Session management:
- Not in session: Session start and end times can be defined here. If you do not want to trade in certain time intervals, mark that session.(helps to reduce slippage and get more realistic backtest results)
KAIRI RELATIVE INDEXAn old but gold Japanese indicator for Mean Reverting strategies and ideal for Pairs Trading...
The Kairi Relative Index measures the distance between closing prices and a Moving Average in percent value (generally SMA).
Extreme reading in the KRI are considered buy and sell signals.
Extreme readings will vary by asset, with more volatile assets reaching much higher and lower extremes that more sedate assets.
The KRI is not an accurate timing signal, and therefore, should be combined with other forms of analysis to generate trade signals.
You can calculate percent difference between the price and 10 different types of Moving Averages in this version of KAIRI as:
SMA : Simple Moving Average
EMA : Exponential Moving Average
WMA : Weighted Moving Average
TMA : Triangular Moving Average
VAR : Variable Index Dynamic Moving Average a.k.a. VIDYA
WWMA : Welles Wilder's Moving Average
ZLEMA : Zero Lag Exponential Moving Average
TSF : True Strength Force
HULL : Hull Moving Average
VWMA: Volume Veighted Moving Average
Personal advice: try using bigger length of Moving Averages like 50-100-200 for pairs and mean reversion strategies
Pairs Trading (basic OLS regression)Pairs trading using hedge ratio.
Firstly, it calculates hedge ration using OLS linear regression.
Then it calculates spread and z-score of spread.
if spread in specific range (which it's possible to change in settings) it makes Long/Short orders.
The very basic script.
level_statsThis script tells you the percentage of time an instrument's closing value is above and below a level of your choosing. The background color visually indicates periods where the instrument closed at or above the level (red) and below it (blue). For "stationary-ish" processes, you can get a loose feel for the mean, high, and low values. The historical information conveyed through the background coloring can help you plan derivatives trades. Try with your favorite pairs, commodities, or volatility indices.
Usage: pick a level of interest using the input.
Currency PairsHello All,
This script shows comparisons between major currencies for the specified time frame. it checks the change since the last bar and set the background and text color.
You can change time frame and background & text colors. you can also change the location of the table as you wish.
in the following example, the script was added to the chart two times, "4 hours" and "Day" time frames used. also changed the colors.
Enjoy!
Strategy Smart Forex Buy Sell Signal by LukasHi, I just convert my Smart Forex Buy Sell Signal into strategy.
BUY and SELL signal base on Price action, RSI , and Correlation between Forex Major Pairs.
It's only work for Forex Major Pairs because I only took their data.
Included alert : Spec, Buy, Strong
Recommended to wait for double signal :
Spec Buy > Buy or Spec Sell > Sell
Buy > Strong Buy or Sell > Strong Sell
So execute after the second signal triggered.
On this strategy I exclude Spec Sell/Buy on strategy test.
I use simple Profit/Loss 200/100 and 5 pyramid, you can play around with the setting.
And to improve the odds, simply use my Currency Strength Indicator to pick what pairs to trade. Choose Strong Vs. Weakness to get maximal profit. It help me to stay away from ranging pairs.
Any feedback are welcome :)
Smart Forex Buy Sell Signal by LukasHi again!
So, this is BUY and SELL signal base on Price action, RSI, and Correlation between Forex Major Pairs.
It's only work for Forex Major Pairs because I only took their data.
Included alert : Spec, Buy, Strong
Recommended to wait for double signal :
Spec Buy > Buy or Spec Sell > Sell
Buy > Strong Buy or Sell > Strong Sell
So execute after the second signal triggered.
It's indicate the trend.
Looking forward for your feedback to improve the script.
Thank you.
It's better combine it with Moving average indicator to indicate direction, I use Moving Average Adaptive Q from cheatcountry to help me make decision.
Buy Sell BandsBuy Sell Bands is a super simple indicator based on the mean reversion (range trading) strategy that shows you exactly where to buy, sell and close trades on every chart, market and timeframe.
It's best used together with our Range Strength indicator to identify when the market is in a range mode, this is the best time to take the entry signals from the Buy Sell Bands.
How Is It Different From Other Indicators?
- Designed specifically for the mean reversion (range trading) strategy
- Upper and lower bands are based on current and past volatility
- Aren't as sensitive to "squeezes" after periods of contracted volatility
- Works well in conjunction with the Range Strength Indicator to confirm entry signals
- Helps identify good "pair trading" opportunities
- Can be applied to all markets and timeframes
How To Use The Indicator?
1) Visit our website URL shown below this description and signup
2) We will then grant your TradingView username permission to use our indicators
3) Go to your Indicators window, then the Invite-Only section and add our indicators to your chart
4) Our indicators will then show on every chart you now look at
5) You can set up alerts to be notified in real time of trading signals from our indicators
6) Read our user manual for all the best tips on how to use our indicators as part of a range trading strategy
7) Feel free to reach out to us for personal one-on-one help with getting setup
What Markets and Conditions Does It Work Best On?
All markets cycle between trending and ranging modes, and the key to successfully using these indicators is identifying when the market is in or about to go into a range trading mode, and as such it can be applied to all markets and timeframes.
Some markets and timeframes trade within ranges more predictably than others, for example Forex, Cryptocurrencies, and Futures on the 15 minute timeframe during the US night session can work well due to the lack of price sensitive news creating lasting trends. With Stocks & ETFs on the 5 minute timeframe during the midday session on large cap blue chip stocks with no recent news releases can show strong range trading environments to use our indicators in.
In addition to single markets, you can also use our indicators on pair charts, for example Coca Cola(KO) versus Pepsi(PEP), you can do this by entering KO/PEP inside your TradingView chart quote box and it will bring up a pair chart. Our indicators will show buy and sell signals right on the pair chart just like any other single instrument chart. You can get very creative with what type of pairs you can come up with.
Our indicators are primarily designed for day trading and swing trading, however they can also be used for position trading and investing by identifying technically oversold and overbought range levels that are based on current and past volatility around a dynamic average price, for this we recommend using a weekly chart to identify longer trading opportunities.
As always indicators should be used as part of a trading strategy to assist in making decisions, instead of just blindly following every signal they produce you should always seek to compliment technical trading signals with additional analysis to reduce your risk and increase your odds of making a winning trade.
Examples Of Use On Various Markets and Timeframes
GBP vs CHF Forex Pair 15 Minute Chart
Tesla Stock 1 Minute Chart
Bitcoin vs USD Crypto Pair 15 Minute Chart
Micro E-Mini SP500 Futures 1 Minute Chart
Mastercard vs Visa Stock Daily Pair Chart
To gain access to the Buy Sell Bands and Range Strength Indicators visit our website shown below.
Happy Range Trading :)
Symbols PairDraws the ratio between two input symbols.
You might find patterns in the ratio.
# Open Source
The code is open source @ github.com and uses the commonpine library github.com
Forex Correlations HeatmapA utility tool to find linear relationships between major forex pairs and specified symbol.
Features
30 well known forex pairs (Pine Script has its limits and incomprehensible "study" errors)
Ability to specify any symbol to see correlations
Ability to specify a preferred timeframe
Ability to specify correlation lookback
Ability to specify different sources (standard prices, volumes, true range, double true range)
How to interpret
The darker the color, the stronger the correlation
Green colors mean positive correlations
Red colors mean negative correlations
Transparent colors mean no correlation or absence of the symbol data
How to get access
PM me for more details
Supported pairs
USDCAD
USDBRL
USDCHF
USDRUB
USDJPY
USDCNY
CADCHF
CADJPY
EURUSD
EURCAD
EURGBP
EURCHF
EURRUB
EURJPY
EURAUD
EURNZD
CHFJPY
GBPUSD
GBPCAD
GBPCHF
GBPJPY
GBPAUD
GBPNZD
AUDUSD
AUDCAD
AUDCHF
AUDJPY
AUDNZD
NZDUSD
NZDJPY
Other similar indicators of mine:
Crypto Correlations Heatmap
Forex Correlations
Forex CorrelationsA utility tool to find linear relationships between different currency pairs and
specified symbols. This is another private indicator of mine.
Features
37 well known Forex pairs
3 correlation display modes ( Positive and Negative , Positive , Negative )
Ability to specify any symbol to see correlations
Ability to specify a preferred timeframe
Readable and optimized code
How to get access
Buy for 1199$ (One-time payment, Source Code Transfer, Sole ownership)
Buy for 539$ (One-time payment, Full-time access, Multi ownership)
Make the symbolic monthly donations to support my open source work (Donate-per-use, Multi ownership)
Supported pairs
USDCAD
USDMXN
USDBRL
USDCHF
USDRUB
USDTRY
USDZAR
USDJPY
USDCNY
USDHKD
CADCHF
CADJPY
EURUSD
EURCAD
EURGBP
EURCHF
EURRUB
EURTRY
EURJPY
EURCNY
EURAUD
EURNZD
GBPUSD
GBPCAD
GBPJPY
GBPCNY
GBPAUD
GBPNZD
AUDUSD
AUDCAD
AUDCHF
AUDJPY
AUDCNY
AUDNZD
NZDUSD
NZDJPY
NZDCNY
Security Tracker - BronzeThis Indicator will be the most simple form of this code, with Silver and Gold versions to come.
Tracked Security - BTCUSD in this example but can be changed anything.
Index - Current Security / Tracked Security
Inverse Index - (1 / Index)
(Current Security = ETHUSD in this example)
Works across all periods and Securities.
Can format lines and colours, but won't be appropriate to plot all three lines at once.
Easily see currency pair without cluttering up your chart or requiring another chart (especially for members with free subscriptions).
Can be BTC vs SNP...if you wanted, something which you couldn't find in the standard list.
I have experimented with several combinations, but if there are any issues, let me know.
MACD Study DASH/BTC 3H ALERTS for AutoviewAutoview qualified Study Script Alerts for Autoview
Please Set Up Alert 1x Bars Close
For Margin Trading (Poloniex)
ULTIMATE PINE INJECTOR V1.2 INSERT
MACD Created by user ChrisMoody
NO REPAINT
With Stopp Loss and Trailing Stopp and Backtest
Now is for Free for all !
Pair Strength: Updated Version of the one by GlazI updated this version used for Forex with Stock&Index related instruments. Enjoy.
Pair Strength BasketAgain thanks to LazyBear for bringing over the wavetrend indicator and glaz for the idea of the basket of currencies. This is a power index based on the wavetrend indicator, I cut it down to 5 securities per currency since the limit of securities I could call was 40. I like to use to see which pair is the most OB/OS as it likely presents the best profit potential.
AUD = Yellow
CAD = Gray
CHF = Maroon
EUR = Blue
GBP = Red
JPY = Purple
NZD = Lime
USD = Green
Reverse ParityShows the reverse graph of the forex pairs. Includes three exponential moving avarages. Option to show Bollinger bands.
Currency Pairs High Low RangeIndicator gives the High-Low range of 18 currency pairs. There is a High Ave which is the average of the top four (you may need to adjust which ones are in the average) as well as the bottom four Low Ave. The picture is of a weekly chart with the indicator set at 12 week average of the High-Low range with a .7 (70%) multiplier. When I am looking for week long trades with lots of movement I pick my pairs based on the most actives with a 70% capture of the range as a guide line of when to exit. Sometime when I am not in the mood for volatility I go with the ones in the Low Ave area. Further, when I day trade I set the indicator to a 1Day chart and move the percent to 20% or 30% as a guideline to tell when to get out of a trade.
Kaufman Stress IndicatorStress Indicator, first proposed by Mr. Perry Kaufman, provides an easy way for trading pairs / arbs.
Kaufman's trading rules for Stress Indicator:
- Decide on a pair to trade: For ex., AAPL v QQQ
- Calculate the Stress Indicator (SI) for that pair
- Buy the stock when SI 50
- Calculate the 60-day moving average of QQQ
- If the trend of QQQ is down, hedge the stock position with QQQ equal to the risk of the stock using the 20-day ATR of each
- Exit the hedge when the stock position exits, or exit the hedge when the trend of QQQ turns up
- Do not trade stocks under $3
Explanation of all potential SI applications is beyond this post. For more info:
- ptasite.s3.amazonaws.com
- www.futuresmag.com
- kaufmansignals.com
- TASC 2014 March issue.
Though Kaufman's Stress stategy is built on top of this Stress Indicator, I suggest reading up his full strategy guidelines before applying this.
Kaufman suggests using 60SMA on the index to track the slope. I have included a custom SMA (find it in the middle pane) that can show SMA for any selected symbol. Use the guide below to import that in to your charts: drive.google.com