# Workbench Reference

## Input of Formulas

\
In the chart workbench, each data set or function that is added to the chart is assigned a unique identifier. These identifiers are in the format of *<mark style="color:yellow;">**m#**</mark>* for metrics and *<mark style="color:yellow;">**f#**</mark>* for formulas, where "#" is a number that increments with each new addition. For instance, the first metric added to the chart is labeled *<mark style="color:yellow;">**m1**</mark>*, the second is *<mark style="color:yellow;">**m2**</mark>*, and so on. Similarly, the first formula is *<mark style="color:yellow;">**f1**</mark>*, the second is *<mark style="color:yellow;">**f2**</mark>*, and so forth.

To illustrate, let’s assume you have loaded the price of Bitcoin: Price onto the chart. By default, this data set is assigned the identifier *<mark style="color:yellow;">**m1**</mark>*. If you subsequently load a formula, it will be assigned the identifier *<mark style="color:yellow;">**f1**</mark>*.

Now, let’s explore how you can utilize these identifiers to perform calculations on the chart. The workbench is powerful and supports a wide array of functions and computations.

For a simple example, if you want to calculate and plot the 100-day moving average of the Bitcoin price (which you loaded earlier as *<mark style="color:yellow;">**m1**</mark>*), you can use the following command: `sma(m1, 100)`. Here, `sma` stands for Simple Moving Average, *<mark style="color:yellow;">**m1**</mark>* represents the Bitcoin price data, and "100" specifies the number of days over which the average is calculated.

Let’s now delve into a more intricate example. Say, you want to calculate the 100-day moving average of the 30-day percentage change in Bitcoin price. This is still achievable in a single command: `sma(percentage_change(m1, 30), 100)`. In this command, the term `percentage_change(m1, 30)` calculates the 30-day percentage change in Bitcoin price. It replaces the *<mark style="color:yellow;">**m1**</mark>* in the initial example. The outer `sma` function then takes this result and computes its 100-day moving average.

By employing these identifiers (<mark style="color:yellow;">**m#**</mark> for metrics, *<mark style="color:yellow;">**f#**</mark>* for formulas) and integrating functions, the workbench enables users to conduct both simple and complex calculations efficiently.

*<mark style="color:yellow;">**n**</mark>* is a float value. A float value is used to store decimal numbers (numbers with fractional parts, i.e. 7.5 or 13.01).\
\
\&#xNAN;*<mark style="color:yellow;">**i**</mark>* is an integer value. An integer is any whole number, positive or negative, including zero.

*<mark style="color:yellow;">**period**</mark>* is an integer value, that represents the number of days to be applied to the specified function (i.e. in the formula `percent_change(m1, 7)` will calculate the percentage change of a data set (<mark style="color:yellow;">**m1**</mark>), over the prior 7 day *<mark style="color:yellow;">**period**</mark>*. Currently, all time resolutions are given in one day increments. Closing values are based on UTC.

<table><thead><tr><th width="242">Workbench Function</th><th width="257.3333333333333">Syntax Options</th><th>Function Description</th></tr></thead><tbody><tr><td>Simple Moving Average</td><td><strong><code>sma(m1, period)</code></strong></td><td>Returns the simple moving average of <strong><code>m1</code></strong> over the specified <code>period</code>.</td></tr><tr><td>Exponential Moving Average</td><td><strong><code>ema(m1, period)</code></strong></td><td>Returns the exponentially weighted moving average of <strong><code>m1</code></strong> over the specified <strong><code>period</code></strong>.  EMA weighting factors decrease exponentially. It calculates by using a formula: EMA = α* <strong><code>m1</code></strong>+ (1 - α) * EMA[1], where α = 2 / (<strong><code>period</code></strong>+ 1).</td></tr><tr><td>Median</td><td><strong><code>median(m1, period)</code></strong><br><br><strong><code>med(m1, period)</code></strong></td><td>Returns the median of m1 over the specified <strong><code>period</code></strong>.</td></tr><tr><td>Sum</td><td><strong><code>sum(m1, period)</code></strong></td><td>Returns the sum of <strong><code>m1</code>over</strong> the specified <strong><code>period</code></strong>.</td></tr><tr><td>Cumulative Mean</td><td><strong><code>cummean(m1)</code></strong><br><br><strong><code>cm(m1)</code></strong></td><td>Returns the running mean using all values from the start of the data,  until each closing <strong><code>period</code></strong>. </td></tr><tr><td>Cumalative Standard Deviation</td><td><strong><code>cumstd(m1)</code></strong><br><br><strong><code>cs(m1)</code></strong><br><br></td><td>Returns the running standard deviation using all  values from the start of the data, until each closing <strong><code>period</code></strong>. </td></tr><tr><td>Cumulative Sum</td><td><strong><code>cumsum(m1)</code></strong></td><td>Returns a cumulative sum by adding all the data from the first day to the closing data point of each respective <strong><code>period</code></strong>.</td></tr><tr><td>Standard Deviation</td><td><strong><code>std(m1, period)</code></strong></td><td>Returns the standard deviation of <strong><code>m1</code></strong> over the specified <strong><code>period</code></strong>.</td></tr><tr><td>Percentage Change</td><td><strong><code>percent_change(m1, period)</code></strong><br><br><strong><code>pc(m1, period)</code></strong></td><td>Returns the percentage change of <strong><code>m1</code></strong> over the specified <strong><code>period</code></strong>.</td></tr><tr><td>Difference</td><td><strong><code>diff(m1, period)</code></strong></td><td>Returns the difference of <code>m1</code> and <code>m2</code> over the specified <strong><code>period</code></strong>.</td></tr><tr><td>Logarithm</td><td><strong><code>log(m1)</code></strong></td><td>Returns the logarithm (base 10) of <strong><code>m1</code></strong>.</td></tr><tr><td>Power</td><td><strong><code>pow(m1, i)</code></strong></td><td>Returns <strong><code>m1</code></strong> raised to the power of <strong><code>n</code></strong>.</td></tr><tr><td>Absolute Value</td><td><strong><code>abs(m1)</code></strong></td><td>Returns the absolute value of <strong><code>m1</code></strong>.</td></tr><tr><td>Range</td><td><strong><code>range(m1)</code></strong></td><td>Returns a line from day y = 0 to y = current day for <strong><code>m1</code></strong>, increasing in increments of 1. </td></tr><tr><td>Relative Strength Index</td><td><strong><code>rsi(m1, period)</code></strong></td><td>Returns the relative strength index of <strong><code>m1</code></strong> over the specified <strong><code>period</code></strong>.</td></tr><tr><td>Min</td><td><code>min(m1, period)</code></td><td>Returns the minimum value of <code>m1</code> over the specified period.</td></tr><tr><td>Max</td><td><code>max(m1, period)</code></td><td>Returns the maximum value of <code>m1</code> over the specified period.</td></tr><tr><td>Shift</td><td><code>shift(m1, period)</code></td><td>Shifts the data of <code>m1</code> by the specified period.</td></tr><tr><td>Correlation</td><td><code>corr(m1, m2, period)</code></td><td>Returns the correlation between <code>m1</code> and <code>m2</code> over the specified <code>period</code>.</td></tr><tr><td>Square Root</td><td><code>sqrt(m1)</code></td><td>Returns the square root of <code>m1</code>.</td></tr><tr><td>If</td><td><code>if(m1, "cond", m2, true, false)</code></td><td>Establishes an if-then condition comparing the trace of <code>m1</code> to <code>m2</code> at each data point, returning the result <code>true</code> or <code>false</code>. The "<code>cond</code>" may be set equal to any of the following: <code>"=" equal to</code> <code>"!=" not equal to</code> <code>">" greater than</code> <code>">=" greater than or equal to</code> <code>"&#x3C;" less than</code> <code>"&#x3C;=" less than or equal to</code></td></tr></tbody></table>
