Z-Score Pairs TradingTitle: Z-Score Pairs Trading Indicator
Description:
This indicator implements a Z-score based pairs trading strategy, allowing traders to identify potential statistical arbitrage opportunities between two selected assets.
Key Features:
- Calculates Z-score for the price difference between any two user-selected symbols
- Visualizes Z-score with customizable thresholds for signals
- Generates long and short signals based on extreme Z-score values
- Adaptable to various markets including stocks, ETFs, and commodities
How It Works:
1. The indicator calculates the price difference between two selected symbols.
2. It then computes the Z-score of this difference, showing how far the current spread deviates from its historical average.
3. When the Z-score exceeds set thresholds (default ±2), the indicator generates trading signals.
Settings:
- Symbol A and Symbol B: Select any two tradable symbols to compare
- Lookback Period: Number of periods for calculating the moving average and standard deviation
Interpretation:
- Z-score above 2: Potential short signal (pair is likely overextended)
- Z-score below -2: Potential long signal (pair is likely oversold)
- Z-score between -2 and 2: Normal trading range, no signals
Visual Aids:
- Blue line: Z-score
- Dashed lines: Threshold levels at 0, ±1, and ±2
- Green triangles: Long signals
- Red triangles: Short signals
Disclaimer:
This indicator is for educational and research purposes only. Trading carries a high level of risk. Always conduct your own analysis and manage your risk appropriately before entering any trade.
Made by @marekfleisi
Pairstrading
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:
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.
TTP Pair Slope/HedgePair slope/hedge uses linear regression to calculate the hedge ratio (slope) between the two assets within a period.
It allows you to specify a "from" and a "to" candle.
Example:
"A regression from 1000 candles back in time and ignore the last 100 candles. This would result in making a regression of 900 candles in total."
The formula used to perform the regression with the assts X and Y is:
Hedge =
mean( (X-mean(X))^2 )
——————————————————
mean( (X-mean(X)) * (Y-mean(Y)) )
You can later use the hedge in a chart of X - Hedge * Y
(Confirm with 1 / hedge )
If the plot is stationary the period tested should look like stationary.
If you cross an imaginary horizontal line across all the values in the period used it should look like a flat channel with values crossing above and below the line.
The purpose of this indicator is to help finding the linear regression test used for conintegration analysis. Conintegration assets is one of the requirements to consider assets for pair and hedge trading.
TTP Pair CipherPair Cipher can run your hedge pair trading strategy.
Pair cipher can use a spread chart (two assets ratio or difference) to manage a hedge position consisting of two assets: one long and one short position.
Event though the spread chart is used to determine the entries and exits each coin price action is used to calculate floating PNL.
It supports different bot platforms. It's backtestable and can run live.
Features:
- Internal and external entry signal
- In-chart realised PNL plot
- Hedge position floating PNL chart
- Individual floating PNL for each long and short ("show coins" toggle)
- Retracement exit strategy: determine at which retracement factor to exit your position while in profit
- PNL RSI exit strategy: determine at which RSI level crossunder you'd like to exit. RSI is applied to the floating PNL
- Static TP/SL levels
- ATR TP/SL levels with individual factors. When ATR is selected the TP or SL acts as a multiplier of ATR instead.
- On-chart debug labels for alerts
- Intra candle alert: signals can trigger intra candle in this mode, but this mode will cause repainting. Example: if the position goes below SL intra candle, the alert will be sent, but later if it goes in profit before closing the candle, the backtest will continue with the position open. The backtest does NOT have access to the intra candle data. Alert intra candle reduces the risk of not applying SL.
Example of setup:
1) Load an empty 1 hour timeframe chart with the spread BYBIT:REQUSDT.P / BYBIT:REEFUSDT.P
2) Select an investment amount
3) Select TP 1.2 and enable ATR
4) Select SL 1.1 and enable ATR
5) Select RSI profits of crossunder 70
6) Don't enable external signal (you can try with TTP PNR)
7) Select BYBIT:REQUSDT.P as symbol 1
8) Select BYBIT:REEFUSDT.P as symbol 2
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.
Theft Indicator - Pip GainerWhat is our indicator?
Theft Indicator - Pip Gainer is one of our recent published scripts that shows price action on a certain period of time (We Use a modified version of ATR). We take pride in enabling trading to become easier for the experienced and the non-experienced traders around the globe. Buy & Sell alerts will be fired once a condition in our algo is met.
Does it Repaint?
Our indicator does NOT re-paint. Although while setting an alert it may pop up the repaint alert, please take into consideration that once a signal is fired on a "CLOSED BAR", our signal will never disappear, they do not repaint.
What Markets is it usable with?
This version is dedicated to FOREX markets, we encourage using it for low timeframes starting the 3 minute to the 15 minute timeframe. WE RECOMMEND USING THIS IN THE FOREX MARKET, ESPECIALLY WITH CURRENCY PAIRS.
How to use:
Simple plug and play it to your chart, in addition to a few other indicators we will recommend to you (we still have not published them yet), and this will confirm your trades. You can also connect TV alerts with a bot and let it run. Please be aware that SLIPPAGE time is important, If you run a bot on this indicator you HAVE to know that the buy/sell price will be on the bar AFTER the Candle close (For example: the BUY/SELL alert is on a candle, the buy/sell your bot or you will execute WILL be in the following candle depending on your trading system. We advise you to not leave the bot to trade on its own, you have to monitor and have a specific syntax that we will help you with creating according to your trading style.
How are the Buy/Sell Alerts fired?
We use the simple ATR (Average True Range) indicator. However we have modified the indicator to serve our trading system. Check below for a definition of what ATR is:
What is Average True Range - ATR?
The average true range (ATR) is a technical analysis indicator that measures market volatility by decomposing the entire range of an asset price for that period. Specifically, ATR is a measure of volatility introduced by market technician J. Welles Wilder Jr. The true range indicator is taken as the greatest of the following: current high less the current low; the absolute value of the current high less the previous close; and the absolute value of the current low less the previous close. The average true range is then a moving average, generally using 14 days, of the true ranges.
Why is our indicator special and different from the normal ATR indicators?
We have modified the mathematical equation and changed it slightly to give more accurate signals, we do not promise all trades are profitable, the use of this indicator is up to your own judgement and liability. We believe that we have an indicator like no other ATR.
P.S: This is not financial advice, we are just sharing our indicator that we know has good results, and it will take time for people in -ve profiles to recover losses and for the profiting to be more profitable. We use a specific trading method that only works with it
You can contact me for more information about the indicator, Goodluck :)
RW Simple Pairs TradeA Simple Implementation of a Pairs Trading Strategy
It uses a simple moving average of specified length (default = 20) and enters at cutoffs set by Entry ZScore. Trades are exited at the moving average.
It is intended to be run on pairs of stocks. To Spread KO and PEP, for example, use the ticker KO / PEP * 1000
To visualise the trade better add Bollinger bands to your charts, corresponding to the SMA length and Entry ZScore criteria you specified.