Scripting

Scripting

Scripting environment

AgenaTrader's programming environment (script) is similar to that of Visual Studio, and allows you to:

  1. navigate the programming workspace using toolbars,

  2. handle multiple components at the same time via the editor (top tab bar),

  3. use the IntelliSense® functionality,

  4. view a list of errors at the bottom of the screen.

Scripting toolbar

Icon

Function

Loads existing self-programmed indicators/strategies to the workspace

Saves source code changes

Cuts marked source code

Copies marked source code

Pastes copied / cut source code

Enables comments on marked source code parts

Uncomments the selected lines

Cancels previous action(s)

Repeats cancelled action(s)

Opens output window

Opens reference popup

Compiles sources

Searches for a text within source code

Find/Replace

Opens list of errors

Deletes file

Visual Studio

Microsoft offers a free version called Visual Studio Community Edition, which is pretty good to develop AgenaScript code. Download: Latest Version of Visual Studio Download: Older Versions of Visual Studio

Supported Versions: • Windows 10: VS2017, VS2019, and VS2022 (latest builds/updates)

Windows 11: VS2022 only (latest builds/updates)

• Please note that VS2015 and older are not supported by Microsoft anymore hence why we will not support either

This article was created by http://script-trading.com.

AgenaTrader and Visual Studio

AgenaTrader offers its very own script editor that can be used for AgenaScript development.

This editor is a useful tool when it comes to quickly changing a couple of lines of code, or if you just want to look at an AgenaScript. For all other applications, it is essential that you use Microsoft’s development environment Visual Studio. It offers a comprehensive solution that has proven itself time and again for almost all areas of software development, including of course for AgenaScript as well as for C#.

The most important advantages are:

  • Debugging

  • Code Completion

  • Syntax checking

In addition, there is a multitude of further features that make developing easier for you.

You can download the free “Visual Studio Community” edition at https://www.visualstudio.com/downloads. Please note that the download and the installation of the software take about 60 minutes!

From AgenaTrader 2.0 onwards, you need to use at least “Visual Studio Community 2017” due to the .NET version 4.6 that is implemented! Check the list of supported visual studio versions above.

Once you have successfully installed Visual Studio, you can link it to AgenaTrader using the Global Configuration setting shown below. From now on, all AgenaScript files will automatically be opened with Visual Studio, and the debugger will also automatically be linked to AgenaTrader.

Global Configuration setting for Visual Studio

You can now conveniently develop, test and debug your AgenaScripts in Visual Studio.

This article was created by http://script-trading.com.

Programming of indicators

Select the Strategy Handlings-> Scripting and then Indicator -> New or Edit menu items to program new indicators or make changes to existing indicators.

Editing indicators

Should you wish to change/modify an existing indicator, select the Edit menu item to open the following Indicators dialog window:

The buttons inside this window have the following functions:

  • Click the Edit button or double-click on the entry to open the scripting window for the selected indicator.

  • Click the Delete button to remove the selected indicator.

  • Click the Compile button to compile all indicators, conditions, strategies and alert handlers. If you delete an indicator, the system will only accept changes after you have clicked the Compile button.

Creating a new indicator

After selecting the New->Create menu item for creating a new indicator you will receive a navigation popup with the option to either create a new indicator or import an indicator from a different trading platform:

  • Step 1. Enter the name

    • Chart-Panel: if this is checked the indicator will be displayed in the charting panel.

    • Indicator-Panel: if this checked the indicator will be displayed beneath the chart.

  • Step 2. Define parameters.

  • Step 3. Define the Plots-Outputs for visualization of the indicator.

  • Step 4. Define Level-Lines with the fixed threshold values (if necessary).

  • Step 5. Begin writing the indicator-specific program code.

    • The compile function is availalbe via Strategy Handling- > Scripting -> Compile

After Indicator would be available in indicator list

Programming of conditions

Select from the main menu Strategy Handling-> Scripting followed by Condition -> New or Edit items to create new or modify existing conditions.

Editing conditions

If you wish to edit the existing condition, select the Edit submenu. You will see the following dialog box.

The buttons inside this window have the following functions:

  • Click the Edit button or double-click on the entry to open the programming window for the selected condition.

  • Click the Delete button to remove the selected conditions.

  • Click the Compile button to compile all indicators, conditions, strategies and alert handlers. If you delete a condition, the system will only accept changes after you have clicked the Compile button.

Creating a new condition

  • Step 1. Enter the name

  • Step 2. Define input parameters

  • Step 3. Select the condition type: entry, stop or target. This will determine where the condition will appear in the SetupBuilder (EntryEscort, StopEscort or TargetEscort respectively).

Additionally, you can specify the line and color for a condition

    • Entry: tba

    • Stop occurred: defines the color of the signal fluctuations ("spikes") within the indicator panel; price defines the color within the chart.

    • Target: tba

  • Step 4. Begin programming the condition-specific code.

Programming of strategies

Select from the main menu Strategy Handling-> Scripting and then Strategy -> New or Edit to program new or edit the existing strategy.

Editing strategy

If you wish to edit the existing strategy, select the Edit submenu. You will see the following dialog box:

The buttons inside this window have the following functions:

  • Click the Edit button or double-click on the entry to open the programming window for the selected strategy.

  • Click the Delete button to remove the selected strategies.

  • Click the Compile button to compile all indicators, conditions, strategies and alert handlers. If you delete a strategy, the system will only accept changes after you have clicked the Compile button.

Creating a new strategy

After selecting the New->Createmenu item for creating a new strategy you will receive a navigation popup with the option to either create a new strategy or import a strategy from a different trading platform:

  • Step 1. Enter the name

  • Step 2. Define input parameters.

  • Step 3. Begin programming the strategy-specific code.

Programming of Alert Handlers

AgenaTrader's extensive functionalities allow you to code custom price and time alerts within a single (or multiple) self-programmed alert handler(s). Programming in AgenaTrader is based on the Microsoft C#/.net language which enables you to control the system environment and use/code features such as email, SMS, blog entries etc.

Select from the main menu Strategy Handling-> Scripting following by Alert Handler -> New or Edit items to programm new or edit existing alerts.

For example, in the Time alert tab you can select an entry reason for an alert.

Once your price or time alert is triggered, all existing alerts will be opened. You will see the reason for the alert inside this window and can terminate the current alert.

Editing Alert Handler

If you wish to edit the existing alert handler select the Edit submenu. You will see the following dialog box:

The buttons inside this window have the following functions:

  • Click the Edit button or double-click on the entry to open the programming window for the selected alert handler.

  • Click the Delete button to remove the selected alert handler.

  • Click the Compile button to compile all indicators, conditions, strategies and alert handlers. If you delete an alert handler, the system will only accept changes after you have clicked the Compile button.

Creating a new Alert Handler

  • Step 1. Enter the name and a short description.

  • Step 2. Click on the Next button and begin programming the alert-specific code.

Example. Alert Handler for sending emails

A simple method of combining a price or time alert with the Alert Handler is to use the alert reason. If, for example, the field for alert reason contains “Send Email” then the programmed alert will be executed as soon as the alert handler finds this alert reason.

Output window

The output tab displays messages that have been built into self-programmed indicators, strategies, alert handlers, etc. based on the print method.

This tab can also be used for troubleshooting (debugging), but besides this it has no other functionalities.

Right click in the tab and select the Clear option to delete all entries in the output tab.

Scripting references

Select Strategy Handling-> Scripting following by Scripting references from the menu to load the necessary references for programming or to edit them.

The following window will be opened:

The references can be selected from the top tabs .Net, COM and Browse.

The buttons inside this window have the following functions:

  • Click the Add button to attach the references to the reference list.

  • Click the Remove button to delete a reference from the reference list.

  • Click the OK button to accept the changes.

Compile

To integrate self-programmed alert handlers, indicators, conditions, strategies, or conditions compiled from external sources using Signal Builder into AgenaTrader, copy the *.CSV file from Documents/AgenaTrader/UserCode/ into the corresponding subfolder "Scripted alert handlers (indicators, conditions, strategies)" or into the Signal Builder subfolder. Then select Strategy Handling-> Scripting -> Compile to make these available within AgenaTrader.

Directory structure

Compiling errors

If the compilation procedure generates errors, this information will appear in a dialog box indicating where the error comes from.

Compile Errors

Compile Error

If the compilation procedure generates errors, this information will appear in a dialog box indicating where the error comes from.

1. Display Error description 2. Display file name. Left click on file name will open file location.

You may use the Visual Studio instead of the internal Script (programming environment) just activate Use Visual Studio checkbox in Global Configuration

Scripted Conditions Error

In order to solve the issue User should verify conditions scripts and try to compile again.

  • Select from the main menu Strategy Handling-> Scripting-> Condition ->Edit items to verify condition.

  • In the following dialog box click the Edit button or double-click on the entry to open the programming window for the selected condition.

Scripted Indicator Error

In order to solve the issue User should verify indicator scripts and try to compile again.

  • Select the Strategy Handlings-> Scripting->__Indicator -> Edit to verify indicator.

  • In the following dialog box click the Edit button or double-click on the entry to open the programming window for the selected indicator.

Scripted Strategies Error

In order to solve the issue User should verify strategy scripts and try to compile again.

  • Select from the main menu Strategy Handling-> Scripting -> Strategy -> Edit item to verify condition. strategy.

  • In the following dialog box click the Edit button or double-click on the entry to open the programming window for the selected strategy.

Last updated