PINE LIBRARY

tp_sl_drawing_lib

TP/SL Drawing Library

A comprehensive library for standardized drawing of trade levels (Entry, Take Profit, and Stop Loss) across different indicators and strategies. Provides consistent visual styling with flexible customization options.

Features:
  • Multiple drawing versions with easy version switching
  • Support for up to 3 Take Profit levels
  • Customizable label positions and styles
  • Unified interface for consistent visual experience
  • Flexible display options for prices, R:R ratios, and trade information
  • Memory-efficient with proper cleanup methods


Version Differences:
  • Version 1: Traditional style with configurable label positions (left/center/right)
  • Version 2: Modern streamlined style with single-side labels and tooltips


Usage Example:


Main Functions:
• draw_trade_tp_sl() - Draw entry, take profit, and stop loss levels
• remove_trade_drawings() - Clean up existing drawings
• shrink_lines() - Dynamically adjust line lengths
• draw_bad_rrr() - Special case for risk/reward scenarios


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)

tradeDrawingsV1
  Fields:
    entryLine (series line)
    entryLeft (series label)
    entryCenter (series label)
    entryRight (series label)
    tp1Line (series line)
    tp1Left (series label)
    tp1Center (series label)
    tp1Right (series label)
    tp2Line (series line)
    tp2Left (series label)
    tp2Center (series label)
    tp2Right (series label)
    tp3Line (series line)
    tp3Left (series label)
    tp3Center (series label)
    tp3Right (series label)
    slLine (series line)
    slLeft (series label)
    slCenter (series label)
    slRight (series label)

tradeDrawingsV2
  Fields:
    entryLine (series line)
    entryLabel (series label)
    tp1Line (series line)
    tp1Label (series label)
    tp2Line (series line)
    tp2Label (series label)
    tp3Line (series line)
    tp3Label (series label)
    slLine (series line)
    slLabel (series label)

tradeDrawingsUnion
  Fields:
    v1 (tradeDrawingsV1)
    v2 (tradeDrawingsV2)
display

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 a publication is governed by House rules.

Disclaimer