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:
statsData.update(SideStats.new(), SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var statsTable = ant.StatsTable.new().init(ant.getTablePos('TOP', 'RIGHT'))
statsTable.update(statsData)
A code example for the MetricsTable is the following:
statsData.update(ant.SideStats.new(), ant.SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var metricsTable = ant.MetricsTable.new().init(ant.getTablePos('BOTTOM', 'RIGHT'))
metricsTable.update(statsData, 10)
A code example for the SeasonalityTable is the following:
seasonalData.update()
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var seasonalTable = ant.SeasonalTable.new().init(seasonalData, ant.getTablePos('BOTTOM', 'LEFT'))
seasonalTable.update(seasonalData)
๐๏ธโโ๏ธ 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
Update to pinescript version 6
Perpustakaan Pine
Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda juga boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod ini dalam penerbitan adalah tertakluk kepada Peraturan Dalaman.
Telegram: @jason5480
๐ Addresses
โฟ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7
* Please contact me before any donation โ
Penafian
Perpustakaan Pine
Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda juga boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod ini dalam penerbitan adalah tertakluk kepada Peraturan Dalaman.
Telegram: @jason5480
๐ Addresses
โฟ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7
* Please contact me before any donation โ