Celestial Pair Spread Hello friends, after a very long time!
Today, I tried to put into code an idea that came to my mind spontaneously and suddenly.
Note :
This script is experimental and improvable.
I haven't had a chance to try it yet.
TIMEFRAME : 1D (Daily Bars)
CELESTIAL SPREAD
The spread moves in a very limited area and is consistent within itself, especially on days far from the end of the contract.
That's why there is a reassuring sky atmosphere. That's why this name was given completely improvised.
Basic logic of the script
We enter the name of the CME Futures contract we want to enter:
Ex : CL1! , ES1! , ZC1! , NQ1!
The script creates us a pair trade parity divided into secondary contracts.
Example : ES1!/ES2!
What is pair trading?
I will explain briefly here.
For users who are wondering:
www.investopedia.com
Let's get back to our topic.
Now we have created a parity that does not actually exist.
This parity is the manifestation of the relative movements of two contracts.
When the parity rises, ES1! increased,ES2! has fallen.
In the opposite case, We can say: ES1! Contract has been dropped ES2! has increased.
Pair trading is generally a trade that needs to be kept in mind from time to time.
It is a method preferred by professionals who can process very quickly.
Market risk is minimal, but since 2 contracts are purchased, more money is paid and very low percentage profits are made.
It is very expensive to do pair trading, especially with oil and its derivatives and interest security derivatives.
The contract we are considering has micros. (small-item contracts tied to the same value)
So when we switch to our broker MES1!/MES2! We will trade.
For all CME futures :
www.cmegroup.com
Anyway, let's continue:
The script created the parity showing its relationship with the next contract and plotted it as bars.
Celestial bands are just like Bollinger bands, but they consist of 3 bands based on percentage changes rather than standard deviation.
The middle band is obtained from moving averages.
The upper and lower bands are the middle band subjected to a threshold value.
The threshold value can be changed.
0.15 percent was charged for this script.
CAUTION :
As can be seen in the example below;
The most important thing is not to make any transactions when the contract switch dates are approaching.
Therefore, it is recommended to use it just below the main chart.
The blue bars in the parity are
Values that outside the upper and lower threshold values are colored blue.
For this condition
Alerts has been added.
Don't forget to add alert and edit.
MAIN PURPOSE
It is aimed to start a pair trade when such conditions come and to quickly close the trades when the parity basis reaches the value.
OTHER IMPORTANT POINTS
Other issues are broker related issues.
Difference between initial margins and maintanence margins of contracts (between 1! and 2!)
It shouldn't be too high.
The commission should not be too high.
Leverage must be high because the profit percentage is very low.
To calculate leverage you must divide your contract size by the relevant margin requirement.
Sample margin requirement table:
www.interactivebrokers.com
RISKS
It is an experimental and intellectual script,
the risk of contract price differences (maybe it will not leave a profit except for very extreme values)
I remind you of the quickness risk that comes from a two-legged trade.
Alerts definitely synchronized with an audible alert sent to a smartphone as an e-mail notification and displayed on the locked screen for quick action.
Best regards!
Pairtrade
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.
SpreadTrade - Auto-Cointegration (ps5)Decsription: Auto-Cointegration-Based Pair Trading Strategy (revised version)
To review, there are three popular styles of Pair trading: distance-based pair trading, correlation-based pair trading and cointegration-based pair trading. Typically, they require preliminary statistical estimation of the viability of the corresponding strategy.
Basically a pair trade strategy boils down to shorting the outperforming instrument and going long on the underperforming instrument whenever the temporary correlation weakens which means one instrument is going up and another is going down. Apart from the typical cointegration strategy which employs two cointegrated instruments, this script uses just one instrument, in base timeframe and in lagged timeframe, actually making it an auto-cointegration, or better still, an auto-correlation strategy.
Notice that each moving average function may require different Threshold settings.The orange cross symbol indicates the exit points. To filter out the signals use higher values for the LongWindow and the Threshold parameters. Also pay attention that in some cases with some moving averages the color of the signals has to be inverted.