When you launch the strategy, you first have to input necessary settings before you proceed with executing that strategy.
The procedure OnCreate runs when the strategy window is opened (when you click 'Run' from the Strategy List or Editor).
This procedure creates the strategy settings (and assigns default values).
You can create any settings you need, but most strategies would utilize at least the following: the instrument, the account and the time interval for the chart data.
Let us describe the different possible settings, and the functions that are used to create them.
a) Integer Type Settings
In order to add an integer data type setting, use the function AddIntegerSetting in the procedure OnCreate.
Example:
AddIntegerSetting(@IntS, 'Integer Setting', 45); |
The function AddIntegerSetting has 3 parameters:
1) | @IntS – this is the variable that will hold the value. It must be of the Integer type, and it must be declared in the global variables list. Please note that the name of this variable should be written with the @-prefix in the settings, but without it in the global variables list. |
2) | 'Integer Setting' – this is the label that will appear in the settings tab. |
3) | 45 – this is the default value. |
b) Double Type Settings
In order to add a double data type setting, use the function AddFloatSetting in the procedure OnCreate.
Example:
AddFloatSetting(@FS, 'Float Setting', 1.45); |
The function AddFloatSetting has 3 parameters:
4) | @FS – this is the variable that will hold the value. This variable must be of the Float type, and it must be present in the global variables list. Please note that the name of this variable should be written with the @-prefix in the settings, but without it in the global variables list. |
5) | 'Float Setting' – this is the label that will appear in the settings tab. |
6) | 1.45 – this is the default value. |
c) String Type Settings
In order to add a string data type setting, use the function AddStringSetting in the procedure OnCreate.
Example:
AddStringSetting(@SS, 'String Setting', ‘a123’); |
The function AddStringSetting has 3 parameters:
7) | @SS – this is the name of the variable that will hold the value. This variable must be of the String type, and it must be present in the global variables list. Please note that the name of this variable should be written with the @-prefix in the settings, but without it in the global variables list. |
8) | 'String Setting' – this is the label that will appear in the settings tab. |
9) | ‘a123’ – this is the default value. |
Here is an example of using these types of settings:
Example:
To sum it all up, let us write a strategy that just creates a list of settings: a Float setting, an Integer setting, and a String setting:
The script will be as follows:
const StrategyName = 'My Strategy';
var FS: Double; IntS: Integer; SS: String;
procedure OnCreate; begin AddFloatSetting(@FS, 'Float Setting', 1.45); AddIntegerSetting(@IntS, 'Integer Setting', 45); AddStringSetting(@SS, 'String Setting', 'a123'); end; |
As a result, when we launch the strategy, we will see the following results in the settings tab:
d) Account Settings
In order to add an account setting, use the function AddAccountSetting in the procedure OnCreate.
Example:
AddAccountSetting(@Account, 'Account', ‘314’); |
The Function AddAccountSetting has 3 parameters:
10) | @Acc – this is the name of the object that will hold the value. This object must be of the TAccount class, and it must be declared in the global variables list. Please note that the name of this object should be written with the @-prefix in the settings, but without it in the global variables list. |
11) | 'Trading Account' – this is the label that will appear in the settings tab. |
12) | ‘314’ – this is the default value. |
Example:
Let us write a strategy that just creates a setting for an account.
The script will be as follows:
const StrategyName = 'My Strategy';
var Account: TAccount;
procedure OnCreate; begin AddAccountSetting(@Account, 'Account', '360'); end; |
As a result, such a strategy will build the following list of settings:
e) Candle History Settings
A strategy normally uses chart data. Besides, one strategy can utilize multiple time intervals (per instrument) and multiple instruments.
In order to add a candle history setting, use the function AddCandleHistorySetting in the procedure OnCreate.
Example:
AddCandleHistorySetting(@History, 'Candle History', 'EURUSD', CI_1_Minute, 100); |
The function AddCandleHistorySetting has 5 parameters:
13) | @History – this is the name of the object that will hold the value. This object must be of the TCandleHistory class, and it must be declared in the global variables list. Please note that the name of this object should be written with with the @-prefix in the settings, but without it in the global variables list. |
14) | 'Candle History' – this is the label that will appear in the settings tab. |
15) | 'EURUSD' – the instrument name. This is the default value. |
16) | 'CI_1_Minute' – the time interval of a chart. (Explained in more detail below). This is the default value. |
17) | 100 — the number of preloaded candles. (You need preloaded candles to calculate whatever indicators that you may want to use). This is the default value. |
The predefined time intervals of the chart
Name |
Description |
CI_Tick: TChartInterval |
The tick chart interval. |
CI_1_Minute: TChartInterval |
1 minute chart interval. |
CI_5_Minutes: TChartInterval |
5 minute chart interval. |
CI_15_Minutes: TChartInterval |
15 minute chart interval. |
CI_30_Minutes: TChartInterval |
30 minute chart interval. |
CI_1_Hour: TChartInterval |
1 hour chart interval. |
CI_2_Hours: TChartInterval |
2 hour chart interval. |
CI_4_Hours: TChartInterval |
4 hour chart interval. |
CI_1_Day: TChartInterval |
1 day chart interval. |
CI_1_Week: TChartInterval |
1 week chart interval. |
Example:
Let us write a strategy that just creates settings for a particular instrument and chart interval.
The script will be as follows:
const StrategyName = 'MyStrategy';
var History: TCandleHistory;
procedure OnCreate; begin AddCandleHistorySetting(@History, 'Candle History', 'EURUSD', CI_1_Minute, 100); end; |
As a result, such a strategy will build the following list of settings:
If your strategy uses more than one instrument, you can add settings for each of these instruments.
Note: Each setting should have a unique label.
Example:
Let us write a strategy that just creates 5 instrument settings.
The script will be as follows:
const StrategyName = 'MyStrategy';
var History1: TCandleHistory; History2: TCandleHistory; History3: TCandleHistory; History4: TCandleHistory; History5: TCandleHistory; procedure OnCreate; begin AddCandleHistorySetting(@History1, 'Candle History1', 'EURUSD', CI_1_Minute, 100); AddCandleHistorySetting(@History2, 'Candle History2', 'GBPUSD', CI_5_Minutes, 50); AddCandleHistorySetting(@History3, 'Candle History3', 'USDCHF', CI_30_Minutes, 200); AddCandleHistorySetting(@History4, 'Candle History4', 'USDJPY', CI_1_Hour, 150); AddCandleHistorySetting(@History5, 'Candle History5', 'EURGBP', CI_1_Day, 340); end; |
As a result, this strategy will build the following list of settings:
When the strategy is started, each instrument chart will be displayed in an individual tab.
f) Tick History Settings
If you want to use rate ticks in your strategy, you need to utilize a tick history setting. Use the function AddTickHistorySetting in the procedure OnCreate.
Example:
AddTickHistorySetting(@History, 'Tick History', 'EURUSD', 100); |
The function AddTickHistorySetting has 4 parameters:
18) | @History – this is the name of the object that will hold the value. This object must be of the TTickHistory type, and it must be present in the global variables list. Please note that the name of this object should be written with the @-prefix in the settings, but without it in the global variables list. |
19) | 'Tick History' – this is the label that will appear in the settings window. |
20) | 'EURUSD' – the instrument name. This is the default value. |
21) | 100 — the number of uploaded ticks. This is the default value. |
Example:
Let us write a strategy that just creates the settings for the tick history of one instrument.
The script will be as follows:
const StrategyName = 'MyStrategy';
var History: TTickHistory;
procedure OnCreate; begin AddTickHistorySetting(@History, 'Tick History', 'EURUSD', 100); end; |
As a result, such a strategy will build the following list of settings: