Welcome Guest, you are in: Login
CTS Futures
Home
Pricing
Market Data
FAQ
Videos

T4 Desktop
User Guide
Scripting Guide
Release Notes

Mobile and Web
T4 Mobile for Android
T4 Mobile for iOS
T4 Mobile for Browser
T4 WebTrader

Admins
T4 Admin Guide
MiFID II/MiFIR

Developers
API 4.7 Guide
FIX API


Page History: Scripting Overview

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2011/07/22 16:30



Code Structure

Scripting code consists of one or more statements that are executed by the script interpreter.

Individual statements are separated by semicolons. White spaces (spaces, tabs, carriage returns, etc.) have no effect on how scripts are interpreted. Scripts are case-insensitive (e.g. sma is the same as SMA).

Statements can do the following:

  • Perform a calculation.
  • Assign a value or calculation to a variable name.
  • Accept user input into a variable.
  • Plot values on a chart in various different formats.
  • Configure the chart.

Lets take a look at a script that computes the Disparity Index indicator:

VSCALE_DECIMALS(2);

periods = INPUT("MA Periods", 14, 1, 100);
indcolor = INPUT("Color", Color.Blue);

ma = SMA(CLOSE, periods);
di = 100 * ((CLOSE - ma) / ma);

PLOT_HISTOGRAM(di, 0.75, indcolor);
SUMMARY("Disparity Index({?}) {?:F2}", periods, di);

The first line, VSCALE_DECIMALS(2);, is a chart configuration command that states that we want numbers on the indicator value scale to display out to two decimal places.

Next, we accept some user input for the number of moving average periods and the color to draw the indicator. These values are stored in variable names (periods and indcolor) for later use in the script.

The indicator values are calculated next. This is done in two steps to make it easier to read and also to improve efficiency of the script. A simple moving average of the closing price is first computed and stored in variable ma. As you can see, we feed the user configurable number periods into the SMA function. This allows for the periods to be adjusted through the chart properties window without having to open and modify the script every time. Finally, we compute the disparity index as a percentage and store it in variable di. This is simply a computation of the percent difference of the current closing price to the moving average and the syntax was designed to be as intuitive as possible.

The last thing done by the script is to plot the values and display a summary.

This script produces the following output:

Image





Assign Values to Variables

Compute SMA 3 Different Ways

Plot Lines, Histograms, Wavecrests, Bands, Points

Plot Limit Lines, Center Lines and Range Markers

Display a Customized Summary

Format Tick Prices for Display

Change Plot Colors/Styles on the Fly

Custom Colors and Transparency

Accept Input via the Properties Window

Configure the Value Scale for Indicators

Using Aggregation Functions

Using IF Statements

Using the Cross Functions

Using NIL

Perform Recursive Calculations

Don't Reassign Variables

Don't Cause Circular References

Trade how you want, where you want

support@ctsfutures.com (312) 939 0164

2 Pierce Pl, Suite 200, Itasca, IL 60143

© 2009-2023 Cunningham Trading Systems LLC All rights reserved.