PINE LIBRARY

analytics_tables

Library "analytics_tables"
📝 Description
This library provides the implementation of several performance-related statistics and metrics, presented in the form of tables.
The metrics shown in the afforementioned tables where developed during the past years of my in-depth analalysis of various strategies in an atempt to reason about the performance of each strategy.
The visualization and some statistics where inspired by the existing implementations of the "Seasonality" script, and the performance matrix implementations of QuantNomad and ZenAndTheArtOfTrading scripts.
While this library is meant to be used by my strategy framework "Template Trailing Strategy (Backtester)" script, I wrapped it in a library hoping this can be usefull for other community strategy scripts that will be released in the future.

🤔 How to Guide
To use the functionality this library provides in your script you have to import it first!
Copy the import statement of the latest release by pressing the copy button below and then paste it into your script. Give a short name to this library so you can refer to it later on. The import statement should look like this:


There are three types of tables provided by this library in the initial release. The stats table the metrics table and the seasonality table.
Each one shows different kinds of performance statistics.

The table UDT shall be initialized once using the `init()` method.
They can be updated using the `update()` method where the updated data UDT object shall be passed.
The data UDT can also initialized and get updated on demend depending on the use case

A code example for the StatsTable is the following:

A code example for the MetricsTable is the following:

A code example for the SeasonalityTable is the following:


🏋️‍♂️ Please refer to the "EXAMPLE" regions of the script for more advanced and up to date code examples!

Special thanks to Mrcrbw for the proposal to develop this library and DCNeu for the constructive feedback 🏆.

getTablePos(ypos, xpos)
  Get table position compatible string
  Parameters:
    ypos (simple string): The position on y axise
    xpos (simple string): The position on x axise
  Returns: The position to be passed to the table

method init(this, pos, height, width, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor)
  Initialize the stats table object with the given colors in the given position
  Namespace types: StatsTable
  Parameters:
    this (StatsTable): The stats table object
    pos (simple string): The table position string
    height (simple float): The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
    width (simple float): The width of the table as a percentage of the charts height. By default, 0 auto-adjusts the width based on the text inside the cells
    positiveTxtColor (simple color): The text color when positive
    negativeTxtColor (simple color): The text color when negative
    neutralTxtColor (simple color): The text color when neutral
    positiveBgColor (simple color): The background color with transparency when positive
    negativeBgColor (simple color): The background color with transparency when negative
    neutralBgColor (simple color): The background color with transparency when neutral

method init(this, pos, height, width, neutralBgColor)
  Initialize the metrics table object with the given colors in the given position
  Namespace types: MetricsTable
  Parameters:
    this (MetricsTable): The metrics table object
    pos (simple string): The table position string
    height (simple float): The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
    width (simple float): The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
    neutralBgColor (simple color): The background color with transparency when neutral

method init(this, seas)
  Initialize the seasonal data
  Namespace types: SeasonalData
  Parameters:
    this (SeasonalData): The seasonal data object
    seas (simple Seasonality): The seasonality of the matrix data

method init(this, data, pos, maxNumOfYears, height, width, extended, neutralTxtColor, neutralBgColor)
  Initialize the seasonal table object with the given colors in the given position
  Namespace types: SeasonalTable
  Parameters:
    this (SeasonalTable): The seasonal table object
    data (SeasonalData): The seasonality data of the table
    pos (simple string): The table position string
    maxNumOfYears (simple int): The maximum number of years that fit into the table
    height (simple float): The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
    width (simple float): The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
    extended (simple bool): The seasonal table with extended columns for performance
    neutralTxtColor (simple color): The text color when neutral
    neutralBgColor (simple color): The background color with transparency when neutral

method update(this, wins, losses, numOfInconclusiveExits)
  Update the strategy info data of the strategy
  Namespace types: StatsData
  Parameters:
    this (StatsData): The strategy statistics object
    wins (SideStats)
    losses (SideStats)
    numOfInconclusiveExits (int): The number of inconclusive trades

method update(this, stats, positiveTxtColor, negativeTxtColor, negativeBgColor, neutralBgColor)
  Update the stats table object with the given data
  Namespace types: StatsTable
  Parameters:
    this (StatsTable): The stats table object
    stats (StatsData): The stats data to update the table
    positiveTxtColor (simple color): The text color when positive
    negativeTxtColor (simple color): The text color when negative
    negativeBgColor (simple color): The background color with transparency when negative
    neutralBgColor (simple color): The background color with transparency when neutral

method update(this, stats, buyAndHoldPerc, positiveTxtColor, negativeTxtColor, positiveBgColor, negativeBgColor)
  Update the metrics table object with the given data
  Namespace types: MetricsTable
  Parameters:
    this (MetricsTable): The metrics table object
    stats (StatsData): The stats data to update the table
    buyAndHoldPerc (float): The buy and hold percetage
    positiveTxtColor (simple color): The text color when positive
    negativeTxtColor (simple color): The text color when negative
    positiveBgColor (simple color): The background color with transparency when positive
    negativeBgColor (simple color): The background color with transparency when negative

method update(this)
  Update the seasonal data based on the season and eon timeframe
  Namespace types: SeasonalData
  Parameters:
    this (SeasonalData): The seasonal data object

method update(this, data, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor, timeBgColor)
  Update the seasonal table object with the given data
  Namespace types: SeasonalTable
  Parameters:
    this (SeasonalTable): The seasonal table object
    data (SeasonalData): The seasonal cell data to update the table
    positiveTxtColor (simple color): The text color when positive
    negativeTxtColor (simple color): The text color when negative
    neutralTxtColor (simple color): The text color when neutral
    positiveBgColor (simple color): The background color with transparency when positive
    negativeBgColor (simple color): The background color with transparency when negative
    neutralBgColor (simple color): The background color with transparency when neutral
    timeBgColor (simple color): The background color of the time gradient

SideStats
  Object that represents the strategy statistics data of one side win or lose
  Fields:
    numOf (series int)
    sumFreeProfit (series float)
    freeProfitStDev (series float)
    sumProfit (series float)
    profitStDev (series float)
    sumGain (series float)
    gainStDev (series float)
    avgQuantityPerc (series float)
    avgCapitalRiskPerc (series float)
    avgTPExecutedCount (series float)
    avgRiskRewardRatio (series float)
    maxStreak (series int)

StatsTable
  Object that represents the stats table
  Fields:
    table (series table): The actual table
    rows (series int): The number of rows of the table
    columns (series int): The number of columns of the table

StatsData
  Object that represents the statistics data of the strategy
  Fields:
    wins (SideStats)
    losses (SideStats)
    numOfInconclusiveExits (series int)
    avgFreeProfitStr (series string)
    freeProfitStDevStr (series string)
    lossFreeProfitStDevStr (series string)
    avgProfitStr (series string)
    profitStDevStr (series string)
    lossProfitStDevStr (series string)
    avgQuantityStr (series string)

MetricsTable
  Object that represents the metrics table
  Fields:
    table (series table): The actual table
    rows (series int): The number of rows of the table
    columns (series int): The number of columns of the table

SeasonalData
  Object that represents the seasonal table dynamic data
  Fields:
    seasonality (series Seasonality)
    eonToMatrixRow (map<int, int>)
    numOfEons (series int)
    mostRecentMatrixRow (series int)
    balances (matrix<float>)
    returnPercs (matrix<float>)
    maxDDs (matrix<float>)
    eonReturnPercs (array<float>)
    eonCAGRs (array<float>)
    eonMaxDDs (array<float>)

SeasonalTable
  Object that represents the seasonal table
  Fields:
    table (series table): The actual table
    headRows (series int): The number of head rows of the table
    headColumns (series int): The number of head columns of the table
    eonRows (series int): The number of eon rows of the table
    seasonColumns (series int): The number of season columns of the table
    statsRows (series int)
    statsColumns (series int): The number of stats columns of the table
    rows (series int): The number of rows of the table
    columns (series int): The number of columns of the table
    extended (series bool): Whether the table has additional performance statistics
analyticsCAGRdisplayMATHmaxdrawdownmetricsperformanceprofitlossseasonalitiesstatisticstatistics

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.


📧 Contact info
Telegram: @jason5480

🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7

* Please contact me before any donation ☕

Disclaimer