PINE LIBRARY
Telah dikemas kini

analytics_tables

1โ€ฏ219
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:
Pine Scriptยฎ
import jason5480/analytics_tables/1 as ant


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:
Pine Scriptยฎ
var ant.StatsData statsData = ant.StatsData.new()
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:
Pine Scriptยฎ
var ant.StatsData statsData = ant.StatsData.new()
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:
Pine Scriptยฎ
var ant.SeasonalData seasonalData = ant.SeasonalData.new().init(Seasonality.monthOfYear)
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
Nota Keluaran
v2
Update to pinescript version 6

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.