PINE LIBRARY

BacktestLibrary

Library "BacktestLibrary"
A library providing functions for equity calculation and performance metrics.

since(date, active)
  : Calculates the number of candles since a specified date.
  Parameters:
    date (simple float): (simple float): The starting date in timestamp format (e.g., input.time(timestamp()))
    active (simple bool): (simple bool): If true, counts the number of candles since the date; if false, returns 0.
  Returns: (int): The number of candles since the specified date.

buy_and_hold(r, startDate)
  : Calculates the Buy and Hold Equity from a specified date.
  Parameters:
    r (float): (series float): Daily returns of the asset (e.g., 0.02 for 2% move).
    startDate (simple float): (simple float): Timestamp of the starting date for the equity calculation.
  Returns: (float): Buy and Hold Equity of the asset from the specified date.

equity(sig, threshold, r, startDate, signals)
  : Calculates the strategy's equity on a candle-by-candle basis.
  Parameters:
    sig (float): (series float): Signal values; positive for long, negative for short.
    threshold (simple float): (simple float): Signal threshold for entering trades.
    r (float): (series float): Daily returns of the asset (e.g., 0.02 for 2% move).
    startDate (simple float): (simple float): Timestamp of the starting date for the equity calculation.
    signals (simple string): (simple string): Type of signals to backtest ("Long & Short", "Long Only", "Short Only").
  Returns: (float): Strategy equity on a candle-by-candle basis.

PerformanceMetrics(base, Lookback, startDate)
  : Calculates performance metrics of a strategy from a specified date.
  Parameters:
    base (float): (series float): Equity values of the strategy or Buy and Hold equity.
    Lookback (int): (series int): Number of periods since the start date; recommended to use the 'since' function.
    startDate (simple float): (simple float): Timestamp of the starting date for the equity calculation.
  Returns: (float[]): Array of performance metrics.

PerfMetricTable(buy_and_hold, strategy)
  : Plots a table comparing performance metrics of Buy and Hold and Strategy equity.
  Parameters:
    buy_and_hold (array<float>): (float[]): Metrics from the PerformanceMetrics() function for Buy and Hold.
    strategy (array<float>): (float[]): Metrics from the PerformanceMetrics() function for the strategy.
  Returns: : Table displaying the performance metrics comparison.
displayMATHstatistics

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. Chúc mừng 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 Quy tắc nội bộ.

Thông báo miễn trừ trách nhiệm