# Equilla Quotations and Time Periods

This entry is about quotations that are delivered by the provider and that you need as input values for the calculation of functions, indicators and strategies. It also offers information on working with date and time date. In the end, you can find information and examples on how to find distinct bars in a chart.

For all Equilla functions, you can find additional information in Tradesignal. To call it up, open the source code in the Equilla Editor. Then right-click on the function in question, e.g. Accelerator, and choose Lookup Equilla Function from the context menu. A window opens with information on the function and links to related functions.

## Data in Quotation Series

The most important data needed for indicators are the quotations. These are delivered by the data provider and can be displayed in a chart. In addition, you can use external quotations from locally saved files in Tradesignal. From most providers, you will receive the following data:
• Open - Opening price for each trading period
• High - High price for each trading period
• Low - Low price for each trading period
• Close - Closing price for each trading period
• Open Interest - Open interest in the case of futures

### Particularities of Volume Data

Two different definitions of trading volume are in existence, which are often confused.
• The more meaningful definition is that the trading volume is given by the number of traded stocks multiplied with its traded price. This way, the volume represents the amount of capital that was traded in the period.
• Differing from this, sometimes the trading volume is only given as turnover in traded pieces. This means only the number of traded stocks is taken as volume, without information on the traded prices. The problem is that in this case, 100 stocks at 0.20 cents would yield the same volume as 100 stocks traded at \$164.40. The number of pieces does not represent the capital used for the trades.
Make sure to ask your data provider which kind of volume data is delivered. Depending on the volume interpretation, indicator data and statistics have to be adapted or put into perspective.

### Example: Using Quotations Series without Volume

/* The following example demonstrates the usage of quotations series without volume. Four variables are declared which will be used for each of the quotation series. Following this, an average is calculated for each series, saved in the variables and displayed as a candlestick chart in a new window. Remember that Equilla scripts are processed once for each trading period. */

Meta:
Subchart ( true );

//The trading period for the average calculation is declared as input.
//You can later edit the value in the properties of the indicator.

Inputs:
Period( 10, 1 );

//Variables are declared

Variables:
myOpenValue, myCloseValue, myLowValue, myHighValue,
avgOpen, avgClose, avgLow, avgHigh;

//Day for day is processed. For each trading day, the price is assigned to
//the variables.
myOpenValue = Open;
myCloseValue = Close;
myLowValue = Low;
myHighValue = High;

/* Now the average calculation follows, which is done once per trading day. The passing of the quotations to the calculation functions is especially complicated to demonstrate the underlying principle. Alternatively, you can pass the quotations to the functions directly. avgOpen = Average ( Open, Period ); avgClose = Average ( Close, Period ); avgLow = Average ( Low, Period ); avgHigh = Average ( High, Period ); */

avgOpen = Average ( myOpenValue , Period );
avgClose = Average ( myCloseValue, Period );
avgLow = Average ( myLowValue, Period );
avgHigh = Average ( myHighValue, Period );

//With the result of the average calculations
//candlesticks are drawn
DrawCandleStick( avgOpen, avgHigh, avgLow, avgClose, Yellow, Red, DarkBlue );

### Inline Instruments and Data Inputs

Indicators can be used for more than just the quotations of a single basic symbol in the chart. Many indicators use the quotation series of more than one stock. The same applies to strategies, many of which are based on several symbols or different quotation series. For these calculations, the tools Inline Instruments and Data Inputs are available.

#### Inline Instruments Using Inline Instruments
An inline instrument is a reference to the stock data which is used directly in the source code. You have to give the symbol and the relevant quotation series. The following example calculates the difference between the quotations of Puma and Adidas Salomon. The result is displayed in a candlestick chart. It does not matter to which chart you apply this indicator - it always uses the given quotations of those two companies. Therefore, inline instruments can be used for calculation with quotations that are not a part of the current chart or portfolio.

//Generate a subchart
Meta:
Subchart( true );

//Declare variables
Variables:
openValue, highValue, lowValue, closeValue;

/* Subtract the time series. By giving the symbol in the series, quotations can be used that are not part of the current chart. */
openValue = Open of 'pum ger' - Open of 'ads ger';
highValue = High of 'pum ger' - High of 'ads ger';
lowValue = Low of 'pum ger' - Low of 'ads ger';
closeValue = Close of 'pum ger' - Close of 'ads ger';

//Display result as candlesticks
DrawCandleStick( openValue, highValue, lowValue, closeValue, White, Red, Black );

#### Dynamic Inline Instruments

Tradesignal 6 offers you the ability to create inline instruments based on runtime information, e.g. the string inputs of an indicator or strategy may be used instead of a constant string expression.

See the Equilla Formula Language reference entry Instruments in Tradesignal for more details on importing symbols.

//Import a single instrument and reference it in the script by using DrawLine on its variable
Input:
Symbol( "" );

Instruments:
mySymbol( Symbol );

DrawLine( mySymbol );

You can also create a list of inline instruments and reference any of the symbols in the list via its index which starts at zero.

//Import a list of instruments and calculate the average price
Input:
ListSymbol( "" );

Instruments:
myInstruments( List( ListSymbol ) );

Variables:
prices( 0 ), i( 0 );

prices = 0;

For i = 0 to Len( myInstruments ) - 1 Begin
prices = prices + Close of myInstruments( i );
End;

If Len( myInstruments ) != 0 Then
DrawLine( prices / Len( myInstruments ), "Average" );

#### Data Inputs Using Data Inputs in a Chart
With data inputs, you can access different quotation series or other data in the chart or portfolio. The only condition is that those series are available in the same chart or portfolio during runtime. For example, you can write an indicator displaying the spread between two time series without defining beforehand to which symbols the series belong. You simply start a chart with two symbols and then apply the indicator.

To recreate the indicator from above with data inputs instead of input instruments, create a chart with Puma AG and Adidas Salomon AG. Now enter a new indicator. The quotations are used as data inputs. The first quotation series is referred to as "Data1", the second as "Data2" etc. Since up to twelve symbols can be displayed in a chart, you can enter up to 12 data inputs.
//Generate subchart
Meta:
Subchart(true);

//Using the data input parameters for the spread
DrawCandleStick( Open of Data1 - Open of Data2,
High of Data1 - High of Data2,
Low of Data1 - Low of Data2,
Close of Data1 - Close of Data2,
white, red, black);

## Date and Time for Quotation Series

The information is delivered with the price data, online or in files. For correct display of quotations, date and time are necessary. This information is also often necessary for other functions, e.g. to recognize day change-overs or certain days of time.

### How a Chart is Drawn

The quotations are displayed linearly, from the first period (in the past) to the last. Usually, this is the current day or hour, depending on the time base of the chart. Within an Equilla script, the navigation is done with the consecutive number of the period (not the date or time). Therefore, if you want to use the close price of three days ago in your indicator, you need to write the script so that is goes three periods back in time.

The date cannot be used for this kind of navigation. You cannot retrieve data such as price or volume with a date. However, you can read the date and time of each period for other uses, for example the output of date and time of certain price levels in a chart.

### Which Data is offered by Tradesignal?

• Date - The date for the current period as numeric value: 1060609 ( this is the 09.06.2006 )
• Time - The time of the current period as numeric value: 1645 ( this is 16:45 )
• DateTime - A combined expression that is already formatted: 2006/07/05 17:25:00.000 ( this is the 05.07.2006 1725)
Extracting the data with code:
//Date of the current trading day in a daily chart
Variables:
myDate;

myDate = Date

//In the output window, the date for each trading day in the chart
//is displayed continuously.
Print( myDate );

//Time of the current period in an intraday chart
Variables:
myTime;

myTime= Time;

//In the output window, the time for each trading period in the chart
//is displayed continuously.
Print( myTime);

### Functions for Formatting and Working with Date and Time

Above, the three basic time series for date and time are given. These data can be read for every period and be used further. In the example above, the date and time were read and printed in the output window. However, it is often necessary to find out single components of the date, for example the day of week, the calendar month or the current year. You may also want to use the given date and time values in another format than the one offered by the system.

#### Functions for Splitting Date and Time

The following functions are not a complete list of all available functions. Only the most important ones are listed.

For returning date components, you can use the simple functions Year(date), Month (date) etc. When entering "now" for the date, the current date is used.

Instead of day, the function DayOfMonth can be used.

//Example: Write the components of the current date and time to the output window:
If IsLastBar Then
Begin
ClearDebug();
Print( "Year=" + CStr( Year( Now ) ) );
Print( "Month=" + CStr(Month( Now ) ) );
Print( "Day=" + CStr( Day( Now ) ) );
Print( "Hour=" + CStr( Hour( Now ) ) );
Print( "Minute=" + CStr( Minute( Now ) ) );
Print( "Second=" + CStr( Second( Now ) ) );
Print( "MilliSecond=" + CStr( MilliSecond( Now ) ) );
End;

To return parts of the DateTime, the function DatePart has to be used, defined as DatePart( DateInterval, DateTime ). For the definition of DateTime, see above.

The DateInterval is a numeric constant representing a certain part of the DateTime. It is always constructed with a leading Interval followed by a date or time expression.

IntervalTime
Interval_YearYear
Interval_MonthMonth of Year (1-12)
Interval_Day
Interval_DayOfMonth
Day of Month (1-31)
Day of Month (1-31)
Interval_DayOfWeekDay of Week (0-6)
Interval_DayOfYearDay of Year (1-365)
Interval_HourHours
Interval_MinuteMinutes
Interval_SecondsSeconds

//Example: Write a date or time part to the output window:

Input:
Interval( iYear, iMonth, iDay, iHour, iMinute, iSecond );

Variables:
name, part;

If Interval = iYear Then Begin
name = "Year";
part = Interval_Year;
End Else If Interval = iMonth Then Begin
name = "Month";
part = Interval_Month;
End Else If Interval = iDay Then Begin
name = "Day";
part = Interval_Day;
End Else If Interval = iHour Then Begin
name = "Hour";
part = Interval_Hour;
End Else If Interval = iMinute Then Begin
name = "Minute";
part = Interval_Minute;
End Else If Interval = iSecond Then Begin
name = "Second";
part = Interval_Second;
End;

Print( name + "=" + CStr( DatePart( part, DateTime ) ) );

#### Functions for Formatting Date and Time Data Recognize Monday Display the time in a chart
The basic date and time entries are dry figures. The DateTime component is also not formatted according to European standard. To allow you to generate various date and time formats, complex formatting functions are available. Two important ones are described here.

/* With the following function, you can format a date so that it includes the full name of the month. The function has the DateTime parameter as input. The formatting possibilities are quite unlimited. */

//No subchart; output in the main chart
Meta:
Subchart ( false );

//Declaring variables for date and day
Variables:
myDate, myDay;

//Reformatting the date, for example to
myDate = FormatDate ( DateTime, "dd/mm/yyyy");

myDay = DayOfWeek ( Date );

//Check if it is Monday - if yes, the text is
//output in the chart
if myDay = 1 Then
DrawText ( High + Range(), "Monday", "Monday," + mydate, 10, blue );

/* The following function is similar to the FormatDate function. It serves for formatting the time data in user-defined formats. It is recommended to take a look at the Equilla help for further information. */

//No subchart; output in the main chart
Meta:
Subchart( false) ;

//Declaring the variables for time and the formatted time
Variables:
myTime, myFormatTime;

myTime = Time;

//Here the time is reformatted with a separator
myFormatTime = FormatTime( DateTime, "hh:mm");

//At five past nine, a message is displayed in the chart
If Time = 0905 Then
DrawText ( High + Range(); "Good morning!", "It is " +myFormatTime,
10, blue);

//At one o'clock, it's time for the lunch break
If Time = 1300 Then
DrawText ( High + Range(); "Lunch time!", "Go and have something to eat, it is " +myFormatTime, 10, blue);

//At half past five, it's time for knocking off
If Time = 1730 Then
DrawText ( High + Range(); "Bye!", "Call it a day, it is " +myFormatTime,
10, blue);

## Information About Specific Periods and Bars Displaying continuous bar numbers
In Equilla Graphs, Outputs and Alerts you can find information on how the navigation in a chart can be controlled by an Equilla script. Reference values are used that can also be interpreted as step sizes. Much as in a game, where a figure makes 6 steps forwards or backwards, the program navigates through the time series.
//Reading the date of three days ago
myPrevDate = Date[ 3 ];

//Reading the close price of five days ago
myPrevClose = Close[ 5 ];

From each period in a chart, you have access to all other data and prices in the chart by going back or forward in the data. To do so, some useful functions are available in Tradesignal, which can be used with Equilla.
/* The parameter 'CurrentBar' gives the reference number of the current period The number is listed consecutively, as can be seen in the chart. */

//Output to be done in the main chart
Meta:
Subchart( false );

Variables:
myBarNum;

//The numeric value CurrentBar is converted into a string
myBarNum = CStr( CurrentBar );

DrawText( High + Range(), "Bar numbers", myBarNum, 10, blue);

For many applications it is important to execute a specific action at the very beginning or ending of a chart. For example, variables are often set at the first bar. Two important functions are offered by Tradesignal for this purpose.
• With the first function, you can read out how many bars (periods, candlesticks) are loaded in the chart.
• With the second function, a flag is set which is "true" when the last bar is reached.
//We set two variables at the first bar
Variables:
myEntryCondition, myExitCondition, myBarNums;

//We look for the first bar
If CurrentBar = 1 Then
Begin
myEntryCondition = false;
myExitCondition = false;
End;
/* We look for the last bar. This time we use the number of total bars in the chart which we get with the variable 'LastBar'. */

If CurrentBar = LastBar Then
Begin
myBarNums = LastBar;
Print ( myBarNums );
End;

//To find the last bar, you can also use the
//function 'IsLastBar' which is a boolean.

If isLastBar = True Then
Begin
myBarNums = LastBar;
Print ( myBarNums );
End;

Last not least it is often important to know the current time base of the indicator. For this, the constant "TimeBase" is available. With it you get the number of seconds spanned by each bar. With some mathematics, we can quickly find out if the indicator is in a day chart or one with a five minute span.

Variables:
outputString("");

If CurrentBar = 1 Then
Begin
//Checking for a day chart
if TimeBase = 86400 Then
outputString="d";
//Checking for a one hour time base
if TimeBase = 3600 Then
outputString="1h";
//Checking for a five minute time base
if TimeBase = 300 Then
outputString="5m";
//Checking for a one minute time base
if TimeBase = 60 Then
outputString="1m";
End;

//At the last bar, the output is written
//into the output window
If isLastBar Then
Print ( outputString );