Skip to main content
Skip table of contents

Structure of a trading system formula

In this example, a trading system is to be created that combines the two indicators GD and momentum. At the same time, this trading system aims to eliminate a typical weakness of momentum, namely the frequently delayed generation of signals when the 100 line is used as a signal generator.

As you can easily see in charts with an overlaid momentum, the standard momentum signal (the breakthrough through the 100 line) is often too late for both buy and sell signals. Therefore, the regression slope of the momentum is to be determined here. It is intended to help determine trend changes in momentum. This is because the direction of the momentum changes when the trend changes, e.g. from falling to rising (in which case a buy signal should be generated) or from rising to falling (in which case a sell signal should be generated). This is an attempt to make better use of the trend.

Variable assignment

In this example, three time series are required, namely the close time series and the moving average formed from it and the regression slope of the momentum. These three time series are first assigned to variables so that they do not have to be recalculated each time they are called up in the formula, but can be read from the memory.

  1. The close time series is used for the calculation in this example. It is assigned to the variable $Close :

    $Close:=Close;

  2. The moving average is formed from the close time series. The function GD[period;method;XVset;Yset] is used for this purpose:

    $Close.GD[$GDperiod]

    The period parameter is assigned the variable $GDZeitraum , which is later assigned values. The other parameters are not assigned, i.e. the default values are used.
  3. The result of this calculation is again a time series. It is stored in the variable $GD .

    $GD:=$Close.GD[$GDperiod];

  4. The momentum is also formed from the close time series. The function MOM[Period;PeriodGD;GD_Variant; GD_XOffset;GD-YOffset] is used for this purpose:

    $Close.MOM[$MOMPeriod;$MOMGDPeriod]

    The "Period" and "PeriodGD" parameters are also assigned variables. The other parameters are not explicitly assigned, i.e. the default values are used for the calculation.
  5. To determine the regression slope of the momentum, the function RegressionSlope[period:number] is applied to the determined momentum (see step 4):

    $Close.MOM[$MOMPeriod;$MOMGDPeriod].RegressionSlope[$Period];

    The "Period" parameter is also assigned a variable.
  6. The result of this partial expression is again a time series. It is stored in the $Mom variable.

    $MOM:=$Close.MOM[$MOMPeriod;$MOMGDPeriod].RegressionSlope[$Period];

Calculation of the trading system

The trading system itself is determined using the following function:

TradingSystem[Lines;Long;Short;CloseLong;Closeshort;SignalMode;Include_Short_Sells;Expenses;LossLimit]

Most of the various parameters are required in this example:

  • The"Lines" parameter defines which progression is displayed in the chart. Since the combination of two indicators can only rarely be shown meaningfully in the chart, the close trend of the security is shown here. The"Lines" parameter is therefore assignedthe $Close variable.
  • The "Long" parameter defines the buy signal. A buy signal should only be given if the close price in the period was greater than the GD and at the same time the regression slope of the momentum was above the midpoint line. The macro GreaterAll[$Comparator;$Period;$YOffset] is used for both comparisons:

    $Close.GreaterAll[$GD;$Comparison_period;$Tolerance]

    This formula is used to examine whether the close has broken through the GD from bottom to top. $Comparison_period specifies how long a breakthrough should be considered as such. $Tolerance indicates the percentage by which the close must have breached the GD for the breakthrough to be considered a signal.

    $MOM.GreaterAll[$centerline;$comparison_period;$tolerance]

    This examines whether the regression slope has broken through the zero line from bottom to top. Since the regression indicates the slope of a curve, it is used to determine whether prices have changed from falling to rising. As both conditions should be fulfilled at the same time, they are linked with AND :

    $Close.GreaterAll[$GD; $Compare_period; $Tolerance] and $MOM.GreaterAll[$Center_line; $Compare_period; $Tolerance]

  • The "Short" parameter is used to define the sell signal. A sell signal should only be given if the close price was below the GD during the period and the regression slope of the momentum was below the midpoint line at the same time. The macro LessAll[$Comparator; $Time period; $YOffset] is used for both comparisons:

    $Close.LessAll[$GD; $Comparison_period; $Tolerance]

  • This formula is used to examine whether the close has broken through the GD from top to bottom. $Comparison_period specifies how long a breakthrough should be considered as such. $Tolerance specifies the percentage by which the close must have broken through the GD for the breakthrough to be considered a signal.

    $MOM.LessAll[$centerline; $comparison_period;$tolerance]

    This examines whether the regression slope has broken through the zero line from top to bottom. Since the regression indicates the slope of a curve, it is used to determine whether prices have changed from rising to falling. As both conditions should be fulfilled at the same time, they are linked with AND :

    $Close.LessAll[$GD; $Compare_period; $Tolerance] and $MOM.LessAll[$Center_line; $Compare_period; $Tolerance]

  • The"CloseLong" and"CloseShort" parameters are not required. They are therefore assigned an underscore"_" to indicate that these signal options are not used and are therefore set to the default value.
  • The"SignalMode" parameter defines how many of the maximum 4 signal options are used, in this case only 2, namely long and short.
  • The"Include short sales" parameter determines whether short positions should be included in the valuation. This parameter is set with the variable $include_empty_sales so that it can be changed later as required.
  • The"Expenses" parameter specifies how many expenses per transaction are to be included in the profit calculation. This information is very important in order to obtain truly meaningful results. This parameter is set with the variable $Expenses so that it can be changed later as required.
  • The"Loss limit" parameter specifies whether the position should be closed automatically at a certain loss. This parameter is set with the variable $Losslimit so that it can be changed later as required.

The complete formula is:

$Close:=Close;
$MOM:=$Close.MOM[$MOMPeriod;$MOMGDPeriod].RegressionSlope[$Period];
$GD:=$Close.GD[$GDperiod];

Trading System[$Close;
$Close.GreaterAll[$GD; $Comparison_period; $Tolerance]
and $MOM.GreaterAll[$Centerline; $Compare_period; $Tolerance];
$Close.LessAll[$GD; $Compare_period; $Tolerance]
and $MOM.LessAll[$center_line; $compare_period; $tolerance];
_;
_;
2;
$Include_short_sales;
$Expenses;
$LossLimit]

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.