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

파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.