Formulas for Server Macros

When creating formulas with server macros, use the symbol names. Using Row Labels with server macros when constructing formulas is not supported.

_CoolingDegreeDays

Originally designed to evaluate energy demand and consumption, degree days are based on how far the average temperature departs from a human comfort level of 65 °F *. Simply put, each degree of temperature above 65 °F is counted as one “cooling degree day”. For example, a day with an average temperature of 80 °F will have 15 cooling degree days. Source: www.weather2000.com/dd_glossary.html.

_CoolingDegreeDays (Series)

Example:

The Series input is always the symbol for a city.

   SHOW 
     cdd: _CoolingDegreeDays ( HOUSTON.TX )  
   WHEN 
       Date is August 

The query above will calculate the daily cooling degree days during the month of August in Houston,TX . As you can see it gets quite warm.

“_CoolingDegreeDays”City

_CoolingDegreeDays

(HOUSTON.TX)

_HeatingDegreeDays

Originally designed to evaluate energy demand and consumption, degree days are based on how far the average temperature departs from a human comfort level of 65 °F*. Simply put, each degree of temperature below 65 °F is counted as one “heating degree day”. For example, a day with an average temperature of 60 °F will have 5 heating degree days. Source: www.weather2000.com/dd_glossary.html.

_HeatingDegreeDays (Series)

Example:

The Series input is always the symbol for a city.

   SHOW 
     hdd: _HeatingDegreeDays ( CHICAGO.OHARE.IL )  
   WHEN 
       Date is February

The query above will calculate the daily heating degree days during the month of February in Chicago,IL . Bring a jacket!

“_HeatingDegreeDays”City

_HeatingDegreeDays

(CHICAGO.OHARE.IL)

_OffPeakAverage

This macro is designed to calculate the Off Peak Average as it relates to hourly power prices. Many ISO data feeds are available from LIM. (PJM, NYISO, NEPOOL, IMO, and many European ones as well).

_OffPeakAverage (Series)

Example:

The Series input will be the symbol for a particular zone/node. Run this using “hourly” execution units.

   SHOW 
     1: _OffPeakAverage ( PJM.WESTERNHUB.HUB.RT )  
   WHEN 
       Date is within 1 week

The query above will calculate the Off Peak Average for the real-time LMP prices on the Western Hub area of PJM. There are some assumptions being made in the calculation. These have been collected from the industry and seem to be standard. Namely, on NERC holidays the Off Peak Average uses all hours in the day. On normal days (non-NERC holidays) hours 1-7 and hour 24 is used in the calculation.

“_OffPeakAverage”Series

_OffPeakAverage

(PJM.WESTERNHUB.HUB.RT)

_OnPeakAverage

This macro is designed to calculate the On Peak Average as it relates to hourly power prices. Many ISO datafeeds are available from LIM. (PJM, NYISO, NEPOOL, IMO, and many European ones as well).

_OnPeakAverage (Series)

Example:

The Series input will be the symbol for a particular zone/node. Run this using “hourly” execution units.

   SHOW 
     1: _OnPeakAverage ( NYISO_DUNWOD_TWRT )  
   WHEN 
       Date is within 3 weeks 
     AND 
       Date is from Monday  to Friday  
     AND 
       Time is 03:00 pm

The query above will calculate the On Peak Average for the real-time LMP prices in ZONE I (Dunwoodie) of NYISO. There are some assumptions being made in the calculation. These have been collected from the industry and seem to be standard. The On Peak average is calculated during Monday to Friday only. Hours 8 – 23 are considered in the average. Notice that you can have 1 number per day returned if you anchor the WHEN condition with a time. This is only an anchor and will not affect the results of the query.

“_OnPeakAverage”Series

_OnPeakAverage

(NYISO_DUNWOD_TWRT)

These macros below ( _2x8Average through _7x16Average) will only be relevant when looking at intraday data (e.g. hourly) in the electricity markets. The typical sources of this data from LIM are the Independent System Operators (ISO’s) in North America, which include PJM, (Pennsylvania Jersey Maryland), NYISO (New York), NEISO (New England) and MISO (Midwest) – in particular the macros will only work in those markets that use LMP pricing methods. The user should note that different US regions have different concepts of peak and off-peak and that generally speaking, the Western region treats Saturday as a peak period and the Eastern region does not.

These types of calculation may also be relevant for European Electricity markets with intra-day pricing as well, although definitions of peak and off-peak pricing again will vary by region.

_2x8Average

This macro is designed to calculate the average for Saturday and Sunday from 12am – 6pm and 11pm.

_2x8Average (Series)

Example:

The Series input will be the symbol for a particular zone/node. The column “lmpVal” is assigned to each Series in the macro script. Therefore only symbols with the column, LmpVal can be used in this macro. Run this using “hourly” execution units.

   SHOW 
     1: _2X8Average ( A418.138KV.TR7212.PJMRT )  
   WHEN 
       Date is within 1 week  

The query above will calculate the average for hours 1-7 and hour 24 on Saturday and Sunday for the real-time LMP prices for the Pnode ID: 32408579 for PJM. Notice in the macro code below, there are some assumptions being made in the calculation. These have been collected from industry and seem to be standard.

“_2x8Average”Series

_2x8Average

(A418.138KV.TR7212.PJMRT)

Macro Code:

ATTR MACRO _2X8Average ( SECURITY PricePoint)  
RETURN 
IF Date is Saturday
OR Date is Sunday
THEN average from 12:00 am to 11:00 pm of 
IFTime is from 12:00 am to 06:00 am 
OR Time is 11:00 pm 
THEN lmpval of PricePoint ENDIF ENDIF
ENDMACRO               

_2x16Average

This macro is designed to calculate the average for Saturday and Sunday from 7am – 10pm.

_2x16Avaerage (Series)

Example:

The Series input will be the symbol for a particular zone/node. The column “lmpVal” is assigned to each Series in the macro script. Therefore only symbols with the column, LmpVal can be used in this macro. Run this using “hourly” execution units.

   SHOW 
     1: _2X16Average ( NEPOOL.Z.CONNECTICUT.DA )  
   WHEN 
       Date is within 3 months 
     AND 
       Time is 04:00 pm 
     AND 
       Date is from Saturday  to Sunday
  

The query above will calculate the average for hours 8-23 on Saturday and Sunday for the real-time LMP prices for the New England ISO LMP LOAD ZONE Day Ahead Market. Notice in the macro code below, there are some assumptions being made in the calculation. These have been collected from industry and seem to be standard.

“_2x16Average”Series

_2x16Average

( NEPOOL.Z.CONNECTICUT.DA )

Macro Code:

ATTR MACRO _2X16Average ( SECURITY PricePoint)  
RETURN  
IF Date is Saturday
OR Date is Sunday
THEN average from 07:00 am to 10:00 pm of lmpval of  
PricePoint ENDIF
ENDMACRO

_5x8Average

This macro is designed to calculate the average for Monday through Friday from 12am-6am and 11pm.

_5x8Average (Series)

Example:

The Series input will be the symbol for a particular zone/node. The column “lmpVal” is assigned to each Series in the macro script. Therefore only symbols with the column, LmpVal can be used in this macro. Run this using “hourly” execution units.

   SHOW 
     1: _5X8Average ( NYISO_GENESE_DA )  
   WHEN 
       Date is within 2 years 
     AND 
       Date is from Monday  to Friday  
  

The query above will calculate the average for hours 1-7 and hour 24 Monday thru Friday for the real-time LMP prices for the NYISO Load Zone Genesee Real Time Market. Notice in the macro code below, there are some assumptions being made in the calculation. These have been collected from industry and seem to be standard.

“_5x8Average”Series

_5x8Average

( NYISO_GENESE_DA )

Macro Code:

ATTR MACRO _5X8Average ( SECURITY PricePoint)  
RETURN
IF Date is from Monday  to Friday
THEN average from 12:00 am to 11:00 pm of IF
Time is from 12:00 am to 06:00 am 
OR
Time is 11:00 pm
THEN lmpval of PricePoint 
ENDIF
ENDMACRO
               

_5x16Average

This macro is designed to calculate the average for Monday through Friday from 7am – 10pm.

_5x16Average (Series)

Example:

The Series input will be the symbol for a particular zone/node. The column “lmpVal” is assigned to each Series in the macro script. Therefore only symbols with the column, LmpVal can be used in this macro. Run this using “hourly” execution units.

   SHOW 
     1: _5X16Average ( DELAWARECT11.AGGREGATE.PJMDA )  
   WHEN 
       range of DELAWARECT11.AGGREGATE.PJMDA  is less than 0.25 
     AND 
       Date is from Monday  to Friday  

The query above will calculate the average for hours 8-23 on Monday through Friday for the real-time LMP prices for the Day Ahead Locational Marginal Price in Delaware. Notice in the macro code below, there are some assumptions being made in the calculation. These have been collected from industry and seem to be standard.

“_5x16Average”Series

_5x16Average

( DELAWARECT11.AGGREGATE.PJMDA )

Macro Code:

ATTR MACRO _5X16Average ( SECURITY PricePoint) 
RETURN
IF Date is from Monday  to Friday
THEN average from 07:00 am to 10:00 pm of lmpval of
PricePoint
ENDIF 
ENDMACRO

_7x8Average

This macro is designed to calculate the average for Monday through Friday from 12am-6am and 11pm.

_7x8Average (Series)

Example:

The Series input will be the symbol for a particular zone/node. The column “lmpVal” is assigned to each Series in the macro script. Therefore only symbols with the column, LmpVal can be used in this macro. Run this using “hourly” execution units.

   SHOW 
     1: _7X8Average ( NYISO_ALLEGHENY_COGEN_DA )  
   WHEN 
       Date is before 7/27/2001 

The query above will calculate the average for hours 1-7 and hour 24 on Sunday thru Saturday for the real-time LMP prices for the NYISO Generator ALLEGHENY___COGEN Real Time Market . Notice in the macro code below, there are some assumptions being made in the calculation. These have been collected from industry and seem to be standard.

“_7x8Average”Series

_7x8Average

( NYISO_ALLEGHENY_COGEN_DA )

Macro Code:

ATTR MACRO _7X8Average ( SECURITY PricePoint) 
RETURN
average from 12:00 am to 11:00 pm of IF
{Time is from 12:00 am to 06:00 am
OR 
Time is 11:00 pm}
THEN lmpval of PricePoint
ENDIF
ENDMACRO

_7x16Average

This macro is designed to calculate the average for Monday through Friday from 7am – 10pm.

_7x16Average (Series)

Example:

The Series input will be the symbol for a particular zone/node. The column “lmpVal” is assigned to each Series in the macro script. Therefore only symbols with the column, LmpVal can be used in this macro. Run this using “hourly” execution units.

   SHOW 
     1: _7X16Average ( NEPOOL.LD.ASHCREEK115.DA )  
   WHEN 
       Date is 1 week before  any holiday

The query above will calculate the average for hours 8-23 on Sunday through Saturday for the real-time LMP prices for the New England ISO LMP NETWORK NOD Day Ahead Market. Notice in the macro code below, there are some assumptions being made in the calculation. These have been collected from industry and seem to be standard.

“_7x16Average”Series

_7x16Average

( NEPOOL.LD.ASHCREEK115.DA )

Macro Code:

ATTR MACRO _7X16Average ( SECURITY PricePoint)
RETURN  
average from 07:00 am to 10:00 pm of lmpval of
PricePoint  
ENDMACRO 

AccDist

The Accumulation/Distribution is a momentum indicator that associates changes in price with the daily range. Divergences between the Accumulation/Distribution and the security’s price imply a change is imminent. When a divergence does occur, prices usually change to confirm the Accumulation/Distribution. For example, if the indicator is moving up and the security’s price is going down, prices will probably reverse and start going up. If the days price change is positive then the difference in the daily high and low price is added to the total, and conversely if the daily change is negative then the daily range is subtracted from the total.

AccDist (Series)

Example:

“AccDist”Series

AccDist

(DELL)

Macro Code:

COLUMN MACRO AccDist ( SECURITY Sec )
    RETURN
        Sum from begin_of_time to today of
          if Close of Sec > Close of Sec 1 unit ago then
               absolute_value ( Close of Sec -
                   if Low of Sec < Close of Sec 1 unit ago
                                then Low of Sec
                                else Close of Sec 1 unit ago
                            endif )
         else
               if Close of Sec < Close of Sec 1 unit ago then
                   0 - 
                   absolute_value ( Close of Sec -
                                 if High of Sec > Close of Sec 1 unit ago
                                    then High of Sec
                                    else Close of Sec 1 unit ago
                                 endif )
               else
               0
            endif
       endif
ENDMACRO

Aspect

Returns the difference in ecliptic longitude degrees between any two planets (except Earth). Choose planets (including Sun & Moon) relations from the “Other: Astronomy” menu in the Search Database window.

Aspect (Planet1, Planet2)

Example:

Aspect (MERCURY, SATURN)
“Aspect”Planet 1Planet 2

Aspect

(MERCURY,

SATURN)

AspectEquatorial

Returns the difference in equatorial right ascension between any two planets (except Earth, the Sun, or the Moon).

AspectEquatorial (Planet1, Planet2)

Example:

AspectEquatorial (MERCURY, SATURN)
“AspectEquatorial”Planet 1Planet 2

AspectEquatorial

(MERCURY,

SATURN)

AspectHelio

Returns the difference in heliocentric longitude between any two planets.

AspectHelio (Planet1, Planet2)

Example:

AspectHelio (MERCURY, SATURN)
“AspectHelio”Planet 1Planet 2

AspectHelio

(MERCURY,

SATURN)

AspectPlot

The following are all used in the same manner. These all plot vertical lines on the chart on days when any astrological aspect is in force. Astrologers are especially interested in the locations of solar system objects relative to other solar system objects - numbers called “aspect” angles with the centers of the Earth or Sun (depending on which coordinate system, geocentric or heliocentric, is used) located at the vertex of the measured angle. Significant aspect angles have names associated with them listed below in order of supposed importance and influence, along with the Orb - the number of degrees of tolerance often used with the aspect, and the usual symbols used to denote the angles in printed Ephemeris tables.

No. Glyphs

Aspect

Abbrev.

Aspect Angle

Orb (tolerance)

Description of Standard

1

Conjunct

(Con)

0.00

+/-7 deg.

Circle with extending line

2

Opposite

(Opp)

180.00

+/-7 deg.

Two circles joined by line

3

Square

(Squ)

90.00

+/- 7 deg.

Quadrilateral

4

Trine

(Tri)

120.00

+/- 7 deg.

Triangle

5

Sextile

(Sex)

60.00

+/- 6 deg.

Six pointed asterisk

6

Inconjunct

(Inc)

150.00

+/- 3 deg.

'K' rotated clockwise

7

Semisextile

(Ssx)

30.00

+/- 3 deg.

'K' rotated counter-clockwise

8

Semisquare

(Ssq)

45.00

+/- 3 deg.

Acute angle

9

Sesquisquare

(Ses)

135.00

+/- 3 deg.

Square with extending lines

Minor Aspects (not included in macro set - use “AspectX” macros which let you specify any arbitrary aspect angle.)

PlotAspectX

Plots vertical lines on the chart on days when any astrological aspect is in force.

PlotAspectX (Planet1, Planet2, aspect, orb)

Example:

PlotAspectX (MARS, NEPTUNE, 90, 0)
“PlotAspectX”Planet 1Planet 2Aspect (Number)Orb (Number)

PlotAspectX

(MARS,

NEPTUNE,

90,

0)

The following are all used in the same manner:

  • PlotConjunct

  • PlotInconjunct

  • PlotOpposite

  • PlotSemisextile

  • PlotSemisquare

  • PlotSesquisquare

  • PlotSextile

  • PlotSquare

  • PlotTrine

These all plot vertical lines on the chart on days when any astrological aspect is in force.

Example:

PlotConjunct (SATURN, MARS, 0)
“PlotConjunct”Planet 1Planet 2Orb (Number)

PlotConjunct

(SATURN,

MARS,

0)

BackContract

Returns the price of the back contract. This functionality is now built into the language itself. The default selection for a parent futures contract (i.e., US) is the front continuous contract. The button labeled ‘continuous’ located directly above the Symbol Browser may be toggled to ‘back’ to perform the same feature. This macro is included for backward compatibility with older versions of the XMIM software.

BackContract (Series, NumDays, ContractMth)

Example:

BackContract (NG, 0, 0)

“BackContract”SeriesNumDays (Number)ContractMth (Number)

BackContract

(HO,

1,

1)

BlackScholesOptionPrice

Computes the option price based on the Black Scholes model for a European option. The interest rate must be expressed as a decimal fraction. For example, 2% will be 0.02. The sigma argument must also be expressed as decimal fraction: e.g. 16% is 0.16. The days to expiration are in actual days and will be divided by 365 to convert to fractions of a year. For a 252 day year adjust the days input by 252/365.

BlackScholesOptionPrice (@underlying_price, @strike, @interest_rate, @sigma, @days_expiration, @is_call)

Example:

BlackScholesOptionPrice ( Close of SP_2004Z, 1100,FRH_DGS1 / 100,
(30 day std_dev of Close of SP_2004Z) / 100,
periods_in_range from today to SP_2004Z.C1100 last_data_day, 1 )
@underlying_price@strike@interest_rate@sigma@days_expiration@is_call

Close of SP_2004Z,

1100,

FRH_DGS1/100,

(30 day std_dev of Close of SP_2004Z) / 100,

periods_in_range from today to SP_2004Z.C1100 last_data_day,

1

ChannelIndex

Returns an index of bollinger bands, a statistical version of the stochastic.

Donald Lambert developed this price momentum indicator - Commodity Channel Index (CCI). It shows how the most recent close relates to the standard deviation range over the recent time period.

ChannelIndex (Series, TimePeriod)

Example:

ChannelIndex (SP, 22 days)
“ChannelIndex”SeriesConstant (Number)Time Period (day/mth/yr)

ChannelIndex

(HO,

22

days)

ChoppinessIndex

Returns an indicator that measures the sum of all the ranges in a time period to the range over the time period as a measure of the trendiness or choppiness of a price series. Inspired by chaos theory, it is similar to Wilder’s Directional Movement Index but with simpler calculations and less lag. The Choppiness Index varies between 0 and 100, the higher the index the choppier the price action is and the lower the index the more trending the price action

ChoppinessIndex (Series, TimePeriod)

Example:

ChoppinessIndex (JY, 10 days)
“ChoppinessIndex”SeriesConstant (Number)Time Period (day/mth/yr)

ChoppinessIndex

(HO,

22

days)

DeMarker

Returns Tom DeMark’s Oscillator. The DeMarker identifies potential price bottoms and tops. The indicator fluctuates between 0 and 1.

DeMarker (Series, TimePeriod)

Example:

DeMarker (Close of SPX, 15 days)
“DeMarker”AttributeofSeriesConstant (Number)Time Period (day/mth/yr)

DeMarker

(Close

of

HO,

22

days)

DeferredContract

This study provides a generalized macro for dealing with futures contracts. The DeferredContract function is used to identify certain back contract relationships within the software.

There are two methods to identify a futures contract:

  1. You may identify the ‘specific’ contract (i.e., the March 1998 30 year U.S. Treasury Bond contract or US_1998H)

  2. You may identify a ‘generic’ contract based upon the contracts expiration (i.e., the front continuous adjusted 30 year U.S. Treasury Bond contract or US). If a user wanted to test a trading strategy that involved the sixth contract on the board, or some contract expiring later than the front, far and back contracts (these selections are available under the ‘continuous’ button above the Symbol Browser), DeferredContract would be used to define contract.

There are four fields that are required to be specified within this study:

  1. The Attribute or series (select your futures series).

  2. 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.).

  3. 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.).

  4. Contract month that is the parameter that 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.).

DeferredContract (Series, DeferredNum, NumDays, ContractMth)

Example 1:

DeferredContract (US, 3, 0, 0)
“DeferredContract”AttributeDeferred NumberNumDays till expire (Number)Contract Month (Number)

DeferredContract

(US,

3,

0,

0)

The following shows further examples to demonstrate the use of DeferredContract.

Example 2:

As the macro code below shows, the deferred contract macro is using the adjust_contract built-in. Therefore, the properties that are required entry for the adjust contract are the same for the deferred contract.

Assuming the 10/8/2002 trade date, the prompt/front contract for the NYMEX natural gas futures is the November 2002 contract (NG_2002X). If we wanted to use the deferred contract macro to modify the continuous NG contract to show the 5th contract out instead of the prompt contract, we could use the following syntax:

   SHOW 
     1: DeferredContract ( NG, 5, 0, 0 )

This will modify NG to the 5th contract out. (Prompt +4). This will now show the price for the March 2003 NG contract. (NG_2003H)

  • NG= base commodity symbol of choice.

  • 5 = N nearest. 5 points to the 5th 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”.

*Any of the 4 parameters can be modified to adjust the continuous contract as described in the adjust_contract built-in definition.

Here is an example of the data:

      Date    Day    Deferred      NG_2003H
 10/08/2002   Tue      4.023         4.023

Example 3:

   SHOW 
     twoSixAvg: 
       (DeferredContract ( NG, 2, 0, 0 )  + DeferredContract ( NG, 3, 0, 0 )  
        + DeferredContract ( NG, 4, 0, 0 )  + DeferredContract ( NG, 5, 0, 
        0 )  + DeferredContract ( NG, 6, 0, 0 ) 
       ) / 5 
     frontNG: NG 
   WHEN 
       Date is within 2 years 
     AND 
       NG is DEFINED

Macro Code:

ATTR MACRO DeferredContract ( ATTR Series, CONSTANT DeferredNum = 1,
                      CONSTANT NumDays = 0, CONSTANT ContractMth = 0 )
    RETURN
      adjust_contract ( Series, DeferredNum, NumDays, ContractMth )
ENDMACRO

DirMove

DirMove returns the Welles Wilder’s Directional Movement indicator. To be used in conjunction with DirMoveIdx (below), which returns the Welles Wilder’s Directional Movement Index. DirMove uses an exponential average in its calculation, while DirMoveIdx uses simple moving average.

Example:

DirMove (Close of MSFT, 0.071428571)

“DirMove”AttributeofSeriesConstant Weight

DirMove

(Close

of

HO,

0.071428571)

DirMoveIdx

Returns the Welles Wilder's Directional Movement Index.

Example:

DirMoveIdx (Close of INTC, 78 days)
“DirMoveIdx”AttributeofSeriesConstant (Number)Time Period (day/mth/yr)

DirMoveIdx

(Close

of

HO,

78

days)

FarContract

Returns the price of the third nearest-to-delivery futures contract in a futures market. This functionality is now built into the language itself. The default selection for a parent futures contract (i.e., US) is the front continuous contract. The button labeled ‘continuous’ located directly above the Symbol Browser may be toggled to ‘far’ to perform the same feature. This macro is included for backward compatibility with older versions of the XMIM software.

FarContract (Series, NumDays, ContractMth)

Example 1:

FarContract (Close of CL, 4, 11)
“FarContract”AttributeofSeriesNumDays (Number)ContractMth (Number)

FarContract

(Close

of

HO,

4,

11)

Example 2:

As the macro code below shows, The FarContract macro is using the adjust_contract built-in. Therefore, the properties that are required entry for the adjust contract are the same for the far contract with the exception of the second adjust_contract parameter which indicates the N month out. This is always set to 3.

A user can utilize the FarContract macro to modify a continuous contract to pull the far (3rd) closest contract to expiration.

Assuming the 10/8/2002 trade date, the prompt/front contract for the NYMEX natural gas futures is the November 2002 contract (NG_2002X). If we wanted to use the FarContract macro to modify the continuous NG contract to show the 3rd contract out instead of the prompt contract, we could use the following syntax:

   SHOW 
     1: FarContract ( NG, 0, 0 )

This will always modify NG to the 3rd contract out. (Prompt +2). This will now show the price for the January 2003 NG contract. (NG_2003F).

  • NG= base commodity symbol of choice.

  • 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”.

*Any of the 3 parameters can be modified to adjust the continuous contract as described in the adjust_contract built-in definition.

Here is an example of the data:

      Date    Day      Far   NG_2003F
10/08/2002    Tue    4.243      4.243

Example 3:

   SHOW 
     macro: FarContract ( CL, 0, 0 )  
     xmimlanguage: far CL 
   WHEN 
       Date is 2001 

Macro Code:

ATTR MACRO FarContract (ATTR Series, CONSTANT NumDays = 0,
                   CONSTANT ContractMth = 0)
 RETURN
       adjust_contract (Series, 3, NumDays, ContractMth)
ENDMACRO

FrontContract

Returns the price of the nearest-to-delivery futures contract in the futures market. This functionality is now built into the language itself. The default selection for a parent futures contract (i.e. US) is the front continuous contract. The button labeled ‘continuous’ located directly above the Symbol Browser may be toggled to ‘front’ to perform the same feature. This macro is included for backward compatibility with older versions of the XMIM software.

FrontContract (Series, NumDays, ContractMth)

Example 1:

FrontContract (Close of NG, 4, 11)
“FrontContract”AttributeofSeriesNumDays (Number)ContractMth (Number)

FrontContract

(Close

of

HO,

4,

11)

Example 2:

As the macro code below shows, the FrontContract macro is using the adjust_contract built-in. Therefore, the properties that are required entry for the adjust contract are the same for the FrontContract macro with the exception of the second adjust_contract parameter which indicates the N month out. This is always set to 1.

A user can utilize the FrontContract macro to modify a continuous contract to pull the prompt or closest contract to expiration.

Assuming the 10/8/2002 trade date, the prompt/front contract for the NYMEX natural gas futures is the November 2002 contract (NG_2002X). If we wanted to use the FrontContract macro to pull the front contract, we could use the following syntax:

    SHOW 
     Front: FrontContract ( NG, 0, 0 )  

This will always modify NG to the front contract (Prompt). This will now show the price for the November 2002 NG contract. (NG_2002X)

  • NG= base commodity symbol of choice.

  • 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”.

*Any of the 3 parameters can be modified to adjust the continuous contract as described in the adjust_contract built-in definition.

Here is an example of the data:

      Date        Day      Front    NG_2002X
10/08/2002        Tue      3.862       3.862

Example 3:

   SHOW 
     macro: FrontContract ( US, 0, 0 )  
     xmimlanguage: front US 
   WHEN 
       Date is 2002

Macro Code:

ATTR MACRO FrontContract (ATTR Series, CONSTANT NumDays = 0,
  CONSTANT ContractMth = 0)
    RETURN
adjust_contract (Series, 1, NumDays, ContractMth)
ENDMACRO

HistVolLog

Returns the historical volatility of a series: the standard deviation of the logarithmic price changes measured at regular intervals of time. The default time period is 20 days. The default number of units per year is 250.

HistVolLog (Series, NumUnits, UnitsPerYear)

Example:

HistVolLog (Close of front CL, 20 days, 250)
“HistVolLog”AttributeofSeriesNumUnits

(Number)

Time Period

(day/mth/yr)

UnitsPer Year

(Number)

HistVolLog

(Close

of

HO,

20

days,

250)

HistVolPct

Returns the historical volatility of a series: the standard deviation of the percent price changes measured at regular intervals of time. The default time period is 20 days. The default number of units per year is 250.

HistVolPct (Series, NumUnits, UnitsPerYear)

Example:

HistVolPct (Close of front NG, 20 days, 250)
“HistVolPct”AttributeofSeriesNumUnits

(Number)

Time Period

(day/mth/yr)

UnitsPer Year

(Number)

HistVolPct

(Close

of

HO,

20

days,

250)

MoneyFlowIndex

The Money Flow Index measures the amount of money flowing in and out of a security. It is an oscillator not unlike RSI that incorporates Volume into its calculation. The values range between 0 and 100. Market tops generally occur around 80 and bottoms around 20.

MoneyFlowIndex (Series, TimePeriod)

“MoneyFlowIndex”SeriesNumUnits (Number)Time Period (day/mth/yr)

MoneyFlowIndex

(HO,

50

days)

NegVolIndex

Returns an accumulated sum of the close-to-close percent moves of the security when the volume is lower than the volume one period ago.

NegVolIndex (Series)

Example:

NegVolIndex (INTC)
“NegVolIndex”Series

NegVolIndex

(HO)

NetHedgers

Returns the net open interest held by traders in the commercial hedgers category of futures traders in a market. The calculation is net long minus net short positions.

NetHedgers (Series)

Example:

NetHedgers (NG)
“NetHedgers”Futures Contract

NetHedgers

(HO)

NetHedgersPct

Returns the net open interest holdings of the commercial hedger category as a percentage of total open interest in the market.

NetHedgersPct (Series)

Example:

NetHedgersPct (SP)
“NetHedgersPct”Futures Contract

NetHedgersPct

(HO)

NetLargeSpecs

Returns the net open interest held by traders in the large speculator category of futures traders in a market. That is, the net long minus net short positions.

NetLargeSpecs (Series)

Example:

NetLargeSpecs (JY)
“NetLargeSpecs”Futures Contract

NetLargeSpecs

(HO)

NetLargeSpecsPct

Returns the net open interest holdings of the large speculator category as a percentage of total open interest in the market.

NetLargeSpecsPct (Series)

Example:

NetLargeSpecsPct (US)
“NetLargeSpecsPct”Futures Contract

NetLargeSpecsPct

(HO)

NetSmallTraders

Returns the remaining net open interest held by traders with positions smaller than reporting thresholds.

NetSmallTraders (Series)

Example:

NetSmallTraders (HO)
“NetSmallTraders”Futures Contract

NetSmallTraders

(HO)

NetSmallTradersPct

Returns the net open interest of the Small Traders category as a percentage of total open interest.

NetSmallTradersPct (Series)

Example:

NetSmallTradersPct (HO)
“NetSmallTradersPct”Futures Contract

NetSmallTradersPct

(HO)

NormalDist

NormalDist(n) returns the percent of area under the normal distribution curve commonly called the z-table. The parameter n is the number of standard deviations from the mean. The macro NormalDist(n) returns the percent of the curve below parameter n. This is commonly used to compute probability.

Example:

NormalDist (5)
“NormalDist”Number of Standard Deviations from the Mean (Number)

NormalDist

(5)

RangeExpIndex

Returns Tom DeMark's REI2 indicator as explained in his book “The New Science of Technical Analysis”.

RangeExpIndex (Series, TimePeriod)

Example:

RangeExpIndex (GE, 15 days)
“RangeExpIndex”SeriesConstant (Number)Time Period (day/mth/yr)

RangeExpIndex

(HO,

15

days)

RealSum

Here Counter is a number which is the # of days to start the look back. Returns the sum of the last N days.

RealSum (Attribute, Counter)

Example:

RealSum (DELL, 3 )

is the same as

sum from 2 days ago to today of DELL

Both are considering 3 days of data for the calculation.

“RealSum”SeriesCounter (N) (Number)

RealSum

(HO,

3)

Stochastics

KStochastic

Stochastics is a momentum or price velocity indicator developed by George C. Lane. This macro is sometimes referred to as "%K" in the market. This is the normal stochastic.

KStochastic (Security, TimePeriod)

Example:

KStochastic (DELL, 18 days)
“KStochastic”SeriesConstant (Number)Time Period (day/mth/yr)

KStochastic

(HO,

18

days)

SDStochastic

This macro is an average of the "SKStochastic" macro.

SDStochastic (Security, TimePeriod, TimePeriod2)

Example:

SDStochastic (MPPP, 24 days, 10 days, 6 days)
“SDStochastic”SeriesConstant

(Number)

Time

Period1

Constant

(Number)

Time

Period2

Constant

(Number)

Time

Period3

SDStochastic

(HO,

24

days,

10

days,

6

days)

SKStochastic

This macro is sometimes referred to as "%D" in the market. It is the slower moving stochastic.

SKStochastic (Security, TimePeriod, TimePeriod2)

Example:

SKStochastic (OAT, 14 days, 4 days)
“SKStochastic”SeriesConstant

(Number)

Time Period1

(day/mth/yr)

Constant

(Number)

Time Period2

(day/mth/yr)

SKStochastic

(HO,

14

days,

4

days,

Trendline

Returns drawing of a line to connect a series of peaks or troughs on a Chart. Both uptrends and downtrends in a market can be defined in terms of trendlines.

Trendline (Price1, Date1, Price2, Date2)

“Trendline”Price 1Date 1Price 2Date 2

Trendline

(21.20,

1/1/2001

17.85,

2/3/2002)

VolPriceTrend

Returns an index which takes the distance of the close of the day from the midpoint of the day, multiplies that times the volume and sums the results over time.

VolPriceTrend (Series, TimePeriod)

Example:

VolPriceTrend (DELL, 68 days)
“VolPriceTrend”Sec SeriesConstant (Number)Time Period (day/mth/yr)

VolPriceTrend

(HO,

68

days)

Volatility

Returns the high of the period divided by the low.

Volatility (Series)

Example:

Volatility (RAD)
“Volatility”Sec Series

Volatility

(HO)

VolatilityIdx

Returns the exponential moving average of the true range.

Refer to Exponential Average notes for weight info.

VolatilityIdx (Security, Weight)

Example:

VolatilityIdx (IO, 0.0714)
“VolatilityIdx”Sec SeriesWeight

VolatilityIdx

(HO,

0.0714)

WildersADX

The familiar average directional movement index is simply the directional movement index (WildersDX) averaged for the time period chosen for study related to the previous day’s average directional movement index.

WildersADX (Series, Weight)

Example:

WildersADX (JO, 0.071428571)
“WildersADX”Sec SeriesWeight

WildersADX

(HO,

0.071428571)

WildersADXR

Returns an exponentially smoothed version of the WildersADX study discussed above.

WildersADXR (Series, Weight)

Example:

WildersADXR (CME.DB, 0.071428571)
“WildersADXR”SeriesWeight

WildersADXR

(HO,

0.071428571)

WildersDIMinus

Returns a momentum indicator typically used to identify downtrend directional behavior in the market and developed by Welles Wilder. This study is calculated by dividing the exponentially Positive Directional Movement (those days when the difference between today’s low minus the previous day’s low is greater than the difference between today’s high minus the previous day’s high) by the smoothed True Range.

WildersDIMinus (Series, Weight)

Example:

WildersDiMinus ( DS, 0.071428571)
“WildersDIMinus”SeriesWeight

WildersDIMinus

(HO,

0.071428571)

WildersDIPlus

Returns a momentum indicator typically used to identify up-trend directional behavior in the market and developed by Welles Wilder. This study is calculated by dividing the exponentially smoothed Positive Directional Movement (those days when the difference between today’s high minus the previous day’s high is greater than the difference between today’s low minus the previous day’s low) by the smoothed True Range.

WildersDIPlus (Series, Weight)

Example:

WildersDIPlus ( CNDL, 0.071428571)
“WildersDIPlus”SeriesWeight

WildersDIPlus

(HO,

0.071428571)

WildersDX

WildersDX returns the equivalent to Welles Wilder’s Directional Movement equation. This calculation divides the difference between DI+ and DI- (true directional movement) and sum of DI+ and DI- (total percentage of directional movement), and then multiplies this value by 100%.

The directional movement index (DX) is thus an accounting or a scoring between 0 - 100 of the power of the trend, be the trend up or down, a high score means the market is strongly trending (up or down) and a low score bespeaks of weak or no trend.

WildersDX (Series, Weight)

Example:

WildersDX (BO, 0.071428571)
“WildersDX”SeriesWeight

WildersDX

(BO,

0.071428571)

WildersRSI

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).

WildersRSI (Series, Weight)

Example:

WildersRSI (Close of MSFT, 0.095)
“WildersRSI”AttributeofSeriesWeight

WildersRSI

(Close

of

HO,

0.095)

WilliamsVolAD

Returns the Larry Williams Volume Accumulation-Distribution indicator.

WilliamsVolAD (Security, TimePeriod)

Example:

WilliamsVolAD (HO, 17 days)
“WilliamsVolAD”Sec SeriesConstant (Number)Time Period (day/mth/yr)

WilliamsVolAD

(HO,

17

days)