User Tools

Site Tools


single-page_reference






SystemTrader - User Guide
















Install

How to Download and Install SystemTrader

Step 1: Download SystemTrader

Click here to download SystemTrader.

It typically takes about one minute to download the 20 MB file on a DSL or cable connection.

Step 2: Install SystemTrader

Before installing, you may have a look at the system requirements.

If Safari is your web browser, Mac OS X will automatically open the installation disk image after the download. If however you are not running Safari or the disk image is not automatically opened, then double-click on the file once the download is finished.

From the disk image that was opened, drag the SystemTrader icon to where you want the software to be installed. If you want to install it in the Applications folder, then simply drag the SystemTrader icon onto the Applications icon.

Step 3: Launch SystemTrader

If this is the first time you launch SystemTrader, you need to connect to the Internet so that the software can check how much evaluation time you have.

Go to the Applications folder, and double-click on the SystemTrader icon.

A dialog appears. Click on Try It.

How to Purchase and Activate SystemTrader

Step 1: Purchase SystemTrader

Go to the purchase page.

Choose the version you want to purchase, and click on the corresponding Order button.

You are directed to an Avangate form. Avangate is the authorized vendor of SystemTrader and will handle your payment.

Fill the Billing Information form. Be sure to provide an accurate e-mail address. The actual payment is made on the next page: Confirmation and Payment.

Step 2: Wait for the Activation E-mail

Within a few minutes, you will receive a personal activation code at the e-mail address you provided.

Step 3: Activate SystemTrader

Launch SystemTrader (see download_and_install_systemtrader).

The evaluation dialog appears: click Activation. Copy and paste your activation key from the e-mail you received to the text box in the activation dialog.

Click Activate.

Step 4: Enjoy our Software or Get your Money Back

We hope you enjoy your experience with SystemTrader. If not, you are free to use the 30-day money back guarantee 1).


Stock Charts

How to Open a Stock Chart

Step 1: Select the Data Source

If the stock ticker has already been downloaded, skip to Step 3.

To download stock tickers, you must first select which data-source to use. Data-sources are found in the sidebar, under the TICKERS section. If you want to download tickers from Yahoo! Finance, then click on Yahoo! Finance - Stocks (US). If you prefer Google Finance, click on Google Finance - Stocks. MSN Money, Finam, InteractiveBrokers and international versions of Yahoo! Finance are available in the same way.

Step 2: Download the Stock Ticker

Choose File > Add a new ticker. A text control appears in the list-view: use it to enter the stock symbol2) and press ENTER. Finally, select the ticker in the pop-up menu.

Step 3: Open the Chart

In the list-view, double-click on the stock ticker to open its chart.

Alternatively, you can also select the ticker then press Command-O.

How to Navigate Inside a Stock Chart

Set the Level of Zoom

When you zoom in and out a chart, you change how much market time is displayed from its left side to its right side.

To change the level of zoom, click on the zoom-in and zoom-out icons in the toolbar, or drag a point in the time bar at the bottom of the chart. You can also use the zoom-box tool in the toolbar.

Select the Time-Frame

The time-frame is how much market time each bar or candlestick represents. For example, in a “1 week” chart, bars display the open, high, low and close prices of each week. Setting a lower time-frame allows you to get a more accurate picture of price changes.

To set the time-frame, use the time-frame choice in the chart toolbar.

Browse Market Data

To move the period of time displayed, use the horizontal scroll-bar at the bottom, or drag any point inside the chart.

How to Add Technical Market Indicators to a Stock Chart

Step 1: Select an Indicator

Click Add Indicator then use the pop-up menu to select the indicator you want to add.

Step 2: Customize its Appearance and Parameters

In the Indicator Parameters dialog3), choose the style and color of the indicator.

In the same dialog, use the Parameters box to set the parameters of the technical indicator.

Close the dialog to finish.

How to Use the Drawing Tools

Step 1: Select the tool

Click Draw in the toolbar and select the drawing tool you want to use.

Step 2: Draw

Click on different points inside the chart to draw the shape.

How to Further Customize a Stock Chart

Colors

To customize the chart colors (background, bars, etc.), click on the color icon in the toolbar.

Bar Style

To change the style of market bars, use the corresponding choice in the toolbar:

  • Close: Curve of the close prices
  • High-Low: Curves of the high and low prices
  • HLC: Bars with High, Low and Close prices
  • Colored HLC: Bars with High, Low and Close prices, colored when the price is down
  • HLOC: Bars with High, Low, Open and Close prices
  • Candlesticks: Japanese Candlesticks

Frames

Frames are independent displays within a chart. One main price frame is generally used in conjunction with a volume frame, and additional frames for oscillators.

To add a frame, click Add New Frame, and select its kind:

  • Price: To display prices and technical indicators
  • Volume: To display volumes
  • Oscillators: To display stock market oscillators

How to Create and Use a Chart Template

Step 1: Create the New Chart Template

In the sidebar, click CHART TEMPLATES.

Choose File > Add a new chart template.

Give a name to the new template, then press ENTER.

Step 2: Customize the Chart Template

Customize the chart template like you would customize any chart, then save it.

Step 3: Apply the Template to a Ticker

Open the chart of a stock ticker.

In the Chart > Load template menu, choose the chart template you want to load.

Note: The Default Template

The chart template named “Default” is automatically applied to stock charts opened for the first time.

You can customize it like any other template.

How to Create and Display a New Technical Indicator

Step 1: Create a New Indicator File

Choose File > Create new > Indicator.

Give a name to the indicator, then press ENTER.

Step 2: Write the Indicator Code

A window is automatically opened: you can use it to edit the code of the indicator. For example, you can enter the following:

return (High + Low) / 2

To learn how to create indicators using the TSL language, please refer to:

Step 3: Add the Indicator to a Chart

Open a stock chart.

Click Add Indicator. Inside Custom indicators in the pop-up menu, select the indicator.


Stock Tickers

How to Browse Available Tickers

With SystemTrader, thousands of stock tickers and their charts are just a few click away.

Be sure to be connected to the Internet before trying to browse tickers.

Step 1: Expand the Data-Source

The following sources allow the browsing of tickers:

  • Google Finance
  • MSN Money
  • Yahoo! Finance
  • Pi Trading

These can be found in the sidebar, under TICKERS. Expand a data-source by clicking on the disclosure triangle on its left.

Step 2: Expand the Source Folders

Folders within data-sources allow you to browse available tickers. Click on their disclosure triangles to download and access sub-folders.

Go deeper within these folders until a dialog appears and automatically downloads stock tickers.

Step 3: Scroll

Once the tickers are downloaded, they appear in the list-view. Use the vertical scroll-bar to browse all the tickers inside this folder.

How to Download a Specific Stock Ticker

Step 1: Select the Data Source

To download a stock ticker, you must first select which data-source to use.

The following sources are available:

  • Google Finance
  • MSN Money
  • Yahoo! Finance
  • Finam Forex
  • Pi Trading
  • InteractiveBrokers (SystemTrader Intraday only)

These can be found in the sidebar, under TICKERS. Click on the data-source you want to use.

Step 2: Download the Stock Ticker

Choose File > Add a new ticker. A text control appears in the list-view: use it to enter the stock symbol4) and press ENTER. Select the ticker in the pop-up menu.

The stock ticker is downloaded within a few seconds and appears in the list-view.

How to Download a Whole Source Folder

SystemTrader allows you to download at once all the sub-folders and stock tickers contained in any source folder (except for data-sources themselves, which contain too much data to be downloaded at once).

Step 1: Select the Folder

In the sidebar, select the folder you want to download in whole5).

Step 2: Launch the Download

Choose Tickers > Download whole folder.

Depending on your connection and the size of the folder, the download may take from a few seconds to several hours. You can stop it at anytime with the Cancel button. Since downloading sub-folders is a lot slower than downloading stock tickers, the pace of the download accelerates substantially once all the folders are downloaded6).

How to Edit a Stock's Historical Prices

SystemTrader allows you to edit the historical prices and trading volumes of any stock ticker.

Step 1: Select the Stock

In the list-view, click on the stock ticker you want to edit.

Step 2: Open the Historical Data Editor

Choose Tickers > Edit historical data. The Edit Ticker dialog appears.

Step 3: Edit the Data

Click on the cell you want to edit, then click on it again to open the editor. Enter a new value then press ENTER.

You can also process a stock-split by clicking Add Split.

Step 4: Save

Click Save to save the new prices and volumes.

How to Connect To Interactive Brokers Real-time Data

To connect to Interactive Brokers you need both SystemTrader Intraday and an account at Interactive Brokers.

Step 1: Install and Launch IB TWS

The IB Trader Workstation (TWS) is needed to get data from Interactive Brokers. Download the latest stand-alone or browser-based version here.

Launch IB TWS and keep it running during the following steps.

Step 2: Allow SystemTrader to Connect to Interactive Brokers

Open the main window of IB TWS. Check Configure > API > Enable ActiveX and Socket Clients.

You should be able to skip this step next time you want to connect to IB.

Step 3: Create a Stock Ticker

Open SystemTrader. In the sidebar, under TICKERS, click on Interactive Brokers.

Choose File > Add a new ticker. A text control appears in the list-view: use it to enter a stock symbol7) and press ENTER. Select the ticker in the pop-up menu.

Step 4: Accept the Connection

At this point, a dialog from IB TWS asking “Accept incoming connection attempt?” should appear. Click Yes to accept the connection with IB.

The real-time prices and volumes of the stock appears in the list-view.

Step 5: Open the Realtime Intraday Chart

Double-click on the stock ticker to open its chart.

In the chart toolbar, select 1 minute as the timeframe.


Watchlists

How to Create a New Watchlist

Step 1: Create and Name the Watchlist

In the sidebar, under WATCHLISTS, click Create new watchlist….

Give a name to the new watchlist then press ENTER.

Step 2: Add Tickers

Choose File > Add a new ticker. A text control appears in the list view: use it to enter the stock symbol8) and press ENTER.

A pop-up menu appears. If the ticker is already downloaded, select it directly in the top part of this menu. Otherwise, use the Download sub-menu to choose the data-source you want to download the ticker from.

Repeat this step for other tickers.

How to Customize a Watchlist

Add a Column

Control-click (or right-click) on the column header in the list-view.

In the Insert column > Properties menu, choose the column you want to add.

Some data-sources allow you to download and display fundamental data. To add a fundamental data column, use Insert column > Fundamentals.

In the same way, you can add built-in or custom indicator values with Insert column > Indicator.

Remove columns

Control-click (or right-click) on the column header you want to remove, then click Remove.

Move and resize columns

To change the order of columns, drag their headers with the mouse.

To change the size of a column, drag the right-side border of its header.

Sort Stocks According to a Column

Single-click on a column header to sort stocks according to this column. Single-click a second time to reverse the order.

How to Open a Watchlist in a Separate Window

In the sidebar, under WATCHLISTS9), double-click on the watchlist you want to open in a separate window.

Alternatively, you can also select the watchlist then press Command-O.

How to Create a Sub-Watchlist

A sub-watchlist is a watchlist within a watchlist with the same configuration10) but containing only a subset of the stock tickers.

Step 1: Create Two New Watchlists

Follow the instructions in Create a New Watchlist to create two new watchlists.

Step 2: Cut

Select the watchlist you want to use as a sub-watchlist.

Choose Edit > Cut.

Step 3: Paste

Select the watchlist you want to use as a parent watchlist.

Choose Edit > Paste.

How to Create a Watchlist from a Source Folder

Watchlists and source folders have different purposes. Source folders are primarily designed to browse and download data while watchlists are designed, as the name says, to “watch” stock tickers.

Although you can use a source folder the way you would use a watchlist, source folders are sometimes less flexible. For example, it is not possible to add or remove sub-folders inside a source folder.

Follow this tutorial to get the flexibility of a watchlist for the data of a source-folder.

Step 1: Create a New Watchlist

In the sidebar, under WATCHLISTS, click Create new watchlist….

Give a name to the new watchlist then press ENTER.

Step 2: Copy

In the sidebar, under the TICKERS section, select the source-folder you want to use as a watchlist.

Choose Edit > Copy.

Step 3: Paste

In the sidebar, select the watchlist you created in Step 1.

Choose Edit > Paste.


Stock Screener

How to Screen Stocks Using the Screener Assistant

The stock screener allows you to filter stocks according to custom conditions. It is available in every watchlist and source folder.

Step 1: Select the Watchlist to Screen

In the sidebar, select the watchlist or source folder in which you want to screen stocks11).

Step 2: Open the Screener Assistant

At the bottom of the list-view, on the right side of Filter when:, click on the drop-down button.

A menu appears: click Assistant….

Step 3: Create the Screening Condition

A screening condition is made of one or more comparisons. To enable an additional comparison, single click on the corresponding AND: checkbox on its left.

Use the drop-down menus to select the left and right operands of each comparison, then choose the appropriate comparison operators.

Click OK to finish and create the screening condition.

Step 4: Launch the Stock Screening

Check the Filter when: check-box.

Any needed ticker data is automatically downloaded, then the screening is performed.

How to Screen Stocks Using a Pre-Built Condition

Step 1: Select the Watchlist to Screen

In the sidebar, select the watchlist or source-folder in which you want to screen stocks12).

Step 2: Select the Pre-Built Condition

At the bottom of the list-view, on the right side of Filter when:, click on the drop-down button.

A pop-up menu appears. In the Condition sub-menu, select a pre-built condition.

A small dialog appears: use it to set the parameters of the condition you selected.

Step 3: Launch the Stock Screening

Check the Filter when: check-box.

Any needed ticker data is automatically downloaded, then the screening is performed.

How to Sort Stocks According to Specific Ticker Data

To sort stocks according to their value in a specific column, single-click on the column header.

For other sorting criterions, use the Sort by: control at the bottom of the list-view.

Step 1: Select the Watchlist to Sort

In the sidebar, select the watchlist or source-folder in which you want to sort stocks.

Step 2: Select the Sorting Criterion

At the bottom of the list-view, on the right side of Sort by:, click on the drop-down button.

A pop-up menu appears. Use the Price or Fundamentals sub-menu to select the sorting data, or click on Operation… for a more complex criterion.

Step 3: Launch the Stock Sorting

Check the Sort by: check-box.

Any needed ticker data is automatically downloaded, then the sorting is performed.

How to Sort Stocks According to a Pre-Built Indicator

Step 1: Select the Watchlist to Sort

In the sidebar, single-click on the watchlist or source-folder in which you want to sort stocks.

Step 2: Select the Pre-Built Condition

At the bottom of the list-view, on the right side of Sort by:, click on the drop-down button.

A pop-up menu appears. In the Indicator sub-menu, select a pre-built indicator.

A small dialog appears: use it to set the parameters of the indicator you selected.

Step 3: Launch the Stock Sorting

Check the Sort by: check-box.

Any needed ticker data is automatically downloaded, then the sorting is performed.


Portfolio Tracking

How to Create a New Portfolio of Stocks

Most portfolio trackers are position-based. SystemTrader's portfolio tracker is trade-based, which means you must enter separately the entry and exit trades of each position.

Entering each trade may take more time initially but it allows SystemTrader to compute more advanced statistics about the performance of your portfolio and curves showing how this performance evolves over time.

Step 1: Create and Name the Portfolio

In the sidebar, under PORTFOLIOS, click Create new portfolio….

Give a name to the new portfolio then press ENTER.

Step 2: Set your Account Parameters

At the bottom of the list-view, use the controls to set:

  1. The initial equity of your stock trading account
  2. The main currency of your account
  3. The default trade commission of your broker

Step 3: Enter Trades & Dividends

In the list-view, click on [ Click here to add a new trade… ].

For each trade made from your stock trading account (and each dividend received), enter:

  1. Symbol: The stock symbol 13)
  2. Entry time: The date of the trade or dividend
  3. Type: The direction of the trade, Buy or Sell (or Dividend if appropriate)
  4. Shares: The number of shares
  5. Filled: The fill price of the trade (or dividend per share)
  6. Commission: The corresponding commission amount (or dividend tax)
  7. Currency rate: The currency rate if the stock is priced in a foreign currency 14).
  8. Note: A personal note about this particular trade or dividend (optional)

Step 4: Enter Other Profits, Losses and Transactions

SystemTrader will automatically compute your profits and losses from trades, trade commissions and dividends. However, you may want to enter additional expenses, incomes, or transactions.

In the Portfolio > Add a new transaction menu, choose the type of transaction you want to take into account:

  1. Deposit: Cash you added to your account (counted as neither a profit nor a loss).
  2. Withdrawal: Cash you took out of your account (counted as neither a profit nor a loss).
  3. Interest Received: Interests paid to you (counted as a profit).
  4. Interest Paid: Interests paid to your broker (counted as a loss).
  5. Broker Fee: Broker fees, excluding trade commissions (counted as a loss).
  6. Tax: Miscellaneous taxes on your stock portfolio (counted as a loss).
  7. Other Profit: Profits that cannot be computed otherwise by SystemTrader.
  8. Other Loss: Losses that cannot be computed otherwise by SystemTrader.

For each profit, loss or transaction, enter:

  1. Entry time: The time of the transaction.
  2. Filled: The amount of money involved.
  3. Currency rate: The currency rate if the transaction happened in a foreign currency.
  4. Note: A personal note about this particular transaction (optional)

How to Browse Portfolio Performances

In the sidebar, under PORTFOLIOS, expand the portfolio item.15)

Click on sub-items to browse performance statistics:

  • Performance sheets: the current performance of the portfolio.
  • Performance curves: the evolution of the portfolio performance over time.16)
  • Positions (current): individual performance of each position in your current portfolio.
  • Positions (closed): performance of each closed positions.

Backtest

How to Create a New Trading System

Step 1: Create a Trading System

Choose File > Create new > Trading system.

Give a name to the trading system then press ENTER.

Step 2: Define the Condition of Market Entry

The Trading System Building Assistant is opened automatically.

Click Next to go to Condition of market entry.

The entry condition is made of one or more comparisons. To enable an additional comparison, check the corresponding AND: checkbox on its left.

For each comparison, use the drop-down menus to select the left and right operands, then choose the appropriate condition operator.

Step 3: Set the Entry Order

Click Next to go to Entry order.

Choose the type of entry order:

  • Buy at market to enter a long position
  • Sell short at market to enter a short position

Click Next to go to Parameters of entry order.

You can set four parameters:

  • Position size: the number of shares to buy or sell.
  • Stop-loss: the loss level at which to automatically exit the position.
  • Trailing stop: the draw-down level at which to automatically exit the position.
  • Take-profit: the profit level at which to automatically exit the position.

Only set these parameters now if you are sure of their values, and you do not want to experiment with them. Otherwise, skip the step and click Next - you will later be able to set these parameters in the Backtest Assistant.

Step 4: Define the Condition of Market Exit

Define the condition of market exit like you did for market entry.

Click Finish.

Step 5: Customize the system with TSL

Once you are finished with the Trading System Building Assistant, the code of your trading system appears in a new window. You can either use it as-is in a backtest, or further edit it to create more complex rules using the TSL Language and its special features for trading systems.

How to Backtest a Trading System

Step 1: Open the Backtest Assistant

In the sidebar, under BACKTESTS, click Create new backtest….

Step 2: Select the Trading System to Backtest

Click Next to go to Trading system selection.

In the left part, select the trading system to backtest.

Step 3: Set the Parameters

Click Next to go to Parameters of trading system and virtual account.

You can set the following trading system parameters:

  • PositionSize: the default number of shares to buy or sell.
  • StopLoss: the default loss level at which to automatically exit the position.
  • TrailingStop: the default draw-down level at which to automatically exit the position.
  • TakeProfit: the default profit level at which to automatically exit the position.
  • MostSimultaneousPositions: the maximum number of positions that can be opened at any time.

You can set the following account parameters:

  • Initial Equity: the equity at the start of the backtest.
  • Maximum leverage: the leverage the trading system can use to enter positions.
  • Margin requirements (%): the level at which a margin call will be sent.17)
  • Commission: the fixed commission for each trade, in currency units.
  • Commission (%): the commission for each trade, in % of amount invested.

Step 4: Select the Historical Data

Click Next to go to Historical data selection.

The sidebar on the left, and the list-view in the middle allow you to browse stock tickers. To use tickers for the backtest, you can either drag them individually onto the right part of the page, or use the Add All button.

Use the date controls at the bottom to set the date of start and end of the backtest.

Step 5: Launch the backtest

Click Launch Simulation.

If additional ticker data is needed, it is downloaded automatically. Then the backtest is performed.

How to Browse Trading System Performances

In the sidebar, under BACKTESTS, expand the backtest item.18)

Click on sub-items to browse backtest results:

  • Performance sheets: the performance of the trading system during the whole backtest.
  • Performance curves: the evolution of the trading system performance over time.19)
  • Positions (current): individual performance of positions not closed at the end of the backtest.
  • Positions (closed): performance of positions closed before the end of the backtest.
  • Orders (executed): summary of orders executed during the backtest.
  • Orders (open): summary of orders not yet executed at the end of the backtest.
  • Tickers: tickers used during the backtest.
  • Console: text output of scripts.20)
  • Parameters: parameters of the backtest.

Trading System Language (TSL)

Learning the Basic Features of the TSL Language

The TSL language is based on Python, which is renowned for its clear syntax and simplicity. Every feature of Python can be used from TSL, but the language also provides new keywords and functionalities to make building trading systems and technical indicators easy.

To understand the TSL language, you do not need to be a seasoned programmer but you must learn some of the basics of Python.

Experiment with Python

SystemTrader provides you with a Python (and TSL) Interpreter. In the sidebar, under UTILITIES, click TSL Interpreter. This allows you to experiment with Python. Try for example:

>>> a = 3
>>> a + a
6
>>> a * 5
15

You only need to understand a small subset of Python, which is mostly covered in the two following tutorials:

If you want to learn about more advanced features, you can always refer to the Python Documentation.

Experiment with Technical Indicators

Every built-in indicator in SystemTrader is provided with its full TSL code.

In the sidebar, click SYSTEMS & INDICATORS, then double-click on any indicator to see its TSL code. You can re-use this code to make your own indicators.21)

Once you are familiar with the basics, learn more about special_tsl_features_for_technical_indicators22).

Special TSL Features for Technical Indicators

This tutorial assumes you are already familiar with the basics of the TSL language.

Most of the features described here are also useful to make trading systems.

How Indicators Work

Here is the code of the SMA (Simple Moving Average) indicator:

SMA
""" Simple Moving Average """
 
return average(Price)

Let's look at each part individually.

""" Simple Moving Average """
The text inside the quotes appears in the the Description column of the list-view when you browse indicators.
average(Price)
This computes the average of the current Price data.
return 
The return keyword sends the value to be displayed in charts or to be used in the stock screener.

A TSL indicator is automatically translated to a Python function similar to the following:

def SMA_Fun():
    """ Simple Moving Average """
 
    return average(Price)

This function is called every-time the value of the indicator is needed, for different stock tickers and different dates23). For example, the moving average curve in a stock chart is made of the return values of SMA at every bar.

Price and Volume Data

In any indicator, price and volume data can be accessed with the [] operator. Here is an example:

Val = Close[0]

Close[0] means: the last (or “close”) price of the current time period (of today in an EOD chart).

Close[1] would mean the last price of the time period before (of yesterday in an EOD chart), and so on.

Here are the price and volume data which can be used in a similar way:

Name Data returned
Open The first price of the time period.
High The highest price of the time period.
Low The lowest price of the time period.
Close The last price of the time period.
Volume The volume of transaction during the whole time period.

Times and Dates

Like with price and volume data, you can access information about time:

Name Sample value Data returned
Date 20100812 The date of the time period.
DateYear 2010 The year of the time period.
DateMonth 8 The month of the time period (from 1 to 12).
DateDay 12 The day of the time period (from 1 to 31).
WeekDay 3 The day of the week (from 0: monday to 6:sunday).
Time 2010\08\12 - 0:00:00 The date and hour of the time period.

Periods

There is not a unique moving average used in all contexts. Depending on the situation, you may use a SMA(14), a SMA(21), a SMA(200) or other variants that you see fit. What changes is the number of time-periods covered by the indicator.

In TSL, this number is stored in the Periods variable. For example, the following indicators return the same value:

return average(Price)
return average(Price[i] for i in range(Periods))

The Periods variable may be needed, for example, when computing an average.

return sum(Price) / Periods

The First variable is always equal to Period minus 1. It makes it easy to access data at one extremity of the period covered by an indicator.

return (Close[First] + Close[0]) / 2

Price keyword

The moving average is generally computed based on close prices. Nonetheless, it is sometimes useful to apply it to other data like the highest prices, the open prices, or even technical indicators.

SMA
return average(Price)

By default, Price behaves just like Close. However, it is possible to replace it with any other data.

return SMA(14, Price=High)

The code above returns the average of the last 14 highest prices.

Parameters

The param keyword enables the use of parameters that can be changed later, for example when an indicator is added to a chart.

FastStoD
""" Fast %D """
 
param(FastD = 3)
 
return average(FastStoK[0:FastD])

The call to param will not be included in the final translated function. Instead, once parameters are set from SystemTrader's GUI, their names are textually replaced by their values.

def FastStoD_Fun():
    """ Fast %D """
 
    return average(FastStoK[0:3])

Saving Data Across Iterations

Indicator values in a stock chart are always computed from left to right. The Init value allows you to know when the first call (at the left extremity) is taking place.

The value is typically used in conjunction with the Save object, in order to pre-compute values or to make the indicator “recursive”, like in the Exponential Moving Average.

EMA
""" Exponential Moving Average (EMA) """
 
param(Smoothing = 2.0)
 
if Init:
	Save.LastEMA = average(Price)
	Save.K = Smoothing / (Periods + 1)
 
Save.LastEMA = Save.K * Price[0] + (1-Save.K) * Save.LastEMA
return Save.LastEMA

Special TSL Features for Trading Systems

How Trading Systems Work

Here is the Price/SMA cross-over trading system. It buys shares when the price crosses the Simple Moving Average (SMA) on the up side, and sells these shares when the same cross happens on the down side.

SMACrossOver
"""
Price/SMA cross-over system
 
Parameters:
- Period: period of the moving average
"""
 
param(Period = 40)
 
if Position.IsFlat:
    if crossOver(Price, SMA(Period)):
        enterLong()
else:
    if crossBelow(Price, SMA(Period)):
        Position.exit()

While this trading system will most certainly not make you rich, it shows the basic structure and what such a system should define: when to enter, and when to exit a position.

The calls to enterLong and Position.exit send buy and sell orders. These orders are then handled by the backtester to simulate the performance of the system on a virtual trading account.

Entry Orders

Entry orders allow you to buy or sell shares when the market conditions match the rules of your trading system. To send an entry order, call one of the following functions:

Order Function
enterLong Buy shares to enter a long position.
enterShort Sell shares to enter a short position.
enterLongAtLimit Enter long position at limit parameter.
enterShortAtLimit Enter short position at limit parameter.

Entry orders only have an effect when no position is opened on the current stock ticker. If a position is already opened, then the call does nothing24).

When you call an entry order, you can set the corresponding limit, stop-loss, take-profit, trailing stop-loss and position size of the trade. Use the following parameters:

Parameter Sample Values Function
PositionSize 20
'1000.00$'
'2.00%'
Number of shares to buy or sell.
StopLoss '2.00'
'5.00%'
'200.00$'
Loss level at which to automatically exit the position.
TrailingStop Draw-down level at which to automatically exit the position.
TakeProfit Profit level at which to automatically exit the position.
Limit Parameter 25) Close[0]-2.0 Limit level at which to automatically enter the position (only for enterLongAtLimit and enterShortAtLimit).

Here is a sample entry order that makes use of all these parameters:

enterLongAtLimit(Close[0]-2.0, PositionSize=20, StopLoss='5.00%', TrailingStop='10.00%', TakeProfit='10.00%')

The limit price is the only mandatory parameter. This is why it does not need a keyword like PositionSize or TakeProfit.

Exit Orders

To close a position, call Position.exit.

Position.exit()

If the position is long, then all the shares are sold at the current market price. If the position is short, the shares are bought back.

Position Properties

The Position object contains information about the current position.

if Position.IsFlat:
    if crossOver(Price, SMA(Period)):
        enterLong()

The following position properties are available:

Attribute Function
IsFlat Equals 1 when there is no position on the current ticker.
IsShort Equals 1 when there is a short position on the current ticker.
IsLong Equals 1 when there is a long position on the current ticker.
Direction -1 when short; 0 when flat; 1 when long.
TickerId Identifier of the current stock ticker.
NumShares Number of shares.
Commission Total broker fees paid since the position was opened.
EntryPrice Share price at entry.
AverageEntryPrice Average entry price - useful when there are multiples entries.
AverageEntryValue Average entry price multiplied by number of shares.
LastPrice Last market price.
MarketValue Last market value.
StopLoss Stop-loss price.
TakeProfit Take-profit price.
TimeLength Time since entry

Performances properties are also available:

RawTotalPL Total profit or loss, in currency units.
NetTotalPL Total profit or loss, net of commissions.
UnrealizedPL Unrealized P/L, in currency units.
RawRealizedPL Realized P/L, in currency units.
PriceGain Change of price: positive number when favorable / negative when unfavorable.
PriceMFE Max favorable price excursion.
PriceMAE Max adverse price excursion.
ValueMFE Max favorable value excursion.
ValueMAE Max adverse value excursion.
PctMFE Max favorable percentage excursion.
PctMAE Max adverse percentage excursion.
PctChange Percentage change between entry price and last price.

Position Changes

You can change the size of a position with Position.setNumShares.

Position.setNumShares(Position.NumShares * 2)

The code above generates a buy or sell order which will double the current position.

In the same way, the following methods allow you to modify a position:

Method Function
setNumShares Create a market buy or sell order to reach the new number of shares.
setStopLoss Set a new stop-loss for the current position.
setTakeProfit Set a new take-profit for the current position.

Account Performances

The Account object contains information about the current performance of the virtual trading account.

Val = Account.Cash

The following performance properties are available:

Attribute Function
Cash Equity not invested.
NetProfit Profit or loss since the start of the backtest.
Equity Current equity.
InitialEquity Equity at the start of the backtest.
PeakEquity Highest equity since the start of the backtest.
LowestEquity Lowest equity since the start of the backtest.
Drawdown Current draw-down.
Runnup Current run-up.
PctDrawdown Current draw-down as percentage of equity.
PctRunnup Current run-up as percentage of equity.

Console Output

The print function displays information in the backtest console26):

if Position.IsFlat:
    if crossOver(Price, SMA(Period)):
        print("Entering long position on", Date[0], "at price", Price[0])
        enterLong()
else:
    if crossBelow(Price, SMA(Period)):
        print("Exiting position on", Date[0], "at price", Price[0])
        Position.exit()
1) Simply send us an e-mail saying you want your money back within 30 days of the purchase date.
2) , 4) , 7) For example: AAPL.
3) Opened automatically when you add an indicator.
5) For example, click on TICKERSYahoo! Finance - Stocks (US)Per IndexUSNASDAQNASDAQ-100.
6) The first few tickers may also download slowly.
8) For example: GOOG.
9) Or under TICKERS for source folders.
10) That is, with the same columns and stock screener configuration as the parent watchlist.
11) It should preferably contain at least a few dozens of stock tickers.
12) The watchlist should preferably contain at least a few dozens of stock tickers.
13) Then select the appropriate ticker in the pop-up menu.
14) This should be equal to the (Trade Currency)/(Account Currency) rate at the time of the trade. For example, if the trade was made on Euronext from a US account, the rate of the EUR/USD currency pair would be used.
15) Click on the disclosure triangle on the left of the portfolio name.
16) , 19) Double-click on the Performance curves item to open all the curves at once.
17) This parameter is divided by Maximum leverage: if the value is 50% and the Maximum leverage is 4, the actual requirement is 12.5%.
18) Click on the disclosure triangle on the left of the backtest label.
20) Using the print function.
22) Which is itself a prerequisite to Special TSL Features for Trading Systems.
23) Or different times in intraday charts.
24) Also, these orders have no effect when the number of opened positions is already equal to the MostSimultaneousPositions parameter, as set in the backtest assistant.
25) The limit parameter is always the first argument in calls to enterLongAtLimit and enterShortAtLimit.
26) To access the console output after the backtest, click on Console under the backtest item in the sidebar.
single-page_reference.txt · Last modified: 2014/08/02 06:37 by admin