OPEN-SOURCE SCRIPT

Universal Ratio Trend Matrix [InvestorUnknown]

Aggiornato
The Universal Ratio Trend Matrix is designed for trend analysis on asset/asset ratios, supporting up to 40 different assets. Its primary purpose is to help identify which assets are outperforming others within a selection, providing a broad overview of market trends through a matrix of ratios. The indicator automatically expands the matrix based on the number of assets chosen, simplifying the process of comparing multiple assets in terms of performance.

Key features include the ability to choose from a narrow selection of indicators to perform the ratio trend analysis, allowing users to apply well-defined metrics to their comparison.

Drawback: Due to the computational intensity involved in calculating ratios across many assets, the indicator has a limitation related to loading speed. TradingView has time limits for calculations, and for users on the basic (free) plan, this could result in frequent errors due to exceeded time limits. To use the indicator effectively, users with any paid plans should run it on timeframes higher than 8h (the lowest timeframe on which it managed to load with 40 assets), as lower timeframes may not reliably load.

Indicators:
  • RSI_raw: Simple function to calculate the Relative Strength Index (RSI) of a source (asset price).
  • RSI_sma: Calculates RSI followed by a Simple Moving Average (SMA).
  • RSI_ema: Calculates RSI followed by an Exponential Moving Average (EMA).
  • CCI: Calculates the Commodity Channel Index (CCI).
  • Fisher: Implements the Fisher Transform to normalize prices.


Utility Functions:
  • f_remove_exchange_name: Strips the exchange name from asset tickers (e.g., "INDEX:BTCUSD" to "BTCUSD").




  • f_get_price: Retrieves the closing price of a given asset ticker using request.security().
  • f_constant_src: Checks if the source data is constant by comparing multiple consecutive values.


istantanea

Inputs:
  • General settings allow users to select the number of tickers for analysis (used_assets) and choose the trend indicator (RSI, CCI, Fisher, etc.).
  • Table settings customize how trend scores are displayed in terms of text size, header visibility, highlighting options, and top-performing asset identification.
  • The script includes inputs for up to 40 assets, allowing the user to select various cryptocurrencies (e.g., BTCUSD, ETHUSD, SOLUSD) or other assets for trend analysis.


Price Arrays:
  • Price values for each asset are stored in variables (price_a1 to price_a40) initialized as na. These prices are updated only for the number of assets specified by the user (used_assets).
  • Trend scores for each asset are stored in separate arrays




Universal Indicator Calculation (f_calc_score):
  • This function allows switching between different trend indicators (RSI, CCI, Fisher) for flexibility.
  • It uses a switch-case structure to calculate the indicator score, where a positive trend is denoted by 1 and a negative trend by 0. Each indicator has its own logic to determine whether the asset is trending up or down.




Array Setting Function (f_array_set):
  • This function populates an array with scores calculated for each asset based on a base price (p_base) divided by the prices of the individual assets.
  • It processes multiple assets (up to 40), calling the f_calc_score function for each.




Conditional Array Setting (f_arrayset):
  • This function checks if the number of used assets is greater than or equal to a specified number before populating the arrays.




Main Logic
  • The main logic initializes arrays to store scores for each asset. Each array corresponds to one asset's performance score.
  • Setting Trend Values: The code calls f_arrayset for each asset, populating the respective arrays with calculated scores based on the asset prices.
  • Combining Arrays: A combined_array is created to hold all the scores from individual asset arrays. This array facilitates further analysis, allowing for an overview of the performance scores of all assets at once.





  • Calculating Sums: A separate array_sums is created to store the total score for each asset by summing the values of their respective score arrays. This allows for easy comparison of overall performance.
  • Ranking Assets: The final part of the code ranks the assets based on their total scores stored in array_sums. It assigns a rank to each asset, where the asset with the highest score receives the highest rank.




Dynamic Table Creation
  • Initialization: The table is initialized with a base structure that includes headers for asset names, scores, and ranks. The headers are set to remain constant, ensuring clarity for users as they interpret the displayed data.
  • Data Population: As scores are calculated for each asset, the corresponding values are dynamically inserted into the table. This is achieved through a loop that iterates over the scores and ranks stored in the combined_array and array_sums, respectively.


Automatic Extending Mechanism
  • Variable Asset Count: The code checks the number of assets defined by the user. Instead of hardcoding the number of rows in the table, it uses a variable to determine the extent of the data that needs to be displayed. This allows the table to expand or contract based on the number of assets being analyzed.
  • Dynamic Row Generation: Within the loop that populates the table, the code appends new rows for each asset based on the current asset count. The structure of each row includes the asset name, its score, and its rank, ensuring that the table remains consistent regardless of how many assets are involved.


Note di rilascio
Add option to Display Summary of the Ratio Trend Matrix.



istantanea
Summary of original Table on the left, Summary of top ranked assets on the right (manipulated with "Highlight Top Assets" input.
Portfolio managementstatisticsTrend Analysis

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?

Declinazione di responsabilità