PINE LIBRARY
Atualizado 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
Pine 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
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)
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?
Notas de Lançamento
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.
Notas de Lançamento
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)
Notas de Lançamento
v4Omega Ratio correction update.
Slapper Value = 1.35
GL
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.