PINE LIBRARY
Cập nhật 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?
Phát hành các Ghi chú
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.
Phát hành các Ghi chú
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)
Phát hành các Ghi chú
v4Omega Ratio correction update.
Slapper Value = 1.35
GL
Thư viện Pine
Theo tinh thần TradingView thực sự, tác giả đã xuất bản mã Pine này dưới dạng thư viện nguồn mở để các lập trình viên Pine khác trong cộng đồng của chúng tôi có thể sử dụng lại. Xin tri ân tác giả! Bạn có thể sử dụng thư viện này riêng tư hoặc trong các bài đăng nguồn mở khác. Tuy nhiên, bạn cần sử dụng lại mã này theo Nội quy chung.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Thư viện Pine
Theo tinh thần TradingView thực sự, tác giả đã xuất bản mã Pine này dưới dạng thư viện nguồn mở để các lập trình viên Pine khác trong cộng đồng của chúng tôi có thể sử dụng lại. Xin tri ân tác giả! Bạn có thể sử dụng thư viện này riêng tư hoặc trong các bài đăng nguồn mở khác. Tuy nhiên, bạn cần sử dụng lại mã này theo Nội quy chung.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.