Hints & Advice

Hints & Advice

Note: Code changes made in self-scripted indicators are automatically applied to conditions in which this indicators are used if the changes were made in the "body" of e.g. "OnCalculate/OnBarUpdate. Changes of parameters, outputs series, etc. require a manual edit of the conditions.

Bar Numbering Within the Chart

The following example demonstrates the usage of the plot method and the properties of the Chart object.

Bar Numbering Within the Chart

Note: For demonstration purposes, each time Paint is called up within the "Bar Numbering" section, "New" and "Dispose" will also be called up multiple times. From a performance point of view, this solution can be better implemented by using constant variable declarations and calling up "Dispose" within the OnDispose statement.

Custom Chart Background Image

The plot method allows you to add a background image to the chart. The following example uses an image with the JPG format located in the main directory on the hard drive (C:).

Custom Chart Background Image

File Selection in the Properties

To enable file selection within the properties dialog of an indicator, you will need a type converter. The following example displays how a selection of WAV files can be programmed for an alert:

Formatting of Numbers

Formatting of Numbers

General information on formatting in C#

Useful Functions

Returns the currency symbol for the current instrument:

Converts a number into a currency with a thousands separator and 2 decimal places. The block separation per 1000 units can be set in "Culture".

Converts a number into a currency with a thousands separator and 2 decimal places and a currency symbol:

Converts a number into a currency with a thousands separator and 2 decimal places as well as a currency symbol, and fills up to a fixed length with empty spaces. The function is great for outputting values into a table.

Converts a number into a percentage. Nothing is calculated, only formatted. Leading plus sign, a decimal place and a percent sign.

Formats the market price depending on the number of decimal places to which the currency is notated. This includes a thousands separator and fixed length, meaning that zeros are filled on the right hand side. Because Culture Info is being used, you must integrate the NameSpace System.Globalization.

Example

Index Conversion

There are two types of indexing in AgenaTrader.

  1. The bars are numbered from youngest to oldest. This type is used in the OnCalculate() method. The last bar has an index of 0, while the oldest bar has the index Bars.Count-1.

  2. The bars are numbered from oldest to youngest. This type is most commonly used in the OnPaint() method in "for" loops. The oldest Bbar receives an index of 0, while the youngest bar has the index Bars.Count-1. The following function can be used to recalculate the index types:

Overwriting Indicator Names

The name of an indicator (or a strategy) is displayed within the properties dialog and at the top edge of the chart. Use the ToString() method and DisplayName property to overwrite it.

Important tip: Always use both override methods in your scripts to assure that your special name is used on all AgenaTrader forms.

Rectangle with Rounded Corners

By using the graphics methods, you can create interesting forms and place them onto the chart. One example of this is the RoundedRectangle class, which is a rectangle with rounded corners.

Rectangle with Rounded Corners

Last updated