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腳本庫

在真正的TradingView精神中,作者將這段Pine程式碼發佈為開源程式庫,以便我們社群的其他Pine程式設計師可以重複使用它。請向作者致敬!您可以私下使用這個函式庫,或在其他開源出版品中使用,但在出版物中再次使用這段程式碼將受到網站規則的約束。

免責聲明