enum

Syntax

input <input name>={default <enum_value_used_by_default>, <enum_value_1>, ... <enum_value_N>};

Description

Defines an enum input of string values. In order to define the input, make sure that:

  • all values are specified in braces;
  • equal values are avoided;
  • one value (not necessarily the first) is declared default using the default reserved word;
  • values containing space symbols are placed in double quotes.

 

Note: enum input names are case and underscore insensitive.

Example

declare lower;


input exchange = {default NYSE, NASDAQ, AMEX};

def breadth;
switch (exchange) {
case NYSE:
breadth = close("$UVOL") - close("$DVOL");
case NASDAQ:
breadth = close("$UVOL/Q") - close("$DVOL/Q");
case AMEX:
breadth = close("$UVOA") - close("$DVOA");
}

plot CVI = if isNaN(close) then Double.NaN else TotalSum(if isNaN(breadth) then 0 else breadth);
CVI.SetDefaultColor(GetColor(8));

The script above is the implementation of the Cumulative Volume Index. The enum type input defines the exchange whose data will be used in calculations, with NYSE being the default one.