Percent Move is the difference, expressed as a percentage, between a specified starting value and an ending specified value. Move calculates the difference between a specified starting value and an ending specified value.
![]()

If either X or X n is a NaN, the immediately preceding value will be considered instead, i.e., X 1 or X n+1 . If these values are also NaN, the percent move will be NaN as well. For example, when computing a 2 day percent move, if X is a NaN, but X 2 is not, then XMIM will return X 1 – X 2 instead of X – X 2 . But, if X 1 is also NaN, then XMIM will return NaN.
Note that percentMove is negative precisely when the move is negative; i.e., the percent move from -10 to -12 is -20, not 20. |
| Constant (Number) | Time-Period (day/mth/yr) | “% move” or "move" | of | Series |
|---|---|---|---|---|
4 | day | % move | of | HO |
1 | month | move | of | CL |
2 | Quarter | % move | of | (HO – CL) |
1 | Month | move | of | (1 week average of HO) |
This study returns the absolute value for a specified Attribute. Where the value is a holiday or missing data series (expressed as NaN) the return will be NaN.
![]()

If X is NaN, absoluteValue returns NaN as well.
| “absolute_value” | of | Series |
|---|---|---|
absolute_value | of | HO |
MIMIC will adjust all studies using futures contract so that the artificial price jump associated with the expiration of a contract will not be factored into the study. For example, if a study using the front continuous contract captured a time period which included a roll or expiration date, by default, that price difference between the old or expiring contract and the new contract would be subtracted or backed out of the equation as of the expiration date. The adjust_contract function is used so that the jump or price difference associated with expiration (cost of carry) is not adjusted out of the study. There are four fields that are required to be specified within this study- the Attribute or series, the deferred number of the contract chosen (i.e., 1 represents the contract nearest to expiration or the front contract, 2 represents the second nearest contract to expiration, etc.), the number of days until expiration that the contract should be followed (i.e., 0 specifies that the contract will be active until expiration, 1 specifies that the contract will be active or followed up until 1 day before expiration, etc.) and contract month which is the parameter which specifies the contract month of interest (i.e., setting the field to 0 will disable this field thereby allowing the contract to roll to the regularly traded serial months, setting the field to 1 will specify only January contracts, etc.).
![]()

where ![]()
is computed by offsetting each relation of type
futures in X with an appropriate amount so that the expiration-day
boundaries do not introduce an artificial jump.
| adjust_contract | “Series” | Contract Number | Days to Expiration | Month of Interest |
|---|---|---|---|---|
adjust_contract | (HO, | 1, | 0, | 0) |
adjust_contract | (CL, | 2, | 5, | 1) |
adjust_contract | (NG, | 3, | 3, | 0) |
In the examples above the first example would create a series that when used in a Formula within another row of the worksheet would unadjust the continuous price series for the nearest to expire (or front) month. This series is set up to ‘roll’ on the expiration day. The next example, when used in a Formula within another row of the worksheet, would unadjust the continuous price series for the second nearest to expire (or back) January month (connects only January contracts). This series is set up to ‘roll’ five days before the expiration day of the contract. The last example, when used in a Formula within another row of the worksheet, would unadjust the continuous price series for the third nearest to expire (or back) contract. This series is set up to ‘roll’ three days before the expiration day of the contract. |
The following shows further examples to demonstrate the use of adjust contract.
Example 1: Consider the trading day of 10/8/2002 for the following scenarios. The “prompt” crude oil contract would be Nov 2002, CL_2002X.
Data Table:
| Date | LIM SYMBOL | adjust_contract version |
|---|---|---|
10/8/2002 | CL_2002Z - Close | adjust 1st December contract out |
adjust_contract (CL, 1, 0, 12) | ||
29.51 | 29.51 | |
CL_2003J - Close | adjust 6th contract month out | |
adjust_contract (CL, 6, 0, 0) | ||
27.6 | 27.6 | |
CL_2004H - Close | adjust 2nd March contract out | |
adjust_contract (CL, 2, 0, 3) | ||
23.86 | 23.86 | |
CL_2005F - Close | adjust 3rd January contract out | |
adjust_contract (CL, 3, 2, 1) | ||
23.03 | 23.03 |
Let’s look closer at each of these to see how the adjust_contract function chooses the correct contract.
December 2002 contract: This is the nearest December contract right now. The explicit LIM symbol is CL_2002Z. To ask for the closest contract month using adjust_contract you fill in adjust_contract (CL, 1, 0, 12), where:
CL = base commodity symbol of choice.
1 = N nearest. 3 would imply the 3rd nearest, 6 the 6th nearest.
0 = This is “Number of days before Expiration”. Setting this number to “0” indicates the series will locate the next nearest contract when the contract expires. Setting this number to “4” would mean that the contract should roll to the next one 4 days before expiration of the current contract.
12 = This is the contract month, 12 equals December, 5 equals May, 7 equals July.
Setting this number to “0” makes the parameter inactive, meaning the other parameters will determine the behavior. |
April 2003 contract: This is the 6th nearest contract out. The explicit LIM symbol is CL_2003J. To ask for the literal N contract out using adjust_contract, you fill in adjust_contract (CL, 6, 0, 0), where:
CL= base commodity symbol of choice.
6 = N nearest. 6 points to the 6th closest or nearest to expiration active contract.
0 = This is “Number of days before Expiration”. Setting this to “0” indicates the series will locate the next nearest contract when the contract expires. Setting this to “4” would mean that the contract should roll to the next one 4 days before expiration of the current contract.
0 = Normally, this is where you put in the contract month. However, since we want the exact 6th closest contract, this is set to “0”.
March 2004 contract: This is the 2nd nearest March contract. The 1st nearest is the March 2003 contract. The 3rd nearest would be March 2005. To ask for the 2nd nearest March using adjust_contract, you would fill in adjust_contract (CL, 2, 0, 3) where:
CL = base commodity symbol of choice.
2 = 2nd nearest
0 = This is “Number of days before Expiration”. Setting this to “0” indicates the series will locate the next nearest contract when the contract expires.
3 = March contract.
January 2005 contract: This is the 3rd nearest January contract. The closest or first nearest would be January 2003. To ask for the 3rd nearest using adjust_contract, you will fill in adjust_contract (CL, 3, 2, 1), where:
CL = base commodity symbol of choice
3 = 3rd nearest
2 = This is “Number of days before Expiration”. Setting this to “2” indicates the series will roll 2 days before the contract expires and choose the next 3rd nearest contract.
1 = January contract.
Example 2: More Real-World Examples
How do you ask for?
Spread between the 2nd December and the 1st December contract. Often times this is referred to as a Dec – Red Dec spread.
adjust_contract (CL, 1, 0, 12) – adjust_contract (CL, 2, 0, 12)
The spread between the 1st and 2nd nearby contracts.
adjust_contract (CL, 1, 0, 0) – adjust_contract (CL, 2, 0, 0)
The 3rd nearest November contract.
adjust_contract (CL, 3, 0, 11)
The 15th closest contract out.
adjust_contract (CL, 15, 0, 0)
Calculates a simple moving average of values in the specified time period. When calculating an N day average, XMIM will display a moving N day average for any executable date; however, where there is a holiday or missing data point (expressed as NaN) a moving average of less than N days will be displayed. For example, if a 5 day average was calculated and our executable dates include December 25, a holiday, the study would calculate a 4 day average for this date because no data point exists for December 25. Likewise, on December 26 a 4 day average will be displayed because of the missing data associated with the holiday. On December 25, a 5 value average will display (NaN) because no data exists to perform the calculation. However on December 26, or the next date where data exists, the study include the data on December 26 and will search back for the other 4 values to perform the calculation (skipping over December 25). To ensure that N actual ‘values’ are used in the calculation the term value should be substituted instead of day in the formula.
![]()

| Constant (Number) | Time Period (day/mth/yr) | “average” | of | Series |
|---|---|---|---|---|
5 | value | Average | of | HO |
3 | month | Average | of | CL |
2 | quarter | Average | of | NG |
1 | year | Average | of | RB.UNL |
4 | week | Average | of | PN |
The term “value” may be used to anchor 5 absolute values to be used in the calculation for the above example. If one the five values were unavailable for the 5-day average, MIMIC would substitute a 4-day average. To ensure that 5 actual ‘values’ are used in the calculation the term value should be substituted instead of day in the formula. Also, on a day without data the use of ‘value’ in the formula would return a “NaN” (not a number, indicating that no values existed on that day for the calculation). |
Bollinger_high and Bollinger_low studies return values that are derived from a moving average plus (high) or minus some relative percent of the moving average. The relative value, subtracted or added to the moving average, is the standard deviation for the time window. These price bands can be defined so that they encompass most of the price activity with the ceiling (bollinger_high) coinciding with the relative highs and the floor (bollinger_low) coinciding with relative lows. These significant high and low thresholds can be used to measure overbought or oversold levels in the market. There are three fields that are required to be specified within this study- the Attribute or series, the relevant time period for the study and the width of the band (1 denotes 1 standard deviation, 2 denotes 2 standard deviations and 3 denotes 3 standard deviations).
![]()

![]()

| “bollinger_high/bollinger_low” | Series | Constant (Number) | Time Period (day/mth/yr) | Constant (Number) |
|---|---|---|---|---|
bollinger_high/bollinger_low | (HO, | 1 | day, | Standard Deviation) |
Compund_return is the accumulated return of a specified relation column, between a specified start and end date. Since the formula relies on multiplication, all NaN values should be skipped at all times. If the relation column value is zero, then the value is 1. If the relation column is all NaN then the return value is NaN. For this study, it is practical to use % move as the attribute.


where C = compound_return and R = relation column
| “compound _return” | Constant (Number) | Time Period (day/mth/yr) | Attribute | of | Series | Time Period (day/mth/yr) | Time Period (day/mth/yr) |
|---|---|---|---|---|---|---|---|
compound _return | 1 | day | % move | of | (GII.DELL.NASDAQ) | 1 year ago | today |
This study returns XMIM's mathematical value corresponding to the date month/day/year format.
![]()

where D is an integer corresponding to the date m/d/y (month/day/year format). The number D is guaranteed to be in the standard date representation of XMIM, as given by the XMIM construct current date.
| “construct_date” | Constant (Number) | Year |
|---|---|---|
construct_date | (month, day, | 1996) |
Returns the statistical co-regression of two series where X is the Independent variable and Y is the dependent variable.
![]()

where 
and 
are the regression coefficients, computed as
follows:






As in the case for linear regression, the formulas above are unstable and prone to round-off errors, so we replace them with the mathematically equivalent ones below:




NaNs are handled exactly as in the case for linearRegression.
| Constant (Number) | Time-Period (day/mth/yr) | “coregression” | of | Series |
|---|---|---|---|---|
1 | day | coregression | of | HO and CL |
Returns the statistical co-regression intercept of two series where X is the independent variable and Y is the dependent variable.
![]()

where 
is the regression intercept, computed as
follows:




As in the case for linear regression, the formulas above are unstable and prone to round-off errors, so we replace them with the mathematically equivalent ones below:




NaNs are handled exactly as in the case for linearRegression.
| Constant (Number) | Time-Period (day/mth/yr) | “coregression_intercept” | of | Series |
|---|---|---|---|---|
1 | day | coregression_intercept | of | HO and CL |
Returns the statistical co-regression slope of two series where X is the Independent variable and Y is the dependent variable.


where 
is the regression slope, computed as
follows:




As in the case for linear regression, the formulas above are unstable and prone to round-off errors, so we replace them with the mathematically equivalent ones below:


NaNs are handled exactly as in the case for linearRegression.
| Constant (Number) | Time-Period (day/mth/yr) | “coregression_slope” | of | Series |
|---|---|---|---|---|
1 | day | coregression_slope | of | HO and CL |
This study returns the statistical correlation coefficient between two series. This study will return values between the range of 1 (perfect correlation) and -1 (perfectly negative correlation).


where 
is equal to average (X, n) and similarly for

. NaNs are handled exactly as in the case for
covariance.
Constant (Number) | Time-Period (day/mth/yr) | “correlation” | of | Series |
|---|---|---|---|---|
100 | day | correlation | of | HO and CL |
1 | month | correlation | of | HO and NG |
4 | week | correlation | of | (HO + CL) and NG |
This study counts the number of occurrences for which a value is returned for a given time period. This function will not include holidays or other NaN (Not a Number) values in its count.
![]()

where defined(X) returns a 0 if X is NaN and 1 otherwise.
| Constant (Number) | Time-Period (day/mth/yr) | “count” | of | Series |
|---|---|---|---|---|
1 | day | count | of | HO |
A statistical covariance measure is the measure of the relationship between two series whose values are observed over a moving time window.
![]()

where 
is equal to average (X, n) and similarly for

. As in the variance study, if n is less than or
equal to 1, covariance returns NaN.
| Constant (Number) | Time-Period (day/mth/yr) | “covariance” | of | Series |
|---|---|---|---|---|
1 | day | covariance | of | HO and CL |
Dividend_adjusted_return is the overall percentage return of a dividend paying stock when it is assumed additional shares (or fractions of shares) are purchased with the dividend gains on Ex-Dividend date at the current stock’s closing price. On each Ex-Dividend date, the amount of shares increases, but the initial investment remains the same. The formula assumes a purchase of 1 share at the start date at the then current closing price (this is the initial investment).
![]()

| “dividend_adjusted_return” | Attribute | of | Series | Time Period (day/mth/yr) | Time Period (day/mth/yr) |
|---|---|---|---|---|---|
dividend_adjusted_return | (Close | of | GII.C.NYSE, | 1 year ago | today) |
This study is derived from Richard Arms’ Ease of Movement indicator and is a momentum indicator that incorporates range and volume to signal certain trends evolving within the markets. This indicator was developed in order to quantify volume and price changes in order to determine the ease, or lack thereof, with which price is able to move up or down. The formula for this study is the difference of the today's midpoint minus a previous midpoint multiplied by today's range all divided by today's volume.
![]()

where M is equal to midpoint (S) and M1 is the previous value of midpoint (S).
| “ease_of_move” | of | Series |
|---|---|---|
ease_of_move | of | HO |
There exists a school of thought that says that using a simple moving average system, where all days are weighted equally, doesn’t properly acknowledge the impact of more recent prices on future price movement. Hence, it is argued that it would be preferred to ‘weight’ the more recent days more heavily in a ‘moving average’ equation. This study is calculated as of the sum of the current price multiplied by a ‘weight’ or smoothing constant and the previous day’s study is multiplied by (1 - weight). The weight of a prior day’s price will decrease the further back in time, relevant to today’s price, it is. There are two fields that are required to be specified within this study- the Attribute or series and weight. There are two acceptable ways to calculate weight: 1 / n (where n represents the number of days) or 2 / n + 1. For example, if we were to use a 14 day equivalent, we could type in either 1 / 14 or 2 / 14 + 1 into the ‘weight’ field for our study.
![]()

where w is restricted to lie in the range

and exponentialAverage
1 (X,
w) is the previous value of exponentialAverage(X,
w) (or NaN if none). ExponentialAverage ignores any NaNs in
X. That is, if a given value is NaN, then the exponentialAverage is
simply equal to the previous value of the exponentialAverage.
Although exponential average takes into account the entire history of X, it is sometimes useful to compare it to an “n-day” average. The closer w is to 1, the shorter term the exponential average becomes. From the formula, it is clear that for w equal to 1, the exponential average of X is precisely X. Conversely, the closer w is to zero, the longer term the exponential average becomes.
| “exponential_average” | Series | Constant (Number) |
|---|---|---|
exponential_average | (HO, | Weight) |
This study returns XMIM's mathematical value corresponding to the day as encoded within the software.
![]()

where d is the day encoded in XMIM date D. See the entry for the section called “Construct Date” for an explanation.
| “extract_day” | from | Date |
|---|---|---|
extract_day | from | 1996 |
This study returns XMIM's mathematical value corresponding to the month as encoded within the software.
![]()

where m is the month encoded in the XMIM date D. See the entry for the section called “Construct Date” for an explanation.
| “extract_month” | from | Date |
|---|---|---|
extract_month | from | 1996 |
This study returns XMIM's mathematical value corresponding to the year as encoded within the software.
![]()

where y is the year encoded in the XMIM date D. See the entry for the section called “Construct Date” for an explanation.
| “extract_year” | from | Date |
|---|---|---|
extract_year | from | 1996 |
This study returns a ceiling for a series using the some units specified as “steps”. There are two fields that are required to be specified within this study- the Attribute or series (this may also be a constant/number or variable) and step. This study will return a value that is greater or equal to the Attribute and that is a multiple of the number specified in the steps field. For example, if the Close of US was specified as the Attribute and ‘2’ was specified in the steps field, the study would return a number that was divisible by 2 and that was greater than the daily closing price.
![]()

| “greatest_integer” | Series | Constant (Number) |
|---|---|---|
greatest_integer | (HO, | Step) |
Returns the highest value in a data series during a specified period of time.
Identification of a succession of higher highs and higher lows is a technical method commonly used to designate an uptrend and may be used to identify certain trending patterns within your studies.


This study will ignore any NaN values. If all the X values are NaN, it will return NaN. Otherwise, it will return the maximum of the non-NaN values.
| Constant (Number) | Time Period (day/mth/yr) | “highest” | of | Series |
|---|---|---|---|---|
1 | day | highest | of | HO |
This language structure lets you assign a Series based on time, date, event or price conditions. It creates a logical structure so that if the condition in the ‘If’ clause is true, the Series represented by the ‘Then’ clause is assigned on that date.
| if | Condition | then | Series | endif |
|---|---|---|---|---|
if | Date is NG expiration_day | then | HO | endif |
if | HO is more than CL | then | CL | endif |
if | 1 week % move of HO is more than 10 | then | 1 week % move of HO | endif |
This study returns the inverse logarithm for a specified Attribute or series.
![]()

If X is NaN, its inverseLog is also NaN.
| “inverse_log” | of | Series |
|---|---|---|
Inverse_log | of | HO |
Returns a value for a given attribute based on a linear regression (fitting data to a line, such as y=ax + b) over a specified time period. Linear regression is a statistical method of following trends. According to industry authorities, the results of linear regression studies are quite similar to the moving averages. This study performs a linear regression over a specified time period.
![]()

where 
and 
are the linear regression coefficients, computed
as follows:






The formulas stated above are the standard formulas for linear regression; however, they are not well-suited to a computer implementation, because they suffer from severe round-off errors. To alleviate this, XMIM implements the equivalent formulas below instead:




Note that some of the expressions above are actually simple functions of n, i.e.,
![]()

In general, XMIM will pre-compute these expressions, and so the formulas above are greatly simplified (and largely unrecognizable). LinearRegression ignores any NaN values in X. That is, if 3 values are NaN in the computation of linearRegression(X, 10), XMIM computes linearRegression(X’ 7) instead, where the X’ are derived from X by “stripping” away the NaN values. Note in particular that the placement of NaNs throughout the X time series is not significant.
| Constant (Number) | Time Period (day/mth/yr) | “linear_regression” | of | Series |
|---|---|---|---|---|
1 | day | linear_regression | of | HO |
Returns the lowest value in a data series during a specified period of time. This function is helpful in identifying lower highs and lower lows, characterizing an downward trend pattern.
![]()

This study will ignore any NaN values. If all the X values are NaN, it will return NaN. Otherwise, it will return the minimum of the non-NaN values.
| Constant (Number) | Time Period (day/mth/yr) | “lowest” | of | Series |
|---|---|---|---|---|
1 | day | lowest | of | HO |
This study’s name is short hand for moving average convergence divergence oscillator. This indicator was developed by Gerald Appel and is widely employed to measure market momentum as well as detecting and following trends. This study measures the rate of convergence and divergence between two exponentially smoothed moving averages (or the rate of acceleration or deceleration between a faster or shorter period moving average and a slower or longer period moving average). There are three fields that must required to be specified within this study- the Attribute or series and two fields representing the weights for the faster and slower exponentially smooth moving averages. This study will return the difference between the two moving averages. A value of ‘0’ would indicate that the averages are exactly the same whereas a positive value (where the faster average was the first defined weight field) would indicate acceleration and a negative value would indicate deceleration.
![]()

For an explanation of the w 1, w2 and w 3 arguments, see the discussion about the section called “Exponential Average”.
| “macd_osc” | Series | Constant (Number) | Constant (Number) |
|---|---|---|---|
macd_osc | (HO, | Weight 1 | Weight 2) |
This study incorporates a ‘signal’ line into the study, macd_osc, listed above. Where the first two fields represent the faster and slower moving averages in the macd_osc study, the third weight represents the exponential weight of this macd_osc study. So in effect this study is an exponential study, as defined by the third weight, of macd_osc created by the first two weight fields. The basic method of incorporating this study into a trading program is to look for buy signals when the macd_osc crosses above the macd_signal and to look for sell signals upon the reverse.
![]()

For an explanation of the w 1, w 2, and w 3 arguments, see the discussion about the section called “Exponential Average”.
| “macd_signal” | Series | Constant (Number) | Constant (Number) | Constant (Number) |
|---|---|---|---|---|
macd_signal | (HO, | Weight 1 | Weight 2 | Weight 3) |
Returns the median value in a data series. Median function first sorts the data series, and then returns the median value. If the data item number in the series is odd, it returns the middle data item in the series. Otherwise, it returns the middle two data item average. For example, if the data series is (10, 4, 7), the median value is 7. If the data series is (10, 2, 3, 27), the median value is (3+10)/2=6.5
![]()

This study will ignore any NaN values. If all the X values are NaN, it will return a NaN. Otherwise, it will return the non-NaN median value.
| “median” | Constant (Number) | Time Period (day/mth/yr) | “median” | of | “Close” | of | Series |
|---|---|---|---|---|---|---|---|
3 | day | median | of | Close | of | CL |
This study returns the mathematical midpoint for a specified Attribute and is calculated by dividing the sum, of the High of the Attribute and the Low of the Attribute, by 2. A popular method of employing this study is to gauge a 50% market retracement (as defined as some point below the midpoint), off from some specified high, as potential entry points for a trading program. The syntax “midpoint” or “mid_point” may be used.
![]()

Where X is the High of the Attribute and Y is the Low of the Attribute.
| “midpoint” or “mid_point” | of | Series |
|---|---|---|
midpoint | of | HO |
mid_point | of` | HO |
Returns the difference between the start and end values over a specified time period.
![]()

If either X or X n is a NaN, the immediately preceding value will be considered instead, i.e., X 1 or X n+1 . If these values are also NaN, the move will be NaN as well. For example, when computing a 2 day move, if X is a NaN, but X 2 is not, then XMIM will return X 1 – X 2 instead of X – X 2. But, if X 1 is also NaN, then XMIM will return NaN.
| Constant (Number) | Time-Period (day/mth/yr) | “move” | of | Series |
|---|---|---|---|---|
1 | day | move | of | HO |
This study returns the natural logarithm for a specified Attribute or series.
![]()

If X is NaN or less than or equal to 0, naturalLog returns NaN
| “natural_log” | of | Series |
|---|---|---|
natural_log | of | HO |
This study will return either the smallest integer or the greatest integer, depending upon which value is closest to the value of the Attribute or series selected. This study may be used to calibrate where the value of the Attribute is relative to some ceiling (greatest integer) or floor (smallest integer).
![]()

or
![]()

depending on which of the two values is closer to N. If N is the midpoint of these two values, XMIM chooses greatestInteger (N, s) arbitrarily.
| “nearest_integer” | Series | Constant (Number) |
|---|---|---|
Nearest_integer | (HO | Step) |
This study will only return the value of the Attribute specified where the value is a negative number. Where the value is positive or zero the value returned is '0'.
![]()

Notice that this function never returns a positive number. If X is NaN, negativeValue returns NaN as well.
| “negative_value” | of | Series |
|---|---|---|
Negative_value | of | HO |
This study is the same as the “move study”, but the sign of the change is removed. Net change is the absolute value of the move.
![]()

This study treats NaNs analogously to move. It also performs the same special cases.
| Constant (Number) | Time-Period (day/mth/yr) | “net_change” | of | Series |
|---|---|---|---|---|
1 | day | net_change | of | HO |
This study returns the absolute value of the percentage move over some time period specified.
![]()

This study treats NaNs analogously to move. It also performs the same special cases.
| Constant (Number) | Time-Period (day/mth/yr) | “net_percent_change” | of | Series |
|---|---|---|---|---|
1 | day | net_percent_change | of | HO |
This study quantifies the trend in volume over time and is most closely identified with research conducted by Joseph Granville. There are several methods by which this study may be analyzed. The primary methods are trend assessment and divergence analysis. The study returns a cumulative value representing the running total equated to the sum of (daily or periodic volume multiplied by 1, where the daily or periodic move is positive, or by -1, where the move is negative). This study is a ‘running’ calculation based on market direction and volume. The only field required to be specified for the study is the Attribute.
![]()

where sign is 1 if Close of S is up and -1 otherwise. The expression onBalanceVolume1(S) refers to the previous value of onBalanceVolume(S).
| “on_balance_volume” | of | Series |
|---|---|---|
on_balance_volume | of | HO |
This study returns the number of periods (days, weeks, etc.) in some specified window time. The most interesting use of this study is to calibrate the number of periods or days between two given conditions. For example, the periods in range from the time when some value crosses above a moving average to when the value crosses below. This example could assist in identifying the period of time a certain trade would be active based on a moving average system.
![]()

where #n counts the number of periods (days, weeks, etc.) in the time period n. If this time period is specified as a from/to range, and the boundaries are reversed (i.e., the “from” occurs after the “to”), periodsInRange returns a negative number.
| "periods_in_range" | Constant (Number) | Time Period (day/mth/yr) |
|---|---|---|
periods_in_range | 1 | day |
This study will only return the value of the Attribute specified where the value is a positive number. Where the value is negative or zero the value returned is ‘0’.
![]()

If X is NaN, positiveValue returns NaN as well.
| “positive_value” | of | Series |
|---|---|---|
positive_value | of | HO |
This study will return the product (the multiplication of some values to each other) of those values of an Attribute as defined over some period of time. Where there exists a holiday or missing data (expressed by NaN) the equation is multiplied by ‘1’. There are two fields that must be specified within this study- the Attribute or series and time period.
![]()

This study will ignore any values that are NaN. That is, it returns the product of the non-NaN values in the given range. If all the X values are NaN, product returns a NaN.
| “product” | Series | Time Period (day/mth/yr) |
|---|---|---|
product | (HO, | day) |
This study will return the range for some specified Attribute by subtracting the High of the Attribute - the Low of the Attribute. Trading ranges, performed for certain key periods (i.e. calendar month or 6 months), are used to establish the upper and lower boundaries that are essential to defining levels of support and resistance. Breakouts from established trading ranges provide important trading signals.
![]()

| “range” | of | Series |
|---|---|---|
range | of | HO |
This study returns the difference between the period percent move of one data series versus another defined series. This study is useful for attribution analysis (research that defines what portion of a security’s price is ‘attributable’ to the broad market moves). The most interesting use of this study is to compare the price of a security or market sector versus its comparable broad market index to see whether the security or sector is outpacing or under-performing the index.
![]()

| “rel_strength” | Sec Series | Index Series | Constant (Number) |
|---|---|---|---|
rel_strength | (HO, | CL, | NumDays) |
The MIM will adjust all studies using futures contract so that the artificial price jump associated with the expiration of a contract will not be factored into the study. For example, if a study using the front continuous contract captured a time period which included a roll or expiration date, by default, that price difference between the old or expiring contract and the new contract would be subtracted or backed out of the equation as of the expiration date. The select_contract function is used so that the jump or price difference associated with expiration (cost of carry) is not adjusted out of the study. This is accomplished by ‘anchoring’ the current contract that satisfies our expiration requirements (i.e. if the front contract is the March 1998 contract, the studies will be performed exclusively on this contract and will ignore all previous contracts that meet our expiration requirement). There are four fields that are required to be specified within this study- the Attribute or series (select your futures series), the deferred number of the contract chosen (i.e., 1 represents the contract nearest to expiration or the front contract, 2 represents the second nearest contract to expiration, etc.), the number of days until expiration that the contract should be followed (i.e., 0 specifies that the contract will be active until expiration, 1 specifies that the contract will be active or followed up until 1 day before expiration, etc.) and contract month which is the parameter which specifies the contract month of interest (i.e., setting the field to 0 will disable this field thereby allowing the contract to roll to the regularly traded serial months, setting the field to 1 will specify only January contracts, etc.).


where![]()
is computed by replacing all references to a
relation in X with the corresponding “current” contract. The current
contract is selected as in adjustContract.
| “select_contract” | Series | Constant (Number) | Constant (Number) | Constant (Number) |
|---|---|---|---|---|
select_contract | (HO, | DeferredNum, | NumDays, | ContractMonth) |
The following shows further examples to demonstrate the use of select_contract.
Example 1:
Consider the trading day of 10/8/2002 for the following scenarios.
The “prompt” crude oil contract would be Nov 2002, CL_2002X .
Data Table
| Date | LIM SYMBOL | adjust_contract version |
|---|---|---|
10/8/2002 | CL_2002Z - Close | adjust 1st December contract out |
select_contract (CL, 1, 0, 12) | ||
29.51 | 29.51 | |
CL_2003J - Close | adjust 6th contract month out | |
select_contract (CL, 6, 0, 0) | ||
27.6 | 27.6 | |
CL_2004H - Close | adjust 2nd March contract out | |
select_contract (CL, 2, 0, 3) | ||
23.86 | 23.86 | |
CL_2005F - Close | adjust 3rd January contract out | |
select_contract (CL, 3, 2, 1) | ||
23.03 | 23.03 |
Let’s look closer at each of these to see how the select_contract function chooses the correct contract.
December 2002 contract: This is the nearest December contract right now. The explicit LIM symbol is CL_2002Z. To ask for the closest contract month using select_contract you fill in select_contract (CL, 1, 0, 12), where:
CL = base commodity symbol of choice.
1 = N nearest. 3 would imply the 3rd nearest, 6 the 6th nearest.
0 = This is “Number of days before Expiration”. Setting this number to “0” indicates the series will locate the next nearest contract when the contract expires. Setting this number to “4” would mean that the contract should roll to the next one 4 days before expiration of the current contract.
12 = This is the contract month, 12 equals December, 5 equals May, 7 equals July.
Setting this number to “0” makes the parameter inactive, meaning the other parameters will determine the behavior. |
April 2003 contract: This is the 6th nearest contract out. The explicit LIM symbol is CL_2003J. To ask for the literal N contract out using select_contract, you fill in select_contract (CL, 6, 0, 0), where:
CL= base commodity symbol of choice.
6 = N nearest. 6 points to the 6th closest or nearest to expiration active contract.
0 = This is “Number of days before Expiration”. Setting this to “0” indicates the series will locate the next nearest contract when the contract expires. Setting this to “4” would mean that the contract should roll to the next one 4 days before expiration of the current contract.
0 = Normally, this is where you put in the contract month. However, since we want the exact 6th closest contract, this is set to “0”.
March 2004 contract: This is the 2nd nearest March contract. The 1st nearest is the March 2003 contract. The 3rd nearest would be March 2005. To ask for the 2nd nearest March using select_contract, you would fill in select_contract (CL, 2, 0, 3) where:
CL = base commodity symbol of choice.
2 = 2nd nearest
0 = This is “Number of days before Expiration”. Setting this to “0” indicates the series will locate the next nearest contract when the contract expires.
3 = March contract.
January 2005 contract: This is the 3rd nearest January contract. The closest or first nearest would be January 2003. To ask for the 3rd nearest using select_contract, you will fill in select_contract (CL, 3, 2, 1), where:
CL = base commodity symbol of choice
3 = 3rd nearest
2 = This is “Number of days before Expiration”. Setting this to “2” indicates the series will roll 2 days before the contract expires and choose the next 3rd nearest contract.
1 = January contract.
Example 2:
SHOW
NGjan: select_contract ( NG, 1, 0, 0 )
NGfeb: select_contract ( NG, 2, 0, 0 )
NGmar: select_contract ( NG, 3, 0, 0 )
avg:
(select_contract ( NG, 1, 0, 0 ) + select_contract ( NG, 2, 0, 0 ) +
select_contract ( NG, 3, 0, 0 )
) / 3
WHEN
Date is December Simple relative strength index is a variation of Welles Wilder's Relative Strength Index indicator and is a popular overbought-oversold measure. These measures are intended to reflect situations when prices have risen or fallen too sharply and are thus vulnerable to a market reaction. Wilder's version uses a form of exponential smoothing where simple_rsi uses a simple moving average. This study compares the relative strength of prices gains (closes that are higher than the previous day's close) versus price losses (closes that are lower than the previous day's close) by averaging these values for some specified period of time. Simple_rsi may be performed for any time period. Wilder originally suggested 14 days, however, technicians sometimes prefer a shorter/more sensitive period of time such as 5 or 7 days. Industry standards derive the overbought and oversold indicators at levels that range around 70 (overbought) and 30 (oversold).
![]()

where U and D are the average of the 1-period up-and down-moves of X, respectively, over the period n. That is, U and D are given by
![]()

![]()

Note in the definition of D that D is always positive, since negativeValue is never positive. |
| “simple_rsi” | Series | Constant (Number) | Time Period (day/mth/yr) |
|---|---|---|---|
simple_rsi | (HO, | 1 | day) |
This study returns the floor for a series using units specified as ‘steps’. There are two fields that are required to be specified within this study- the Attribute or series (this may also be a constant/number or variable) and step. This study will return a value that is lesser or equal to the Attribute and that is a multiple of the number specified in the steps field. For example, if the Close of US was specified as the Attribute and ‘2’ was specified in the steps field, the study would return a number that was divisible by 2 and that was lesser than or equal to the daily closing price.
![]()

That is, smallestInteger returns the floor of N using the units in s. For example, smallestInteger (5, 2) is equal to 4, because 4 is the largest multiple of 2 less than or equal to 5. Similarly, smallestInteger (5.3, .25) is equal to 5.25.
| “smallest_integer” | Series | Constant (Number) |
|---|---|---|
smallest_integer | (HO, | step) |
This study provides the standard deviation of a population based on the sample as defined by the values included in the specified time period. Standard deviation measures the spread from the mean (or measures how far from the center or mean the data tends to range). This study is a commonly used statistic used to measure the degree of dispersion in the data.
![]()

This corresponds to the standard deviation used for population samples.
| Constant (Number) | Time Period (day/mth/yr) | “standard_deviation” | of | Series |
|---|---|---|---|---|
1 | month | standard_deviation | of | HO |
1 | quarter | standard_deviation | of | (2 * CL) |
2 | year | standard_deviation | of | 1 day move of HO |
Returns a moving population standard deviation of values in the time period (uses n as a divisor) based on the population itself, that is, the values in the period.


For efficiency and stability, this formula is actually computed as follows:
![]()

| Constant (Number) | Time Period (day/mth/yr) | “standard_deviation_population” | of | Series |
|---|---|---|---|---|
1 | day | standard_deviation_population | of | HO |
Returns the sum total of all the values in the series during some specified time period. Holidays and missing values (expressed as Nan) have no effect on the sum. As with any study, if you want the sum to always include a set number of periods or days than use the term ‘value’ in lieu of day.
![]()

This study will ignore any values that are NaN. That is, it returns the sum of all the non-NaN values in the period n. If all the X values are NaN, sum returns a NaN.
| Constant (Number) | Time Period (day/mth/yr) | “sum” | of | Series |
|---|---|---|---|---|
1 | day | sum | of | HO |
This study is very similar to the 'midpoint' study except ‘High’ is defined as the true High or the greater of either today’s or yesterday’s High and ‘Low’ is defined as the true Low or lesser of either today’s or yesterday’s Low. For most days, the true High will be identical to today’s High and the true Low will be identical to today’s low. The differences, where the previous day’s value is selected, will occur on downside gap days (the range is below yesterday’s range) or conversely upside gap days (the range is above yesterday’s range). By using the ‘true’ value, we can factor in the downside or upside gap in price.
![]()

where H is the higher of the High of S and the previous Close of S, and L is the lower of the Low of S and the previous Close of S.
| “true_midpoint” | of | Series |
|---|---|---|
true_midpoint | of | HO |
The True Range indicator is the greatest of the following:
The current High less the current Low
The absolute value of: current High less the previous Close
The absolute value of: current Low less the previous Close
trueRange(S)?maximum((High-Low), (|High-Close 1 day ago|), (|Low-Close 1 day ago|))
| “true_range” | of | Series |
|---|---|---|
true_range | of | HO |
This study returns the statistical variance of a population based on the values specified in the time period. Variance is the square of the standard deviation, which is a measure of data dispersion. A data series that has values that are widely dispersed will have a high standard deviation and variance.
![]()

We choose to use a different but equivalent formula to compute the above expression, so that it can be computed in a single pass. The actual formula used is:
![]()

In the cases where there are less than two non-NaN values in n, variance returns NaN.
| Constant (Number) | Time Period (day/mth/yr) | “variance” | of | Series |
|---|---|---|---|---|
1 | day | variance | of | HO |
Returns the Welles Wilder’s Relative Strength Index indicator, a popular overbought-oversold measure. This study is very similar to simple_rsi, except Wilder’s version uses a form of exponential smoothing where simple_rsi uses a simple moving average.
This study compares the relative strength of prices gains (closes that are higher than the previous day’s close) versus price losses (closes that are lower than the previous day’s close) by using an exponentially smooth average of these values for some specified period of time.
Like simple_rsi, wilders_rsi may be performed for any time period. Wilder originally suggested 14 days, however, technicians sometimes prefer a shorter/more sensitive period of time such as 5 or 7 days. This study will range between 0 and 100.
Industry standards derive the overbought and oversold indicators at levels that range around 70 (overbought) and 30 (oversold).
![]()

where U and D are the exponential average of the 1-period up-and down-moves of X, respectively, using the weight w. That is, U and D are given by
![]()

![]()

For an explanation of the weight w, see the discussion in the section called “Exponential Average”.
![]()

| “wilders_rsi” | Series | Constant (Number) |
|---|---|---|
wilders_rsi | (HO, | weight) |
This study is a momentum indicator and is used to calibrate the position of the Close relative to the High for some period. Successive values of 100 for the study may indicate an upward trend since the price of a series closes at its High. Conversely, successive values of 0 may indicate a downward trend since the price of the series closes at its Low.
| “williamsr” | of | Series |
|---|---|---|
williamsr | of | HO |