There are 8 types of parameters you can use:
ot_Longword - unsigned integer, 0..4294967295
ot_Integer - signed integer, -2147483648..2147483647
ot_Double - double, 5.0 x 10^-324 .. 1.7 x 10^308
ot_String - text string
ot_Boolean - true/false
ot_EnumType - you can define list of strings for this parameter, internal value will be position in this list 0...N-1
ot_Timeframe - this parameter represents available timeframes PERIOD_M1..PERIOD_W1
ot_Currency - this parameter contains currency name and will allow you to choose currency from currency list in dialog
You should define parameters in InitStrategy procedure. There are 5 procedures that you can use to do this:
RegOption - this procedure creates new parameter.
AddSeparator - just adds horizontal separator to parameters' dialog to separate one group of parameters from another.
AddOptionValue - this procedure adds new string value to parameter of type ot_EnumType to create drop down list of strings.
SetOptionRange - if you want to check user input for correct values you can set range of values for a parameter. Only for longword, integer and double parameters.
SetOptionDigits - defines how many digits after point you will see in dialog. Only for double parameter.
Let's add parameter to our strategy from lesson 1. First of all we need to define variable where this parameter will be stored:
Code: Select all
// external parameters
var
Delta: double = 3.46;
This parameter will be initialized with value of 3.46 on the first start, after that this value will be stored in ini file for this strategy automatically.
And some extra strings in InitStrategy procedure:
Code: Select all
RegOption('Delta', ot_Double, Delta);
SetOptionRange('Delta', 0, 100);
SetOptionDigits('Delta', 2);
Simple, isn't it? With RegOption we created new parameter 'Delta' of type ot_Double and linked it with variable Delta.
With SetOptionRange we defined that this parameter can vary from 0 to 100.
With SetOptionDigits we said that we want to see only 2 digits after point in parameters dialog.
Our strategy code will looks like:
Code: Select all
library DemoStrategy;
uses
SysUtils, StrategyInterfaceUnit, TechnicalFunctions;
// external parameters
var
Delta: double = 3.46;
procedure InitStrategy; stdcall;
begin
StrategyShortName('DemoStrategy');
StrategyDescription('Demo strategy that does nothing');
RegOption('Delta', ot_Double, Delta);
SetOptionRange('Delta', 0, 100);
SetOptionDigits('Delta', 2);
end;
procedure DoneStrategy; stdcall;
begin
end;
procedure ResetStrategy; stdcall;
begin
end;
procedure GetSingleTick; stdcall;
begin
end;
exports
InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick;
end.
If you do not want to do extra job, you can omit SetOptionRange and SetOptionDigits. In this case ForexTester will not control the range and use 2 digits after point by default.
And here it is our parameters' window after we copied our strategy and restarted ForexTester: