Ensign Windows has an array of 256 storage variables called Global Variables (GV). DYOs, Study Alerts, and Studies can read and write values and Boolean flags to these global variables. A short hand notation for a specific Global Variable will be the variable number in square brackets, like GV[2] or just [2]. The number in the brackets is the index for the GV array position.
Writing Study Values:

The study property forms have a Global column and a spinner box for each of the lines drawn by the study. In this example for Moving Averages, the 1st Average value is being saved in Global Variable 1, [1]. The 2nd Average value has been assigned to [2].
The Spread value stores in [0], but [0] will be treated as the throw away place. Although [0] is a valid variable, the selection of 0 in the Global Variable spinner should be thought of as 'not saved.'
Plotting Studies from Another Chart:
A Moving Average can plot a Global Variable as the average's Data Point. This is one way to transfer a study from another chart. Write Global Variables for the study on the other chart as shown in the previous section. Then plot the GVs using an Exponential Average study with parameters set to 1 as shown in this parameter form.

It is important to use the Exponential formula. Use parameters of 1 to plot the study from the other chart. In the following example the top chart is a 10 minute chart with 2 moving averages that store values in [1] and [2]. The 2nd chart is a 2 minute chart that plots the averages from the 10 minute chart. The Average's parameter form for the 2 minute chart is shown above. The Data Points plotted are Global Value | Variable 1 and Global Value | Variable 2.

The two charts open and calculate independently of each other. The 10 minute chart was opened at 15:20 and the two averages had values of 1090 (Blue) and 1088 (Red). These are the two values last written to [1] and [2]. Then the 2 minute chart opened, calculated, found constant values in [1] and [2] and plotted these as the flat Cyan and Green lines on the left side of the Yellow vertical line. Live data updated the chart on the right side of the Yellow line.
As new ticks arrived, both charts updated tick by tick and recalculated their averages tick by tick. The Cyan and Green lines on the 2 minute chart are plotting the 10 minute's Blue and Red averages.
read more » Studies: Transfer from Another Chart
Reusing Global Variables:
A Global Variable (GV) is just a storage place in an array. The GV reference is the index for the array. Global means this array can be written and read by any study, alert or DYO. A value or flag can be written to the array, and will remain stored there until the same global variable is written to again. The life of the variable content can be short or long depending on what the designer needs.
Studies calculate when a trade tick is received. The order of processing is from the top of the chart's object list to the bottom of the list. For a DYO, the execution is from Line A through Line J. Perhaps Line A writes a GV so Line B can use it. Then the Line A value might never be needed again, so the GV written to by Line A can be reused by Line B or another line.
The only time a truly unique global variable is needed is when a value is to be shared with another chart. Possibly a 2-minute chart writes a GV that a 10-minute chart reads. You do not know when the 2-min chart or the 10-min chart will execute, or which will execute first. Therefore, the GV written by the 2-min chart must never be used by another chart, lest it be overwritten before the 10-min chart reads its value.
Global Variables Owned Privately by a Chart:
Global Variables [0] through [199] are public, and can be read or written by any study or draw tool. There are times when a template needs private storage that will be unique to the chart the template occupies. Therefore, Global Variables [200] through [255] are owned privately by each chart and can only be written and read by the studies and tools (including ESPL) that are owned by that chart. GVs [200] through [255] cannot be used to transfer study values from one chart to another.
Read GV:

The values stored in the Global Variables can be used in the Alert Objects, Studies and DYOs. In this example, the panel A category is Function. The Ave[#] selection will average the Number of adjacent Global Variables (GV) beginning at the location of the Global Variable specified by the Read GV setting. Assume the chart has a Bollinger Band study with the Upper Band value stored in [1] and the Middle Line value stored in [2]. Panel A returns the average of these two lines, and plots the average using the Blue curve marker. The following chart shows the effect.

[#] Notation for a Set:
The notation of [#] will be used when a series of Global Variables are being used as a set. In our example the function selected was Ave[#], and it will average a group of adjacent Global Variables. The size of the set is specified by the Number field, which was 2 in the example. The Read GV spinner identifies the location of the first Global Variable in the set.

Value, Next, 3rd Notation:
'Value' will refer to the GV at the location indicated by the Global Variable spinner value. 'Next' will refer to the next GV in sequence. 'Value' and 'Next' are adjacent GVs. '3rd' will refer to the third GV in sequence. 'Value', 'Next' and '3rd' are adjacent GVs.
'#' will refer to the value in the Number field. '[#]' will refer to a set of GVs, where # is the size of the set and is the value in the Number field. If [xx] is used in the Number field, then the value from the GV reference is used as the number.
'Scale Low' is the value for the lowest scale shown on the chart. 'Scale Mid' is the midpoint between the chart's highest scale value and its lowest scale value. 'Range' is the chart's scale range which is the Scale High - Scale Low.
Functions Category:
'Sum' calculates the summation for the values in a set of GVs. 'Ave' calculates the average across a set of GVs. 'Min' finds the minimum value in a set of GVs. 'Max' finds the maximum value in a set of GVs.
Modulo returns the remainder as an integer from a division. Example: 5 Modulo 4 = 1 Round returns an integer. Fractions above 0.5 round up, and fractions below 0.5 round down. Trunc returns an integer. The fraction part is dropped. Frac return the fraction part of the expression. Abs returns the absolute value of the expression. Negative values are returned as positive values. Exp returns the value of e raised to the power of X, where e is the base of the natural logarithms. Power raises the Base (first parameter) to any power (2nd parameter). Example Ln returns the natural logarithm of the expression. Ln( e ) = 1 Log10 returns the log base 10 of the expression. Value to neartest multiple of # is used to round a value to a price multiple. Example Value Degrees for Pyrapoint # uses the Pyrapoint technology to convert a line's slope to an angle in degrees. Example 1 Example 2 Nearest[#] will return the number that is closest to Value from a set of GVs that follow Value's index. Above[#] will return the closest number that Value is above from a set of GVs that follow Value's index. Below[#] will return the closest number that Value is below from a set of GVs that follow Value's index.
Number Field:
A fixed numeric value can be entered. The number field can reference a Global Variable value by enclosing the GV number in square brackets. Example: [5] will get the number value from GV[5]. Permitted GV references are [0] through [255].
Bar values such as these can be referenced. Click the read more link to see a full list of reference tags.
| [$O],[$H],[$L],[$C] |
Bar Open, High, Low, Close |
| [$V],[$T] |
Bar Volume, Tick Count |
| [$N],[$R] |
Bar Net, Range |
read more » DYO: Reference Tags
Write GV:

The Alert calculations can be written to Global Variable just like Study Values. The Alert result will be stored in the Global Variable identified by the Write Variable spinner box which is on the right side of the Marker frame. In this example the Alert result is stored in [4].
The Condition selection greatly affects the Alert result that is stored in the GV. The selections 'A above B' through 'A AND Not B' generate a Boolean True or False result. The Boolean result will store a True using a value of 255, and store a False result using a value of zero. This result for the alert is stored in the GV identified by the Write Variable.
The next five Conditions, 'Test A, Do B' through 'Do A, Do B' will store the value from panel A in the Write Variable GV. Panel A may be returning a value such as the Ave[#] in our example of a Boolean result. Panel A value is stored in GV, and then panel B is evaluated. Panel B may be a Global Action that is always done, or conditionally done depending on the result of panel A. Panel B may use the value stored by Panel A because the GV was written before before panel B is evaluated. Panel B has a separate Write GV spinner box that can be used to store the panel B value in a GV.
Global Flag:

Flags that are stored in Global Variables are stored as values. A True flag stores a value of 255, and a False flag stores a value of zero. In reading a Global Variable as a flag, any non-zero value is treated as a True flag. A zero value is treated as a False flag.
'Count True[#]' will count the number of GVs in a set that hold a Boolean True, ie. value is non-zero. Example 'Count False[#]' will count the number of Boolean False values in a set of GVs. These two selections are very useful in establishing a Consensus among a set of signals stored in Global Variables. See the Study Consensus example where these global flags are used to create the final Buy and Sell signals.
'AND[#]' will perform the Boolean AND operation between each member of the set of GVs. Example: With # = 3, and Read GV = 5, results in: Flag = [5] AND [6] AND [7] 'AND[#] OR Next' will perform the AND on the set, and then the GV following the set is ORed. Example: With # = 3, and Read GV = 5, results in: Flag = ( [5] AND [6] AND [7] ) OR [8] 'AND[#] OR AND[#]' will AND two equal size sets, one following the other, and then OR them. Example: With # = 2, and Read GV = 4, results in: Flag = ( [4] AND [5] ) OR ( [6] AND [7] )
The OR operator sets mimic what has been described for the AND operator sets. The Modulo operator returns the remainder as an integer from a division. Example: 5 Modulo 4 = 1
Value >= Next[#] - The [#] notation refers to a set, and Next refers to the Global Variable that follows the Value reference. So Next[#] would be a set of GVs the flag is testing. Example: A statement with Read GV = 50 and # = 9 would compare the value in GV[50] with the set of values in GV[51] through [59].
Value > High[#] - The [#] notation refers to a set, and High refers to a bar's High. So High[#] would be a set of bar High values the flag is testing. Example: A statement with Read GV = 50 and # = 9 would compare the value in GV[50] with the set of 9 bar Highs beginning at this bar's position and looking leftward for 8 additional bar highs.
read more » DYO: Boolean Logic Examples
Variables Quote Page:
A special custom quote page named 'Variables' will display the 200 public Global Variables in a matrix. The GV values will update in real-time. Zero values are shown as a blank. Boolean True values are shown using the word 'True'.

read more » DYO: Tutorial watch video» Design Your Own
Last modified 8/26/09 5:50 PM
|