weak_hand

Risk Management

Library "RiskManagement"
This library keeps your money in check, and is used for testing and later on webhook-applications too. It has four volatility functions and two of them can be used to calculate a Stop-Loss, like Average True Range. It also can calculate Position Size, and the Risk Reward Ratio. But those calculations don't take leverage into account.

position_size(portfolio, risk, entry, stop_loss, use_leverage, qty_as_integer)
  This function calculates the definite amount of contracts/shares/units you should use to buy or sell. This value can used by `strategy.entry(qty)` for example.
  Parameters:
    portfolio (float): This is the total amount of the currency you own, and is also used by strategy.initial_capital, for example. The amount is needed to calculate the maximum risk you are willing to take per trade.
    risk (float): This is the percentage of your Portfolio you willing to loose on a single trade. Possible values are between 0.1 and 100%. Same usecase with strategy(default_qty_type=strategy.percent_of_equity,default_qty_value=100), except its calculation the risk only.
    entry (float): This is the limit-/market-price for the investment. In other words: The price per contract/share/unit you willing to buy or sell.
    stop_loss (float): This is the limit-/market-price when to exit the trade, to minimize your losses.
    use_leverage (bool): This value is optional. When not used or when set to false then this function will let you invest your portfolio at max.
    qty_as_integer (bool): This value is optional. When set to true this function will return a value used with integers. The largest integer less than or equal to the given number. Because some Broker/Exchanges let you trade hole contracts/shares/units only.
  Returns: float

position_size_currency(portfolio, risk, entry, stop_loss)
  This function calculates the definite amount of currency you should use when going long or short.
  Parameters:
    portfolio (float): This is the total amount of the currency you own, and is also used by strategy.initial_capital, for example. The amount is needed to calculate the maximum risk you are willing to take per trade.
    risk (float): This is the percentage of your Portfolio you willing to loose on a single trade. For example: 1 is 100% and 0,01 is 1%. Default amount is 0.02 (2%).
    entry (float): This is the limit-/market-price for the current investment. In other words: The price per contract/share/units you willing to buy or sell.
    stop_loss (float): This is the limit-/market-price when to exit the trade, to minimize your losses.
  Returns: float

rrr(entry, stop_loss, take_profit)
  This function calculates the Risk Reward Ratio. Common values are between 1.5 and 2.0 and you should not go lower except for very few special cases.
  Parameters:
    entry (float): This is the limit-/market-price for the investment. In other words: The price per contract/share/unit you willing to buy or sell.
    stop_loss (float): This is the limit-/market-price when to exit the trade, to minimize your losses.
    take_profit (float): This is the limit-/market-price when to take profits.
  Returns: float

change_in_price(length)
  This function calculates the difference between price now and close price of the candle 'n' bars before that. If prices are very volatile but closed where they began, then this method would show zero volatility. Over many calculations, this method returns a reasonable measure of volatility, but will always be lower than those using the highs and lows.
  Parameters:
    length (int): The length is needed to determine how many candles/bars back should take into account.
  Returns: float

maximum_price_fluctuation(length)
  This function measures volatility over most recent candles, which could be used as an estimate of risk. It may also be effective as the basis for a stop-loss or take-profit, like the ATR but it ignores the frequency of directional changes within the time interval. In other words: The difference between the highest high and lowest low over 'n' bars.
  Parameters:
    length (int): The length is needed to determine how many candles/bars back should take into account.
  Returns: float

absolute_price_changes(length)
  This function measures volatility over most recent close prices. This is excellent for comparing volatility. It includes both frequency and magnitude. In other words: Sum of differences between second to last close price and last close price as absolute value for 'n' bars.
  Parameters:
    length (int): The length is needed to determine how many candles/bars back should take into account.
  Returns: float

annualized_volatility(length)
  This function measures volatility over most recent close prices. Its the standard deviation of close over the past 'n' periods, times the square root of the number of periods in a year.
  Parameters:
    length (int): The length is needed to determine how many candles/bars back should take into account.
  Returns: float
파인 라이브러리

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

면책사항

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

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

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