Return Dispersion Matrix Strategy [The Quant Science] by thequantscience

By thequantscience

Performance Metrics

Description

This is a simple buy and sell strategy developed using the Dispersion Return Matrix indicator.Before proceed, if you are new to Dispersion Return MatrixAbout Dispersion Return Matrix: https://www.tradingview.com/script/ZN19COW6-Return-Dispersion-Matrix-The-Quant-Science/This strategy script highlights the potential of Pine Script, which makes it easy to incorporate quantitative ideas into your trading strategy. In this example, the algorithm decides which type of entry to choose based on the current market conditions. 🚦🟢 When Quadrant Q1 is dominant, the market is in a strong trend phase and is suitable for trend-following and bullish breakout strategies. Strat will use a trend-following approach for entries in this market phase.🚦🟢 When Quadrant Q2 indicates a mean reverting market where buyers step in immediately when prices fall, suitable for accumulation strategies on pullbacks. In this phase, we will use RSI oversold entries.🚦❌ When Quadrants Q2 and Q3 dominate the market, no trading is conducted, as there are no trading opportunities for our strategy during this phase.What is it for?To test the indicator's functionality within a trading strategy.To demonstrate how to structure a trading strategy by integrating the Dispersion Return Matrix into your code.The algorithm monitors the market and trades only when quadrants Q1 and Q2 are the winners, ensuring that it trades during a favorable market condition. The algorithm never trades when Q3 and Q4 dominate the market.Depending on the winning quadrant, the algorithm applies two different entry strategies:🏆Q1 Win: Trend following strategy🟢 Entry condition: closing price higher than the previous closing price and price above the 20-period SMA.Pine Script®trend_following_strat_entry = close > close[1] and close > sma🏆Q2 Win: Mean reverting strategy🟢 Entry Condition: The RSI(14) indicator crosses below the oversold level of 35.Pine Script®mean_revert_strat_entry = ta.crossunder(rsi, 35)Exits are always calculated using a take-profit and a fixed percentage stop-loss. The take-profit and stop-loss values are calculated based on the entry price of the opening trade.The values set in the code are 🟢 5% for the take-profit and 🔴 15% for the stop-loss.Pine Script®tp = 5sl = 15The capital used for trading is 10% of the initial capital.Pine Script®qty_order := (strategy.initial_capital * 10)/100Opens only one trade at a time.The algorithm highlights in white on the chart the market periods when Q3 and Q4 dominate the market, making it easy to assess the strategy's reliability in the past.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView