Trading Systems and Money Management : A Guide to Trading and Profiting in Any Market

(やまだぃちぅ) #1

  1. The input TestRunVar will not be used here, but is present so that you can
    run through your own systems using the random-entry feature. The code for
    the random-entry feature can look something like this:
    Variable: RandomTrigger(0);
    RandomTrigger = IntPortion(Random(2));
    If RandomTrigger = 1 and (rest of entry criteria) Then Begin
    Final buy or sell trigger rule
    An example of how to use the code can be found in Part 2.

  2. We need to create one array to contain the data for our calculations. We could
    have done without the array and instead run through all the calculations for
    each bar, but to speed up the computing time, we will do most of the calcu-
    lations only once, on the very last bar on the chart. The array is now set to
    hold 2,000 trades. The larger the arrays, the slower the calculations, so you
    might want to change this number to what makes the most sense for the sys-
    tem you currently are working on.

  3. These calculations and exports only need to be done once, on the very first
    bar on the chart. By altering the state of the variables AllowLong and
    AllowShort at the very top of the code (see the code for any of the individ-
    ual systems), we can test all long and short trades, either separately from
    each other or together. Then we create the file that we will import into Excel
    (variable SCT.FileString) and the column headers for the data we need to
    export later (variable SCT.TestString).

  4. These calculations are done on every bar on the chart. We are now filling the
    array SCT.TradeProfit with the end result of each trade. An array is a series
    of values stored in a specific order. In this case, the first position in the array
    will hold the result of the first trade, and so on.

  5. All remaining calculations will only be executed on the very last bar of the
    chart. Note: If you plan to use this code and use the criteria Open Next Bar
    (or Open Tomorrow) for your entries and exits, you must use the alternative
    function. First, we run a loop (that starts with the word “For”) to calculate the
    total profit (variable SCT.SumProfit) by adding all the values contained in
    the array SCT.TradeProfit. We also count the number of winning trades in
    the variable SCT.WinTrades.

  6. Moving out of the first loop, we now calculate the variables AvgTradeVar and
    PercWinVar, which are self-explanatory.

  7. The second loop (also starting with the word “For”) sums up the squared
    profits from all trades in the SCT.SumSqProfit variable.

  8. Moving out of the second loop, we calculate the standard deviation of all
    trades (variable StDevVar).

  9. Finally, all the necessary data will be stored in the variable SCT.TestString
    and exported into a file that we can open with Excel, with the help of the


CHAPTER 20 Adding Exits 225

Free download pdf