Handling of Data, Times and Periods.

Part 4: With Equilla to Trading Success.

When programming trading strategies, time and calendar dates are important. No matter whether you want to use specific times of the day as a filter or track recurring patterns of the markets – Equilla permits implementation and testing of nearly any idea.

Table of Contents.

  • How to use time functions in Equilla
  • Practical Example: Open Range Breakout
  • Weekdays in Equilla: Turnaoround Tuesday
  • Flexible data handling: Inline Instruments
  • Practical Example: VDAX Trigger

NOTE: This paper was published in the German edition of the TRADERS’ magazine (issue 12/2014). All examples use data and security codes from Thomson Reuters Eikon.

Day Traders, Pay Attention!

How to use time functions in Equilla.

Day Traders, Pay Attention – How to use time functions in Equilla
For day traders, the use of hour and minute information is an essential tool for the development of trading strategies. Depending on the market and time of the day, there are, after all, large differences in trade volumes and volatility. Equilla offers a simple solution with the time function to define specific time information. The following applies:

Time = (hour * 100) + minute

Accordingly, 08:20 AM corresponds to 820 in Equilla. 9:40 PM (21:40 hours) is translated into 2140. The following code shows how the time function can be used to create a basic system in just a few lines that is aligned with times only for entry and exit.
The inputs defined are the time for the long entry and exit.


EnTime(​​ 1700​​ ),

ExTime(​​ 930​​ );

This is followed by the time-controlled entry and exit commands. In the specific case, the entry occurs at 5:00 PM, and exit on 09:30 AM of the following day.

If​​ Time​​ =​​ EnTime​​ Then Buy Next Bar​​ at​​ Market;

If​​ Time​​ =​​ ExTime​​ Then Sell Next Bar​​ at​​ Market;

This simple code tells the trader during the back test that, e.g., the DAX of the bull market of the last five years experienced a growth of about 5300 points between 5 PM and 9:30 AM. During the day, i.e. between 9:30 AM and 5 PM, the index gained about 1500 points per balance. This is an interesting insight that downright invites to conducting further research.


Figure 1 shows the capital curve of a trading system that takes a long position in the DAX every day at 5 PM and closes again the following day at 9:30 AM. The bottom shows the accumulated DAX gains between 9:30 AM and 5:00 PM.

Practical Example.


Let us now come to a trading strategy that should be known to many readers: the Open Range Breakout. The target is to trade the breakout from an individually specified period. The time function permits this classic approach to be tested for robustness quickly and precisely. The following code is only a simple framework, but shows how a small trick permits determination of the high and low of a specific time of the day and to use breakouts from this zone to develop positions. Additionally, the number of trades per day and direction is limited to avoid overtrading on sideways days.
Let us start with specifying all inputs. The opening automatically marks the start of the open range of the underlying market and does not require any input of its own. StartTime ends the opening phase and trading can commence. The input EndTime controls the exit at the end of the day to avoid overnight positions.


Price(​​ Close​​ ),

StartTime(​​ 1600​​ ),​​ 

EndTime(​​ 2130​​ );

The variables hh and ll are needed to specify the highs and lows of the opening range; the last two variables act as counters that permit limiting the number of trades.

Variables:​​ hh(​​ 0​​ ),​​ ll(​​ 0​​ ),​​ longTrade(​​ 0​​ ),​​ shortTrade(​​ 0​​ );

When a new trading day begins – this is what the query in the first line does – the high and low of the first candle are defined as the “high” and “low”.

If​​ Date​​ <>​​ Date[1]​​ Then​​ 


 hh​​ =​​ high;

 ll​​ =​​ low;

 longTrade​​ =​​ 0;

 shortTrade​​ =​​ 0;


After completion of the first intraday bar, the following loop starts, which is performed until the opening phase ends – in our case, this is at 4 PM. The target of this nested loop is to review each bar for which rate has the highest high and the lowest low of the opening phase so far.

If​​ Date​​ =​​ Date[1]​​ And​​ Time<=​​ StartTime​​ Then​​ 


 If​​ High​​ >​​ hh​​ Then​​ hh​​ =​​ High;

 If​​ Low​​ <​​ ll​​ Then​​ ll​​ =​​ Low;


Now the trading phase starts. First, the code checks if a long trade has already been performed or not. If this is not the case (longTrade=0), a stop buy order is placed at the high of the opening range. The low of the opening range serves as loss stop; the corresponding sales order is placed. This process is performed accordingly for the short side. If there is an entry on the long or short side, the corresponding counter (longTrade or shortTrade) is set to 1. In practice, this means that if a long trade has already been performed on that trading day, no further long trades are permitted anymore. The same applies to short trades.

If​​ Time​​ >=​​ StartTime​​ And​​ Time​​ <=​​ EndTime​​ Then​​ 


 If​​ longTrade​​ =​​ 0​​ Then Buy Next Bar​​ at​​ hh​​ Stop;

 Sell Next Bar​​ at​​ ll​​ Stop;

 If​​ shortTrade​​ =​​ 0​​ Then Short Next Bar​​ at​​ ll​​ Stop;

Cover Next Bar​​ at​​ hh​​ Stop;

 If MarketPosition​​ =​​ MarketPositionLong Then​​ longTrade​​ =​​ 1;

 If MarketPosition​​ =​​ MarketPositionShort Then​​ shortTrade​​ =​​ 1;


To tell the computer when the exit is to take place at the end of the day, the following condition must be defined at the end:

If​​ Time​​ >=​​ EndTime​​ Then


 Sell(​​ "End of Day Exit"​​ );

 Cover(​​ "End of Day Exit"​​ );


How Can Weekdays Be Back Tested?

Practical Example: TURNAROUND TUESDAY.

In addition to using times, Equilla can, of course, also use other data formats. For example, if you would like to use specific days within the trading system, use the function “dayofweek”. We will use a simple code as an example that performs long or short entries on Tuesdays, depending on whether the rate is below or above a simple moving average (SMA).

First, we define the required variables and inputs, as always:

Variables:​​ sma;

Inputs:​​ price(​​ close​​ ),​​ period(​​ 50,1​​ );


sma=average(​​ close,period );

The next step defines the condition for the short entry. “dayof week(date)=2” means Tuesday. If the market opens above the previous day’s SMA, a short position is taken:

If dayofweek(​​ date​​ )=2​​ and​​ open>sma[1]​​ 

then short this bar​​ at​​ open;

The condition for the long case is specified accordingly:

If dayofweek(date)=2​​ and​​ open<sma[1]

then buy this bar​​ at​​ open;

For the results of the Tuesday strategy to be properly reflected in the back test later, the exit condition at trading close is entered at the end of the code:

ExitPosition all shares this bar​​ at​​ close;

The date function permits flexible programming and evaluation of time- and calendar-based queries. At the same time, they can be used as a filter within a more complex trading system and thus contribute to improving performance.

Flexible Data Handling.


Finally, we would like to demonstrate with a simple example which opportunities Equilla offers for data handling. Traders can access any present data in the code using data inputs or inline instruments and use them to generate trading signals. Find a few examples for different data accesses below:

Data Input: The data series opened in the chart is used as source. If, for example, you want to draw the difference of one security (data1) and another (data2), the indicator is as follows:

DrawLine(​​ Close​​ of​​ Data1​​ -​​ Close​​ of​​ Data2​​ );

Inline-Instrument: The specific data are directly requested from the data provider here without the corresponding security having to be opened in the chart. The following code calculates a simple SMA for the time level currently chosen in the chart (note: the abbreviation .GDAXI means the DAX at Thomson Reuters).

DaxMA​​ =​​ AverageFC(​​ close,​​ 38​​ )​​ of​​ '.GDAXI';

The following example shows the code presented above with a small change. The addition “60m” and “d” uses the 60-minute and daily chart for calculation. This way, e.g. information from the daily or weekly chart can be used on an intraday basis and vice versa. No matter if Bollinger bands, channels or swing points – your imagination need have no limits here.

Meta:​​ subchart(​​ false​​ );


DrawLine(​​ AverageFC(​​ close​​ of​​ '.GDAXI 60m',​​ 200​​ ) );

DrawLine(​​ AverageFC(​​ close​​ of​​ '.GDAXI d',​​ 50​​ ) );


Practical Example.


Let us assume that a trader wants to use the VDAX (volatility index) and its rate of change (ROC) as the basis for entries in the DAX. First, the inputs for the VDAX and the associated ROC indicator are specified. The input “Bars” is needed later.


vdaxTrigger(​​ 40​​ ),

rocTrigger(​​ 50​​ ),

Bars(​​ 10,0​​ );



LongCondition(​​ false​​ );

The long entry is to take place when the VDAX drops below a specific level – the preset mark is 40 here. This is solved by direct referencing ‘.vdax’. Observe that the security ticker used here corresponds to the ticker of the respective data provider; otherwise, Equilla cannot access the data history. Due to the or-condition, a long trade is also possible if the final rate of the data series data2 exceeds the threshold “rocTrigger” that was declared as input. With function data2, Equilla accesses the second data series within a chart. In our case, this is the ROC of the VDAX. When replacing the ROC in the chart with a different indicator, the trading system instead accesses the new indicator.

LongCondition​​ =​​ '.vdax'​​ crosses below​​ vdaxTrigger​​ 

or​​ close​​ of​​ data2>rocTrigger;

If one of the two conditions is met, the system will go to the long position and place a stop buy order at the high (hhv) of the last three bars.

If​​ ( LongCondition )​​ Then buy​​ at​​ hhv(​​ high,3​​ )stop;

To verify with a back test how such VDAX panic signals have affected the DAX performance in the subsequent days, a simple exit function can be used. Once X days (adjustable via the input “bars”) have passed, the exit from the position takes place.

If BarsSinceEntry​​ =​​ Bars​​ Then​​ 

ExitPosition All Shares Next Bar​​ At​​ market;


The figure shows the VDAX and its change rate, as well as the DAX with all signals.


With Equilla to Trading Success.

With Equilla, Tradesignal offers a flexible and practical formula-based language with which dedicated traders and investors can test algorithmic trading and investment strategies in detail and then put them into practice. The compatibility with the wide-spread programming language EasyLanguage™ by TradeStation® permits exchange with many other traders and system developers and thus is a clear bonus. No matter if you need chart-technical patterns, indicator-based strategies, seasonal or entirely different approaches – with a little know-how, any trader can make his own algorithm.

For questions about Tradesignal we are always happy to help. If you are not yet a Tradesignal customer, we will gladly provide you with a trial version.

That’s it for today. Take care, take profit and auf Wiedersehen.


(Copyright notice: EasyLanguage™ is a registered trademark of TradeStation Technologies, Inc.)