The OPTION keyword is used to define a special numeric property that can be optimized during the trading-system backtesting. Options can in fact be used ONLY in trading systems.
Options can be used ONLY in trading systems
An option is a numeric property with a specific validity range. The difference with the other numerical properties is that it can be optimized during the trading system backtesting (performed by the Tester application). In other words, backtesting will automatically test all the values that an Option can assume (from minimum to maximum by adding the step value to each new test), trying to identify the Option value that produces best results in the trading system.
Option <option name> (<minimum value>, <maximum value>, <step>, ["<description>"])
Options can be defined exclusively in the Common Module of trading systems
An Option is defined by OPTION keyword and the following attributes:
Option Name: defines Option name. The name will identify the Option internally and externally to the script.
Minimum Value: Option minimum value.
Maximum Value: Option maximum value.
Step: defines the increase in value of the Option during the backtesting. For example, if minimum value is 2, maximum value is 14 and step is 4, during the backtesting the Option will assume the values: 2, 6, 10, 14. The fundamental rule is that (Maximum Value – Minimum Value) must be a multiple of Step. In the example, 14 – 2 = 12, and 12 is a multiple of 4.
Description: (optional) Option short description which will be shown for example in the trading system configuration property grid.
An Option is used internally and externally to the script like any property. So externally you will have to set it in the trading system configuration window, inside the script you will use it as any “read only” variable.
Let’s consider a trading system that generates buy/sell signals depending on up/down crossing of two moving averages built on different periods. The significant parameters of this trading system are the periods on which to calculate the moving averages. To find the best value of the two periods we will therefore use two Options and test the trading system with the Tester application, which will assign all possible combinations of values to the two Options, finding the ones that produced best results.
Option MM1(5, 30, 1, "Period of Moving Average 1") Option MM2(5, 50, 1, "Period of Moving Average 2")
Function Main() If (my.Analysistool.Crossabove(Mov(Close, MM1), Mov(Close, MM2)) = True) Then Return True EndIf Return False EndFunction
Function Main() If (my.Analysistool.Crossbelow(Mov(Close, MM1), Mov(Close, MM2)) = True) Then Return True EndIf Return False EndFunction