Documentation>Application Documentation>XMIM Documentation>XMIM Examples>Repeat Function Example

Repeat Function Example
 

The Repeat statement may be selected as an extension to both the SHOW Attribute as well as the WHEN Condition. This time saving feature is selected when you wish to repeat the SHOW Attribute or WHEN Condition statements for a continuous period of time.  

Topics:

Using the Repeat Function for with SHOW Attributes

Using the Repeat Function for with the WHEN Condition


Using the Repeat Function for with SHOW Attributes

After selecting what you wish to see displayed from the SHOW Attribute feature, it is useful in many situations to have XMIM display your query attribute's values for a period of time surrounding the data identified in the WHEN condition to provide context. Typically, the Repeat function is used to show your attribute before and after the occurrence date for purposes of analyzing the period leading up to a signal or the period of market activity following the signal to see if the signal had any characteristic or predictable effect on the market.

Repeat Period Pane

There are five different types of Repeat categories available for selection in the Repeat Period pane. The following describes the options associated with each Repeat category:

top


Previous / Current / Next Period 

The default Repeat category is the Previous/Current/Next Period category. The selection criteria available for the Previous/Current/Next Period category include specification of periods Previous to the Condition date specified within your query, the Current or Condition date and the Next periods following the Condition date.

The default selection criteria will repeat whatever Attribute specified in the SHOW area of the query for the Previous 1 day, the Current day and the Next day. To modify the default selection criteria simply, deselect the boxes next to Previous, Current or Next, change the number of periods specified in the text fields and change the period setting.

Example:

   SHOW
      1: Close of SP
         repeated for the previous 10 days
    WHEN
        Close of SP is more than 1 month highest of Close of SP  1 day ago

The example above will return the closing price of the S&P Futures contract for the 10 days leading up to a new monthly high for the contract.

   SHOW
     1: Close of SP
        repeated for the previous 10 and current day
   WHEN
       Close of SP is more than 1 month highest of Close of SP 1 day ago

The example above has been modified to include the closing price of SP for the date meeting the Condition as well as the 10 previous days leading up to the Condition or the new monthly high.

The Condition button located in the bottom right corner of the Previous/Current/Next Period window allows you to set up a Repeat function over irregular date event intervals. For example you can run the following query, which will show the close of the SP futures on February 1 for every year, and show the price on the previous two and next two Presidential Election Days.

Example:

   SHOW
     1: SP
        repeated for the previous 2 to next 2
          Date is Presidential Election day
   WHEN
       Date is 2/1/_

top

Period 

The Period syntax lets you create an attribute expression that repeats over the entire time period specified.

Example:

   SHOW
     1: Close of NASD
        repeated for the entire week 
   WHEN
       Date is 1st day of the year

The example above will return the closing price for the NASDAQ Composite Share Index for the entire week that includes the first day of the year (i.e. Monday through Friday that the date 1/1 falls in). This function is particularly important for conducting intra-day analysis for economic releases. XMIM has recorded the day on which certain economic releases are made. Oftentimes it will be necessary to analyze how certain securities traded during the release day (a finer grade of analysis than simply the daily bar). By using the Period syntax of the Repeat function you may return values of the specified period.

Example:

   SHOW
     1: The 1 hour BAR of US
        repeated for the entire day 
   WHEN
       Date is in "napm.rpt"

The example above will return the hourly pricing bars for the 30 year U.S. Treasury Bond Futures contract for the entire day on which the National Association of Purchasing Managers Survey is released.

top

Repeat From-To:

As with all From/To statements in the XMIM system, this feature allows you to select a specific time period range in which the Attribute values will be repeated This is similar to the Previous-Current-Next syntax, but there is a subtle difference. The Previous-Current-Next imposes the units specified on the repeat onto the series. So, for example, if you wanted to show 15-minute bars over a span ranging from a day before and two days after an event, and you were to use the Previous-Next syntax, the system would display only four 15-minute bars. This is a better overall language element because you are merely specifying the range of time over which the default attribute units will be displayed.

The following choices are available from the Condition button:

- Date Time Condition

- Custom Event

- If-Then-Else

- Server Macros

 

Example:

   SHOW
     1: Close of NG
        repeated from November to March

The example above will return the closing price of the Natural Gas Futures contract for the winter strip or the period beginning in November to March.

Example:

   SHOW
     1: The 5 minute BAR of SP
        repeated from first 5 minutes  of trading to 12:00 pm

This example using the Repeat statement was selected from the Date Time Condition option to specify the From/To time period.

top


Repeat For... To... By... 

The Repeat For…To…By language structure lets you create a "loop" using a variable that can tracks the counter values. The variable name is the name of the counter, which can be referenced elsewhere in the query. The "For" statement is the starting value, "To" is the ending value, and "By" is the amount by which the value will be increased or incremented. To invoke the Repeat For…To…By… window using the Repeat function, select Repeat For…To…By… from pull-down menu in the Repeat Period pane.

The following query will allow you to determine if there is any 'edge' or market advantage in the Standard & Poor's 500 Stock futures associated with the Fed lowering the discount rate.

Example:

   SHOW
     SP: percent_move from today to numDays days later  of SP 
         repeated for numDays from 1 to 10 by 1
   WHEN
       DISCOUNT is down

In this case, the value of numDays (our defined variable) starts off at 1, and increases by 1 until it reaches 10. Each time, it generates the movement (as a percentage) of the SP futures from "today", the day the Fed lowers the Discount rate, to numDays in the future. The above query is nearly identical to the much longer one below:

Example:

   SHOW
     1: percent_move from today to 1 day later  of SP 
     2: percent_move from today to 2 days later  of SP 
     3: percent_move from today to 3 days later  of SP 
     4: percent_move from today to 4 days later  of SP 
     5: percent_move from today to 5 days later  of SP 
     6: percent_move from today to 6 days later  of SP 
     7: percent_move from today to 7 days later  of SP 
     8: percent_move from today to 8 days later  of SP 
     9: percent_move from today to 9 days later  of SP 
     10: percent_move from today to 10 days later  of SP 
   WHEN
       DISCOUNT is down

top


In Date/Time Condition 

This last type of repeat condition lets you specify any date or time condition over which to repeat the SHOW Attribute. To invoke the In Date/Time Condition window using the Repeat function, select In Date/Time Condition from the pull-down menu in the Repeat Period pane.

This is a very generic repeat condition and can be useful for getting at values not available with any other Repeat window.

top

The Affect of Using Different Units of Time and the Repeat Function

For a more complete understanding of the Repeat feature, it is important to mention the relationship between the "time" Units settings and the Repeat options. The Attribute Units and Execution Units settings affect the results displayed when Time Offset is used within a repeat statement. When the Attribute Units are set to minutes or hours (tick mode) and you select a Time Offset feature that refers to daily mode (i.e., 1 day ago, 1 day later, etc.), the results affect the date of the attribute, not the time.

Example:

   SHOW
     1: The 15 minute BAR of SP
        repeated from 1 day ago  to 1 day later 
   WHEN
       Time is 12:00 pm

The Attribute Units in this query are set to 15 minutes and the Execution Units are defaulted to daily. Therefore, the values displayed will be the 15 minute bar chart from noon yesterday up to and including noon tomorrow. Without the Repeat function, this query would show the last 15 minute bar daily. The addition of the Repeat function will return all of the 15 minute bars meeting our defined condition.

top


Compound Attributes using the Repeat Function

Another very useful feature is to apply the same Repeat function to multiple SHOW Attributes using a single command. For example, say we want to view the bar chart of IBM, the 10 day average of Close of IBM, and the volume of IBM for 20 consecutive days. Our query could be constructed in the following manner:

Example:

   SHOW
     1: BAR of GII.IBM.NYSE
        repeated for the previous 10 to next 10 days
     2: 50 day average of GII.IBM.NYSE 
        repeated for the previous 10 to next 10 days
     3: Volume of GII.IBM.NYSE
        repeated for the previous 10 to next 10 days

However, grouping the Attribute statements and then applying the Repeat options to all statements is a more efficient and less time consuming procedure for accomplishing the same goal. Using the Curly Brace characters to combine the statements, our query now displays as follows:

Example:

   SHOW
     {
       1: BAR of GII.IBM.NYSE
       2: 50 day average of GII.IBM.NYSE 
       3: Volume of GII.IBM.NYSE
     }
       repeated for the previous 10 to next 10 days

Because the statements are grouped inside the curly braces, the repeat command will apply to all statements.

top


Using the Repeat Function for with the WHEN Condition

When selected as an extension to the WHEN Condition, the Repeat feature adds an additional level of search criteria which must be satisfied for your query. The Repeat function may be used to repeat Daily/Tick Conditions and Client or Server Macro Conditions.

Except for the "Number of Times In" option, all other options are exactly the same as the Repeat window associated with the SHOW Attribute statement. The notable difference between the Repeat windows used for a SHOW Attribute and the Repeat window used for the WHEN Condition is that the WHEN Condition Repeat window will be split into two columns. The right column will contain all the familiar options available in the SHOW Attribute window. The left window will contain the Number of Times In option. All Repeat functions used in the WHEN Condition allow you to create a condition that must be repeated a certain time period (repeated for previous 10 days), or a condition that will repeat at least a certain number of times in a specified time period (i.e. repeated 3 times in the previous month).

To invoke the Repeat function, select the Repeat button. The following window displays:

 

top


Number of Times In 

The Number of Time Ins option is used in conjunction with the 'normal' Repeat functions available in the Repeat Period pane of the Repeat window to capture irregular periods of time when your Condition is repeated. There are two options available for repeating a WHEN Condition using Number of Time In function: repeated for a time period and repeated a number of times in a time period.

The following WHEN Conditions may be created using the Number of Times In function:

Example:

   SHOW
     1: percent_move from 10 days later  to 20 days later  of GII.IBM.NYSE 
   WHEN
       GII.IBM.NYSE is down more than 10
     AND
       GII.IBM.NYSE is up more than 10
       repeated 1 time in the next 10 days

The example above will return the 10 day percent move of IBM when the price of the stock drops by $10 in one day followed by a one day correction of the same amount in the next 10 days to follow the decline.

Example:

SHOW

1: Bar of DEC

repeated for previous 10 to next 10 days

WHEN

DEC is up more than 2%

repeated 2 times in the entire month

  

The example above will return the 20 days of daily pricing bars of Digital Equipment Corporation stock when the price of the stock drops is up more than 2% in one day twice in one month.

The following examples will review the normal Repeat functions as they are used in conjunction with WHEN Condition statements:

top


Previous, Current, Next

Example:

   WHEN
       Close of GII.IBM.NYSE is more than Close of GII.IBM.NYSE 4 days ago 
       repeated for the previous to next 8 days

  

This Condition will only be satisfied when IBM closes higher than the close of IBM 4 days ago for 9 days in a row. Previous, Current, and Next were all selected from the top portion of the Repeat window.

top


From/To

Example:

   WHEN
       The 1 minute Close of US is down more than 2
       repeated from today to 2 hours later

This Condition will be satisfied when the close of US is down more than 2 from the current time period of the query to 1 hour later. The Time Condition was selected to set the To option.

top
 

Period

Example:

   WHEN
       Low of US is at most 104
       repeated in the month 

This Condition is satisfied when the US low is less than or equal to 94 every day in the month. The time period unit month was selected from the In Entire option.

top  


Repeat For...To... By...

This function allows you to create a looping variable whose variable will start at the From value, will end at the To value and will increase at each iteration by the By value. This variable can be used to create conditions whose value increases or decreases with each iteration of the loop

top


In Date or Time Condition

This allows you to set up a repeating loop that lets you specify that it repeats over all instances where a date or time condition is true.

top


Compound Conditions using the Repeat Function

As with the SHOW Attribute, occasionally it is useful to combine your WHEN Conditions within the curly braces and then apply the Repeat feature to all conditions.

Example:

   SHOW
     1: The daily BAR of GC
        repeated for the previous 10 to next 30 days
   WHEN {
            Close of GC is at least High of GC
          AND
            Low of GC is at least High of GC 1 day ago  }
          repeated for the previous 3 and current day

top


Inserting the Braces 

You may type in the braces directly into the query from the Edit window.

top