Tradesignal How To 07.

DEVELOPMENT OF A SYSTEMATIC TRADING STRATEGY.

PART 2: WITH EQUILLA TO TRADING-SUCCESS.

Having looked at the most important basics and the setup of the source code in Equilla in the first part, we will now present the generation of a simple trading strategy. Here, we will deal with use of variables and conditional processes. Read how you can use the 200-day line as buy and sell signals with few lines and how to implement an ATR stop.

TABLE OF CONTENTS.

  • Variables – Data Containers
  • Conditional Processes
  • Step by Step to the First Trading Strategy
  • Implementation of a Stop
  • Results of the Back Test
  • Conclusion

 

NOTE: This paper was published in the German edition of the TRADERS’ magazine (issue 09/2014).

 

VARIABLES – DATA CONTAINERS.

Before starting with the generation of the trading strategy, we would like to introduce our readers to the function of variables.

They are what saves numbers, calculation results, user input or price values and makes them accessible for further processing and later use. Variables result by being declared in the script with the tag “Variables”.

IMPORTANT: Variables always only apply within the respective script because access to the variable is limited to that.

 

CONDITIONAL PROCESSES.

In addition to variables, conditional processes belong to the central elements of a trading strategy. They determine which reaction is to happen to specific events (e.g. calculation results, user input).

  • Simple operation (if… then…): IF condition THEN do a
  • Condition with branch (if… then… else…): IF condition THEN do a, ELSE do b

In addition to these two basic forms, conditions can also be nested, which will lead to several queries and instructions to be performed. Below, you will see how such nested conditions can look based on the buy and sell commands of the crossover trading strategy

 

STEP BY STEP TO THE FIRST TRADING STRATEGY.

With the pre-defined functions and indicators, Tradesignal users can write their individual trading strategy. In this instance, we would like to use the generally known crossover method as a basis for this kind of trading strategies.

Let us start with the header. This includes a brief description of the trading strategy to quickly recognise which approach is behind the strategy if there are many strategies.

Meta:

Synopsis​​ ("Dieses Handelssystem handelt Überschneidungen des Kurses mit der 200-Tage-Linie. Es kann sowohl long only, als auch als Long-Short-Variante genutzt werden. Der Initial Stopp basiert auf der ATR.");

Let us continue with the input area. Here, all user-specific parameters (inputs) as well as the variables just discussed are declared. Price(Close) determines that the moving average is calculated on base of the close price. The input Period(200,1) is used to enter the period number. The number 1 means that only integer changes of this parameter are permitted. To define bullish and bearish signals that can later be modified via the input mask of the software, use the inputs Bullish and Bearish.

Each of these inputs offers two options. For the input Bullish, the user can specify if he wants a long or a short entry. Accordingly, the input Bearish permits a long exit as well as a short entry. This option permits comfortably playing through all combinations in the later back test.

To have entry and exit signals displayed in the chart, we add Visuals as an input and set them to active by default so that the moving average is automatically displayed in the chart.

Inputs:​​ Price(Close),​​ 

Period(200,1),

Bullish(LongEntry,ShortExit)=​​ LongEntry,​​ 

Bearish(LongExit,ShortEntry)=​​ LongExit,

Visuals(Active,Inactive)=Active;

 

In the next step, we will come to the variables that are responsible for continuous calculation and storage of the values of the moving average in this script. The variable „avg“ already uses the function AverageFC presented in part 1, which calculates a simple moving average*. It uses the inputs Price and Period, which we have declared on the close basis of the last 200 trading periods. We also declare the variable „avtr“ as an ATR across 14 periods.

Variables:

avg,​​ avtr;​​ 

 

avg=AverageFC(Price,Period);​​ 

avtr=avgtruerange(14);

The following programme part contains the actual core of the trading strategy: Here, all commands that control opening or closing of a position are written down. Let us first have a look at the first part, which is responsible for the bullish signals:

If​​ Price​​ Crosses Over​​ avg​​ Then

 If​​ Bullish​​ =​​ LongEntry​​ Then

 Buy Next Bar​​ at​​ Market

 Else If​​ Bullish=ShortExit​​ Then

 Cover Next Bar​​ at​​ Market;

As you can see, the command structure is relatively simple to understand. If the underlying market closes above the 200-days line (crosses over avg), the following condition comes into play: if the input Bullish is set to LongEntry, the security is bought at market at the next trading period. If it is, in contrast, set to ShortExit, a present short position is closed (cover) – also at market at the next trading period. The same structure is now used for the bearish mode:

If​​ Price​​ Crosses Under​​ avg​​ Then

 If​​ Bearish=LongExit​​ Then

 Sell Next Bar​​ at​​ Market

 Else If​​ Bearish=ShortEntry​​ Then

 Short Next Bar​​ at​​ Market;

IMPLEMENTATION OF A STOP.

Finally, we want to implement a simple stop for loss limitation. Specifically, we want to use an ATR stop. The pre-installed functions make this easy:

SetStopContract;​​ 

SetStopLoss(LotSize*1*avtr[BarsSinceEntry]);

The code calculates the stop based on the lot size (LotSize), which is multiple with the simple Average True Range (avtr). The square brackets ensure that the ATR value is fixed at the time of entry. Lot size is the multiplier of the future per point, e.g. 25 for the DAX future. To define that the stop applies per future and not for the entire position, SetStopContract is added in the top line. The function BarsSinceEntry also easily permits integration of a time stop. The following applies to long positions:

If MarketPosition=1​​ and BarsSinceEntry​​ >=10​​ Then Sell next bar​​ at​​ low[BarsSinceEntry]​​ stop;

Here, the programme initially checks if the market holds a long position (marketposition=1) and if at least ten trading periods have passed since the entry. In this case, the position is closed once the market closes below the low of the entry candle. If the market is in a short position:

If MarketPosition=-1​​ and BarsSinceEntry​​ >=10​​ Then Cover next bar​​ at​​ high[BarsSinceEntry]​​ stop;

If you want to pull the stop after 50 trading period to entry price, the exit command would have to be as follows:

If MarketPosition=1​​ and BarsSinceEntry​​ >=50​​ Then Sell next bar​​ at​​ low[BarsSinceEntry]​​ stop;

If MarketPosition=-1​​ and BarsSinceEntry​​ >=50​​ Then Cover next bar​​ at​​ high[BarsSinceEntry]​​ stop;

Last, we would like the moving average and the stops to be displayed automatically in the chart. The two graphic functions DrawSymbol and DrawLine can put this into practice as follows.

If​​ Visuals=Active​​ Then begin​​ 

 DrawSymbol(GetActiveOrderPrice(1));​​ 

DrawLine(avg);

End;

 

The complete Equilla code is shown in figure 1

Meta:

Synopsis​​ ("This trading system trades with crosses of the price with the 200-day line. It may be used as long only, as well as in a long-short version. The initial stop is based on the ATR.");

 

Inputs:​​ Price(Close),​​ 

Period(200,1),

Bullish(LongEntry,ShortExit)=​​ LongEntry,​​ 

Bearish(LongExit,ShortEntry)=​​ LongExit,

Visuals(Active,Inactive)=Active;

 

Variables:

avg,​​ avtr;​​ 

 

avg=AverageFC(Price,Period);​​ 

avtr=avgtruerange(14);

 

If​​ Price​​ Crosses Over​​ avg​​ Then

 If​​ Bullish​​ =​​ LongEntry​​ Then

 Buy Next Bar​​ at​​ Market

 Else If​​ Bullish=ShortExit​​ Then

 Cover Next Bar​​ at​​ Market;

 

If​​ Price​​ Crosses Under​​ avg​​ Then

 If​​ Bearish=LongExit​​ Then

 Sell Next Bar​​ at​​ Market

 Else If​​ Bearish=ShortEntry​​ Then

 Short Next Bar​​ at​​ Market;

 

SetStopContract;​​ 

SetStopLoss(LotSize*1*avtr[BarsSinceEntry]);

​​ 

If MarketPosition=1​​ and BarsSinceEntry​​ >=50​​ Then Sell next bar​​ at​​ low[BarsSinceEntry]​​ stop;

If MarketPosition=-1​​ and BarsSinceEntry​​ >=50​​ Then Cover next bar​​ at​​ high[BarsSinceEntry]​​ stop;

 

If​​ Visuals=Active​​ Then begin​​ 

 DrawSymbol(GetActiveOrderPrice(1));​​ 

DrawLine(avg);

End;

FIGURE 1: EQUILLA CODE.

This Equilla code trades with crosses of price with the 200-days line and uses an initial stop on ATR basis.

 

RESULTS OF THE BACK TEST.

The trading system just presented can be used for our first practice test now. For this, we compile the Equilla Code and then just pull it into a chart of our choice, e.g. the DAX, by drag and drop.

Tradesignal visualises all entries and exits in the DAX chart as well as the corresponding progress of the equity curve. The inputs declared in the Equilla script can be easily modified via the tool bar; the results are visible in the chart immediately. You need only a few clicks to learn whether trading the short signals of the DAX would have paid off.

Changing the period length is also comfortably possible thanks to the inputs declared in the code.

FIGURE 2: APPLICATION OF THE TRADING STRATEGY TO THE DAX (LONG/SHORT VERSION).
All entry and exit signals and stops are visually marked in the chart. The curve below shows the historic progress of the equity curve. Source: Tradesignal

 

CONCLUSION.

With Tradesignal, traders can develop individual trading strategies and to put their own trading on a solid base without any great programming skills. With predefined functions, they can transfer their own ideas into a script and then check them thoroughly and optimise them.

Equilla provides many tools and modules for this that make the lives of strategy developers easier. For more on this, see the next part of our Equilla series.

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.