tp_sl_styling_lib

A professional-grade library for creating highly customizable trade management visualizations with extensive styling options and multiple display versions. Perfect for indicators and strategies that require consistent, professional-looking trade level drawings.
Key Features - Extensive Styling Options
Multiple Visual Styles
- Version 1: Traditional multi-label style with left/center/right positioning
- Version 2: Modern streamlined style with single-side labels and tooltips
- Version 3: Advanced style with directional arrows (▲/▼) and bar-level indicators
Comprehensive Customization
- Line Styles: Solid, Dashed, Dotted for all levels
- Line Thickness: Individual thickness control for each level
- Color Schemes: Separate colors for TP1, TP2, TP3, SL, Entry, Buy/Sell signals
- Label Positioning: Flexible left/center/right positioning for all information
- Information Display: Configurable display of prices, R:R ratios, percentages, and position sizes
Professional Features
- Memory Management: Proper cleanup functions prevent memory leaks
- Dynamic Line Adjustment: Automatic line length adjustment based on chart view
- Tooltip Integration: Hover information for all trade levels
- Bad R/R Detection: Special visualization for poor risk/reward scenarios
What Makes This Library Unique
Unlike basic drawing functions, this library provides:
- 3 Different Visual Styles to match any trading strategy aesthetic
- Granular Control over every visual element (colors, styles, thickness, positioning)
- Professional Consistency across all your indicators and strategies
- Memory-Efficient design with proper cleanup methods
- Future-Proof architecture with version-based feature progression
Usage Example
Main Functions
Core Drawing Functions
- draw_trade_tp_sl() - Create complete trade visualization with all styling options
- draw_bad_rrr() - Special visualization for poor risk/reward scenarios
- remove_trade_drawings() - Clean up all drawings to prevent memory issues
- remove_trade_drawings_labels() - Remove only labels while keeping lines
- shrink_lines() - Dynamically adjust line lengths based on chart view
Data Types
- tradeDrawingsV1 - Traditional multi-label style
- tradeDrawingsV2 - Modern streamlined style
- tradeDrawingsV3 - Advanced style with directional indicators
- tradeDrawingsUnion - Unified interface for all versions
Perfect For
- Professional Indicators requiring consistent trade visualization
- Trading Strategies with multiple take profit levels
- Educational Content with clear trade management displays
- Algorithmic Trading systems needing reliable drawing functions
- Custom Indicators requiring extensive styling flexibility
Pro Tips
- Choose the Right Version: V1 for detailed info, V2 for clean look, V3 for modern style
- Memory Management: Always call remove_trade_drawings() before creating new ones
- Styling Consistency: Use the same color scheme across all your indicators
- Performance: Use shrink_lines() for dynamic line adjustment on large charts
Version Comparison
Label Positions:
- V1 (Traditional): Left/Center/Right positioning available
- V2 (Modern): Right-side positioning only
- V3 (Advanced): Right-side + Bar-level positioning
Directional Indicators:
- V1 (Traditional): ❌ Not available
- V2 (Modern): ❌ Not available
- V3 (Advanced): ✅ Available (▲/▼ arrows)
Tooltips:
- V1 (Traditional): ❌ Not available
- V2 (Modern): ✅ Available
- V3 (Advanced): ✅ Available
Bar-Level Markers:
- V1 (Traditional): ❌ Not available
- V2 (Modern): ❌ Not available
- V3 (Advanced): ✅ Available
Memory Efficiency:
- V1 (Traditional): Good
- V2 (Modern): Better
- V3 (Advanced): Best
Note: This library is designed for professional use and provides extensive customization options. Choose the version that best fits your visual style and requirements.
Main Functions:
shrink_lines(version, start_idx, min_bars_label_length, drawings)
Parameters:
version (int)
start_idx (int)
min_bars_label_length (int)
drawings (tradeDrawingsUnion)
draw_bad_rrr(version, ep, rrr, min_bars_label_length, ep_thickness, ep_color)
Parameters:
version (int)
ep (float)
rrr (float)
min_bars_label_length (int)
ep_thickness (int)
ep_color (color)
remove_trade_drawings(version, drawings)
Parameters:
version (int)
drawings (tradeDrawingsUnion)
remove_trade_drawings_labels(version, drawings)
Parameters:
version (int)
drawings (tradeDrawingsUnion)
draw_trade_tp_sl(version, direction, ep, tp1, tp2, tp3, sl, rrr, tp1_perc, tp2_perc, tp3_perc, sizeInfo, patternStartBarIdx, tp_sl_line_length, show_tp1, show_tp2, show_tp3, show_sl, show_ep, show_size_info, tp_sl_label_pos, tp_sl_price_pos, tp_sl_rrr_pos, tp_sl_perc_pos, tp_sl_qty_pos, tp1_style, tp2_style, tp3_style, sl_style, ep_style, tp1_thickness, tp2_thickness, tp3_thickness, sl_thickness, ep_thickness, tp1_color, tp2_color, tp3_color, sl_color, ep_color, buy_color, sell_color)
Parameters:
version (int)
direction (int)
ep (float)
tp1 (float)
tp2 (float)
tp3 (float)
sl (float)
rrr (float)
tp1_perc (float)
tp2_perc (float)
tp3_perc (float)
sizeInfo (string)
patternStartBarIdx (int)
tp_sl_line_length (int)
show_tp1 (bool)
show_tp2 (bool)
show_tp3 (bool)
show_sl (bool)
show_ep (bool)
show_size_info (bool)
tp_sl_label_pos (string)
tp_sl_price_pos (string)
tp_sl_rrr_pos (string)
tp_sl_perc_pos (string)
tp_sl_qty_pos (string)
tp1_style (string)
tp2_style (string)
tp3_style (string)
sl_style (string)
ep_style (string)
tp1_thickness (int)
tp2_thickness (int)
tp3_thickness (int)
sl_thickness (int)
ep_thickness (int)
tp1_color (color)
tp2_color (color)
tp3_color (color)
sl_color (color)
ep_color (color)
buy_color (color)
sell_color (color)
Libreria Pine
In pieno spirito TradingView, l'autore ha pubblicato questo codice Pine come libreria open-source in modo che altri programmatori Pine della nostra comunità possano riutilizzarlo. Complimenti all'autore! È possibile utilizzare questa libreria privatamente o in altre pubblicazioni open-source, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento.
Declinazione di responsabilità
Libreria Pine
In pieno spirito TradingView, l'autore ha pubblicato questo codice Pine come libreria open-source in modo che altri programmatori Pine della nostra comunità possano riutilizzarlo. Complimenti all'autore! È possibile utilizzare questa libreria privatamente o in altre pubblicazioni open-source, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento.