Get Simple Moving Average
0x484428507A212cA56D71baa27Ca6089a6dB63a88

What this does

This plug records the named token's latest Chainlink USD price under a day-aligned key in socket storage and returns the simple moving average across a caller-set window of days. It asks the caller for a token address and a window count of days. It runs when invoked, reading the current block timestamp and looping over the window to sum daily prices before dividing by the window. Computing this manually or off a stale stored reading yields an average that misstates the token's true price trend.

Actions · 15

  • Get current timestamp
    Get current timestamp
    Returns the current block timestamp as Unix seconds.
  • Get interval start
    Get start of containing
    Returns the start timestamp of the hour, day, week, or larger interval containing a timestamp.
  • Get price
    Get price of in
    Reads the latest Chainlink price of a base asset in a quote asset, normalized to 18 decimals.
  • Set nested map value
    Set nested map value of in in to
    Writes a value into a two-level keyed map in the socket's persistent storage.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • Predicate
    Steers control flow by comparing two values: branch, loop, or require the condition holds.
  • Use
    Use where
    tokenis
    todayis
    days_backis
    price_running_totalis
    Composes another plug inside this one.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • Calculate
    Calculate
    Applies a binary arithmetic operation to two values and returns the result.
  • Set
    Set to
    Assigns a value to a named variable that later steps reference.
  • End block
    End block
    Closes the innermost open block, whether a conditional branch or a loop.
  • Calculate
    Calculate
    Applies a binary arithmetic operation to two values and returns the result.
  • Bubble
    Bubble
    Surfaces a value as an output of this plug.
  • Bubble
    Bubble
    Surfaces a value as an output of this plug.

Related plugs · 8