Trading Systems Coding: System Design
  1. Trading Systems Coding: Introduction
  2. Trading Systems Coding: System Design
  3. Trading Systems Coding: The Coding Stage
  4. Trading Systems Coding: The Coding Process
  5. Trading Systems Coding: Testing, Troubleshooting and Optimizing
  6. Trading Systems Coding: Using Your System
  7. Trading Systems Coding: Conclusion

Trading Systems Coding: System Design


By Justin Kuepper
Contact Justin

The first step when coding any application is the design phase. Whether coding a software application or a trading system, careful design and planning will help you finish in a shorter amount of time with fewer errors. We will be using a simple three-step process to design our trading system.


Step 1: Create Your Trading System Rules
The first step when designing a trading system is simply coming up with the rules by which your system will operate. There should be four core rules to every trading system:

  1. Buy - Identify when you want to buy a position.
  2. Sell - Identify when you want to sell a position.
  3. Stop - Identify when you want to cut your losses.
  4. Target - Identify when you want to book a gain.
So, for example:
  1. Buy - When the 30-day moving average (MA) crosses above the 60-day MA
  2. Sell - When the 30-day MA crosses below the 60-day MA
  3. Stop - Maximum loss of 10 units
  4. Target - Target of 10 units
This example system will buy and sell based on the 30- and 60-day moving averages and will automatically book gains after a 10-unit profit or sell at a loss after a 10-unit move in the opposite direction.

Step 2: Identify the Components of Each Rule
Now that we have our rules down, we need to identify the components involved in each rule. Each component should contain two elements:
  1. The indicator or study used
  2. The settings for the indicator or study
These components should be constructed by typing the shorthand name for the study, followed by the settings in parentheses. These settings in parentheses are referred to as "parameters" of the indicator or study. Occasionally, a study may have multiple parameters, in which case you simply separate them with commas.

Let's take a look at a few examples:
  1. MA(25) - 25-day moving average
  2. RSI(25) - 25-day relative strength index
  3. MACD(Close(0),5,5) - Moving average convergence divergence set based on today's close, with a five-day fast length and a five-day slow length
If you are unsure of how many parameters a certain component requires, you can simply consult your trading program's documentation, which lists these components along with the values that need to be filled in. For example, we can see that Tradecision tells us that we need three parameters with MACD:



So, for the example mentioned in step one, we would use:
  1. MA(30) - Meaning 30-day moving average
  2. MA(60) - Meaning 60-day moving average
Step 3: Adding Action
Now we will add actions to our rules. Each action adheres to the following basic format:

IF Condition [WHILE Condition] THEN Action




Typically, the condition will consist of the components and parameters you created above, while the action will consist of buy or sell. Conditions may also consist of simple English if no component is present. Note that the "while" component is optional.


Here are a few examples to help illustrate this point:
  • IF MA(30) Crosses Above MA(60) THEN Buy
  • IF MA(30) Crosses Below MA(60) WHILE Volume(20,000) THEN Sell
  • IF EMA(25) Is Greater Than MA(5) THEN Sell
  • IF RSI(20) Is Equal To 50 THEN Buy
So, for the example we've been using, we'd simply list:
  • IF MA(30) Crosses Above MA(60) THEN Buy
  • IF MA(30) Crosses Below MA(60) THEN Sell
  • IF our trade has 10 units of profit THEN Sell
  • IF our trade has 10 units of loss THEN Sell
What's Next?
Next, we'll take a look at converting these rules into a code that your computer can understand!
Trading Systems Coding: The Coding Stage

  1. Trading Systems Coding: Introduction
  2. Trading Systems Coding: System Design
  3. Trading Systems Coding: The Coding Stage
  4. Trading Systems Coding: The Coding Process
  5. Trading Systems Coding: Testing, Troubleshooting and Optimizing
  6. Trading Systems Coding: Using Your System
  7. Trading Systems Coding: Conclusion
RELATED TERMS
  1. Optimization

    In the context of technical analysis, it is the process of adjusting ...
  2. Moving Average - MA

    A widely used indicator in technical analysis that helps smooth ...
  3. Balanced Fund

    A fund that combines a stock component, a bond component and, ...
  4. Forex System Trading

    A method of trading forex that is based on a series of analyses ...
  5. CB Leading Index

    An index that is a composite average of ten leading indicators ...
  6. Purchasing System

    A method used by businesses to buy products and/or services. ...
RELATED FAQS
  1. How do I pick the best method for forex system trading?

    Discover how to identify the best type of forex system trading style for you based on your available time, your trading preferences ... Read Answer >>
  2. How are moving averages used in trading?

    Moving averages are very popular tools used by technical traders to measure momentum. The main purpose of these averages ... Read Answer >>
  3. How can I use simple moving averages to signal when to buy or sell stocks?

    Learn about simple moving averages, simple moving average strategies and how to use these strategies to signal buy and sell ... Read Answer >>
  4. What do the bracketed numbers following a technical indicator mean?

    In technical analysis, it is common to see a series of numbers following a given technical indicator, usually in brackets. ... Read Answer >>
  5. How are Moving Average Envelopes calculated?

    Discover how to create a moving average envelope for a security or index and how to determine which time length and band-widths ... Read Answer >>
  6. Can I borrow from an IRA without penalty?

    Yes. A 60-day rollover rule applies to all types of IRAs. This 60-day rollover rule allows you to withdraw assets from your ... Read Answer >>

You May Also Like

Hot Definitions
  1. Yield Curve

    A line that plots the interest rates, at a set point in time, of bonds having equal credit quality, but differing maturity ...
  2. Stop-Limit Order

    An order placed with a broker that combines the features of stop order with those of a limit order. A stop-limit order will ...
  3. Keynesian Economics

    An economic theory of total spending in the economy and its effects on output and inflation. Keynesian economics was developed ...
  4. Society for Worldwide Interbank Financial Telecommunications ...

    A member-owned cooperative that provides safe and secure financial transactions for its members. Established in 1973, the ...
  5. Generally Accepted Accounting Principles - GAAP

    The common set of accounting principles, standards and procedures that companies use to compile their financial statements. ...
  6. DuPont Analysis

    A method of performance measurement that was started by the DuPont Corporation in the 1920s. With this method, assets are ...
Trading Center