peacefulLizard50262

strategy_helpers

This library is designed to aid traders and developers in calculating risk metrics efficiently across different asset types like equities, futures, and forex. It includes comprehensive functions that calculate the number of units or contracts to trade, the value at risk, and the total value of the position based on provided entry prices, stop levels, and risk percentages. Whether you're managing a portfolio or developing trading strategies, this library provides essential tools for risk management. Functions also automatically select the appropriate risk calculation method based on asset type, calculate leverage levels, and determine potential liquidation points for leveraged positions. Perfect for enhancing the precision and effectiveness of your trading strategies.

Library "strategy_helpers"
Provides tools for calculating risk metrics across different types of trading strategies including equities, futures, and forex. Functions allow for precise control over risk management by calculating the number of units or contracts to trade, the value at risk, and the total position value based on entry prices, stop levels, and desired risk percentage. Additional utilities include automatic risk calculation based on asset type, leverage level calculations, and determination of liquidation levels for leveraged trades.

calculate_risk(entry, stop_level, stop_range, capital, risk_percent, trade_direction, whole_number_buy)
  Calculates risk metrics for equity trades based on entry, stop level, and risk percent
  Parameters:
    entry (float): The price at which the position is entered. Use close if you arent adding to a position. Use the original entry price if you are adding to a position.
    stop_level (float): The price level where the stop loss is placed
    stop_range (float): The price range from entry to stop level
    capital (float): The total capital available for trading
    risk_percent (float): The percentage of capital risked on the trade. 100% is represented by 100.
    trade_direction (bool): True for long trades, false for short trades
    whole_number_buy (bool): True to adjust the quantity to whole numbers
  Returns: A tuple containing the number of units to trade, the value at risk, and the total value of the position:

calculate_risk_futures(risk_capital, stop_range)
  Calculates risk metrics for futures trades based on the risk capital and stop range
  Parameters:
    risk_capital (float): The capital allocated for the trade
    stop_range (float): The price range from entry to stop level
  Returns: A tuple containing the number of contracts to trade, the value at risk, and the total value of the position:

calculate_risk_forex(entry, stop_level, stop_range, capital, risk_percent, trade_direction)
  Calculates risk metrics for forex trades based on entry, stop level, and risk percent
  Parameters:
    entry (float): The price at which the position is entered. Use close if you arent adding to a position. Use the original entry price if you are adding to a position.
    stop_level (float): The price level where the stop loss is placed
    stop_range (float): The price range from entry to stop level
    capital (float): The total capital available for trading
    risk_percent (float): The percentage of capital risked on the trade. 100% is represented by 100.
    trade_direction (bool): True for long trades, false for short trades
  Returns: A tuple containing the number of lots to trade, the value at risk, and the total value of the position:

calculate_risk_auto(entry, stop_level, stop_range, capital, risk_percent, trade_direction, whole_number_buy)
  Automatically selects the risk calculation method based on the asset type and calculates risk metrics
  Parameters:
    entry (float): The price at which the position is entered. Use close if you arent adding to a position. Use the original entry price if you are adding to a position.
    stop_level (float): The price level where the stop loss is placed
    stop_range (float): The price range from entry to stop level
    capital (float): The total capital available for trading
    risk_percent (float): The percentage of capital risked on the trade. 100% is represented by 100.
    trade_direction (bool): True for long trades, false for short trades
    whole_number_buy (bool): True to adjust the quantity to whole numbers, applicable only for non-futures and non-forex trades
  Returns: A tuple containing the number of units or contracts to trade, the value at risk, and the total value of the position:

leverage_level(account_equity, position_value)
  Calculates the leverage level used based on account equity and position value
  Parameters:
    account_equity (float): Total equity in the trading account
    position_value (float): Total value of the position taken
  Returns: The leverage level used in the trade

calculate_liquidation_level(entry, leverage, trade_direction, maintenance_margine)
  Calculates the liquidation price level for a leveraged trade
  Parameters:
    entry (float): The price at which the position is entered
    leverage (float): The leverage level used in the trade
    trade_direction (bool): True for long trades, false for short trades
    maintenance_margine (float): The maintenance margin requirement, expressed as a percentage
  Returns: The price level at which the position would be liquidated, or na if leverage is zero

Thư viện Pine

Với tinh thần TradingView thực sự, tác giả đã xuất bản mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác từ cộng đồng của chúng tôi có thể sử dụng lại nó. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này một cách riêng tư hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của 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.

Bạn muốn sử dụng thư viện này?

Sao chép văn bản vào khay nhớ tạm và dán nó vào tập lệnh của bạn.