Volatility

374
Library "Volatility"
Some practical measures of volatility that can be easily used to satisfy the need to show expanding and contracting volatility but are not tied to an underlying price level. The code I translated of the book "Trading Systems and Methods."

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_change(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(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. Optional. Default value is 14, and minimum value is 2.
  Returns: float

annualized_returns(roc, length, syminfo_type)
  This function measures volatility over most recent percentage values, and it is the same calculation as 'annualized()', except it uses an external source to get the same result. Its the standard deviation of rate of change (ROC) over the past 'n' periods, times the square root of the number of periods in a year.
  Parameters:
    roc (float): Rate of change ('ta.roc(close, 1)') to calculate annualized volatiltiy.
    length (int): The length is needed to determine how many candles/bars back should take into account. Optional. Default value is 14, and minimum value is 2.
    syminfo_type (simple string): The type of symbol. Optional. Default is 'syminfo.type'.
  Returns: float

bars(look_days_back, is_cumulative)
  Calculates the historical volatility and the current volatility, both as bars/volume. This funtion works for Intraday use only!
  Parameters:
    look_days_back (int): Number of days to include in the historical data.
    is_cumulative (bool): If 'true', the cumulative volatility is calculated (ascended wedge pattern).
  Returns: tuple [float average, float current]

absolute_daily_range()
  This function is the ATR on a fixed 10 days length. It could be used as TP, or a fraction of it for SL.
  Returns: float

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.