TheTradingParrot

TTP Pair Cipher

Pair 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


版本注释:
Fixed: coin labels were still showing with show coins disabled
版本注释:
According to TradingView using spread charts can cause repainting. ( see spread
repainting
)

In order to prevent this you have to read candles settle one candle late and not just use this for tracking floating PNL but also for entry signals so they all occur consistently with the same timing.

Unfortunately this is not possible when using external signals that read the spread chart while we track floating PNL with one candle back in time since this causes to track profits from before the signal was triggered generating unrealistic inflated results.

I've decided to remove support for external signals and provide for now 2 deal start conditions that are applied to the non repainting settled spread: one candle back in time too.

RSI crossover and PNR crossover.

We could have decided to allow the strategy to repaint to use earlier data but that downside would have been that backtest will quickly get out of sync with the alerts. Using late data is not great but it guarantees that backtest does right what the live strategy does. The exchange can always update later their data on TV causing repainting but that is then impossible to avoid if they do so.
版本注释:
Repaint toggle added. You decide!

Why using repainting? in repainting mode the strategy can take intra candle actions at the cost of backtests getting out of sync with real time.

If you don't allow repainting, backtest and real time should remain in sync (+99% probabilities). The trade-off is that the strategy will only use settle closed candles and it won't be able to take any intra candle decision. This includes all entry and exit events. This means that if you are trading on the 1 hour tf, for example, and the hedge position goes beyond TP or SL this won't activate until the candle closes. This could result in something good or bad depending on the final closing bar price action.
版本注释:
Added max deal drawdown to the stats table. Useful to help with calculations of collateral needed. Different from the existing strategy DD which instead relates to the cumulative strategy PNL.
版本注释:
Two spread modes are now supported:

1) Y/X
2) Y - Hedge *X + constant

Both modes are very popular among pair traders.

I recommend starting with 1) which doesn't use the Hedge and constant value.

Once feeling more confident you can later try using my recently released indicator TTP pair slope/hedge to assist calculating it the slope for a given period. Create an empty chart and plot the spread formula to confirm it helps to turn it into an stationary spread (staying flat as a horizontal line).

You can also use the new constant parameter if the resulting spread ever goes below 0. Just find the minimum value of spread and add a constant to push all values above 0.

Areas below 0 are not tradable since RSI and other indicators won't work properly.


You might notice there are OKX alert controls in this version. OKX alerts will remain disabled but stay tuned for OKX copy trading by end of October.
版本注释:
Data window now also shows all the stats from the table.
版本注释:
FIX: deal max drawdown was calculated wrongly in the stats table.
版本注释:
Added Z-score filter: this will filter any entry signal if the Z-score value is not above the provided threshold parameter. Values of Z-score above 0 tend to revert.

I've seen good results when using values between -0.5 and 1.0 depending on the strategy used.

Join our membership to gain access to the private scripts.
www.thetradingparrot.com
受保护脚本
该脚本是闭源发布的,您可以自由使用它。您可以收藏它以在图表上使用。您无法查看或修改其源代码。
免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?