PINE LIBRARY
Updated CobraMetrics

Library "CobraMetrics" :
This Library was made to ease the implementation of the "Coded Metrics Table" for strategy evaluation, as well as the plotting asthetics for it's "Equity Curve" that is used for indexing.
Moreover, it will boost your code's efficiency by reducing it of somewhere around 200 lines.
curve(disp_ind)
Call this function in a plot() to get a certain curve of your strategy, depending on your "disp_ind" input.
Parameters:
disp_ind
Returns: curve of your selection
cleaner(disp_ind, plot)
Call this function in your Strategy's plot() lines to filter out your Strategy plots when displaying equity or any other curve.
Parameters:
disp_ind
plot : the variable you want to plot.
cobraTable()
Call this function to get the "Cobra Table" of your strategy
Special thanks to ShauryaM14 for the cell calculatons.
Simply copy paste the following into your strategy script
I have decided to add the following metrics on top of the usual ones since they provide you with a clearer POV of your strategy,
to decide if it fits your trading\investing style. Although, they are not included in the evaluation of a ⚡💫 𝙎𝙎𝙎𝙡𝙖𝙥𝙥𝙚𝙧 💫⚡.
Net Profit Long\Short Ratio - Theoretically, a good strategy has a fair balance between both sides of its trading directions. Clearly this is subjective since most assets are assymetrical and some people challenge the idea of a strategy trading both ways. Still, it gives useful insight.
Max Consecutive Wins\Losses - Checks for consistancy in the strategy
Max Flat Days - Gives an approximation of how fast\slow the strategy is. Are you patient enough to wait that long till your strategy fires? Irrelevant for fully perpetual strategies (Those which are always in a position, switch from one direction to the other. The alternatives are called semi perps)
Total Months in Profit\Loss - Are you able to financialy withstand that long in a loss? Are you able to manage your capital correctly in the winning period to minimize potential losses?
This Library was made to ease the implementation of the "Coded Metrics Table" for strategy evaluation, as well as the plotting asthetics for it's "Equity Curve" that is used for indexing.
Moreover, it will boost your code's efficiency by reducing it of somewhere around 200 lines.
curve(disp_ind)
Call this function in a plot() to get a certain curve of your strategy, depending on your "disp_ind" input.
Parameters:
disp_ind
Returns: curve of your selection
cleaner(disp_ind, plot)
Call this function in your Strategy's plot() lines to filter out your Strategy plots when displaying equity or any other curve.
Parameters:
disp_ind
plot : the variable you want to plot.
cobraTable()
Call this function to get the "Cobra Table" of your strategy
Special thanks to ShauryaM14 for the cell calculatons.
Simply copy paste the following into your strategy script
Pine Script®
import EliCobra/CobraMetrics/4 as cobra
//// PLOT DATA
disp_ind = input.string ("None" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
pos_table = input.string("Middle Left", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
plot(cobra.curve(disp_ind))
cobra.cobraTable(type_table, pos_table)
//// PLOT DATA
disp_ind = input.string ("None" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
pos_table = input.string("Middle Left", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
plot(cobra.curve(disp_ind))
cobra.cobraTable(type_table, pos_table)
I have decided to add the following metrics on top of the usual ones since they provide you with a clearer POV of your strategy,
to decide if it fits your trading\investing style. Although, they are not included in the evaluation of a ⚡💫 𝙎𝙎𝙎𝙡𝙖𝙥𝙥𝙚𝙧 💫⚡.
Net Profit Long\Short Ratio - Theoretically, a good strategy has a fair balance between both sides of its trading directions. Clearly this is subjective since most assets are assymetrical and some people challenge the idea of a strategy trading both ways. Still, it gives useful insight.
Max Consecutive Wins\Losses - Checks for consistancy in the strategy
Max Flat Days - Gives an approximation of how fast\slow the strategy is. Are you patient enough to wait that long till your strategy fires? Irrelevant for fully perpetual strategies (Those which are always in a position, switch from one direction to the other. The alternatives are called semi perps)
Total Months in Profit\Loss - Are you able to financialy withstand that long in a loss? Are you able to manage your capital correctly in the winning period to minimize potential losses?
Release Notes
v2Updated customization, corrected calculation of some metrics to work on different timeframes (hopefully I did it right).
This one will be slightly harder to achieve slapper status, good luck.
Release Notes
v31. Addressed the visual overlapping of cells on smaller screens, such as laptops. (Even works on mobile lol)
2. Added the option to switch display between "Full" and "Simple" layouts, can also hide the table completely.
3. Added the functionality to change the position where the table will be anchored.
4. Increased the variety of timeframes the anual metrics such as Sharpe, Sortino and Omega will be calculated correctly.
5. Added Net Profit % metric. (Friendly reminder to optimize for efficiency)
Release Notes
v4Omega Ratio correction update.
Slapper Value = 1.35
GL
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 publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
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 publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.