With practice comes mastery. With mastery comes knowledge. With knowledge comes strength. —Marvel’s Iron Fist
Level One ‘trading structure’ — the basics
How I am developing my trading system.
A logical methodology is the most important requirement for any automated trading system. Automating a logical, methodical trading process is straightforward. I will take you through a step-by-step analysis that you should be able to follow and understand. A trading framework is a structure upon that add analysis to optimize it. I will lay out a basic framework, explaining the logic behind trading strategies. How to build and use them.
Goal/objective: The purpose of this framework is to make it easy for me to fine tune and keep improving the trading system as I advance in my trading career.
Trading structure is a hierarchical arrangement organizing the actionable aspects of my investment plan. It has capability to grow to be a large and complex system when I have a bigger seven-digit account and diversified portfolio.
The framework allows for a more complex system future, as my trading experience and portfolio develops and when I implement comprehensive trading processes. I focus more on the trading and Investment Plan, and less on my own plan itself, as the scope of this blog article is ‘you as reader develop your own framework for your trading system.
The capital amount I will be working with is $15,000 as my initial capital. I cannot advise you how much capital you should have as seed capital. It is up to you to determine what asset classes and capital you will use for trading. In my case there is a finite amount of capital that I need to manage, preserve and grow this capital.
Selecting an asset class (market) is a strategic decision that you need to make, and — of course — you are free to choose more than one. The market is asset class that I will trade are stocks, Forex, Options, Options on future and commodities. I don’t feel comfortable with virtual currencies. You can trade any asset class with your level of confidence, liquidity levels, volatility, understanding of underlying assets and capital requirement.
There are eight groups of major technical, fundamental, or macroeconomic drivers and 16 factors behind a security’s risk and returns, so we have many reasons to prefer one asset class over another as below:
|Value||Value is the level of undervalued-ness of a stock or underline relative to the rest of the market (think Warren Buffett looking for “cheap” stocks). |
e.g., After earning report, a stock dropped 50% in 1 day. Find out if it is overly-beaten-down?
2 Earnings yield
|Momentum||4. Momentum is the idea that stocks going up or down will keep going for some time.|
|Size||5. Size of Capital: |
6. Small-caps have outperformed large-caps. Higher growth, higher risk, higher reward. Lots of penny stocks go to zero.
|Quality||‘Quality’ is value indicating underlying unit economics & business lines make sense: stable earnings, consistent asset growth, healthy debt, strong management team, etc.|
8. Investment quality
9. Earnings variability
10. Earnings quality
|Volatility||Volatility is price movement, quantified. Stocks with lower volatility earn greater risk-adjusted returns. On the other hand, more volatility is best for options selling strategies. Quant models use standard deviations of 1–to-3-year timeframes.|
13(a) Residual volatility
|Growth||14. Underlines’ growth prospect in key ingredient in rising price curve|
|Yield||15. Dividend yield|
|Liquidity||16. Liquidity is king|
Factor-based Models Ok, no
The base currency is the trading accounts currency.
Your Investment Plan
My trading plan will serve my purpose, goals and needs, and your plan needs to serve your purpose and only you know what your purpose is. That is why we never copy other traders’ trading plans, rather develop ‘your’ own individual plans to achieve each of ‘your’ goals. Goals lead us to strategies, discussed below.
In this framework a strategy has a set of actions occurring in stages, designed to achieve a specific goal within a broader plan, by executing trades.
Structure of a strategy: The actions occur in specific sequence of trade’s stages. This is how our plan would run every strategy with the same logic to develop a scalable system that may grow to any number of strategies.
Here is my strategy design: (** It is rough draft**)
Developing an auto trading system for trading options:
I currently use my app to calculate and submit the fully-protected option positions. I only have to manually enter the entry, stop, target, direction, and quantity and it calculates everything, creates the order, and sends it to the market in less than a second. I built it so I can send the same order to multiple accounts at the same time (i.e., analyze once and trade for multiple accounts). Of course, once it is live, there will be enhancements.
Section 1 – Strategy logic to determine a trading opportunity. Logic is the ‘secret sauce’. Automation is only as good as your rules. I have been focusing on just trading one symbol so far (SPY and/or SPX), but like to trade a portfolio to trade a basket of symbols (stocks, options, or futures) independent of each other. I was able to resolve the issue so that the Option Chain Provider (OCP) allows me to trade indexes like SPX as well as options for SPY. I just had to pass in the symbol type of index instead of option. I determine the option positions (entry, stop, and target) based on my rules and pass them into the next section of code. I can use any other indicators or logic to help in this decision. I use multiple Price Series Providers (PSP) to get MTF (multi time frames) current data. Once the opportunity is identified, I would use an Option Chain Provider (OCP) to identify options to trade, but I trade indexes like $SPXW.X, which are not available in OCP (although most other symbols are). So, I determine the option positions based on my rules and put them into a specifically defined vector I created. I can populate the vector with just my option positions or a range of options to consider for creating a position once they are priced and calculated.
Section 2 – A function that when I pass in the parameters, creates and returns an OSO/OCO order for me complete with price activation rules based on prices and time of day. For example, I have an OCO order that exits 5 minutes before the market closes if I have not reached my OCO order for my stop or target. A key element of this code is that I had to calculate the Greeks at my entry price, which was often not the current price. I wrote helper functions for all of these to make it much easier. I verified my results with OSPro results and got the same answers. When day-trading options, I use a .8 delta single leg long put or call. I can calculate the .8 delta option at any entry price and then build the order around that position. Writing these all as supporting functions helped tremendously.
I pass the vector into a function I wrote that calculates the option prices and Greeks at the current SETUP, Entry, PT Price Target, and Stop prices. The fully populated vector gets returned to the calling indicator. This function was no small feat. I had to create some other custom functions to calculate Implied Volatility (IV), days to expiration.
Section 3 – Once the vector is returned, I can evaluate the results and determine if I want to take the trade. If so, then I create an entry OSO Order Ticket and pass the vector and order ticket into another custom function that creates the rest of the order. One of my rules is to never trade without a stop. I also include stop/target at the end of the entry OSO Order Ticket, so I am always protected and have a planned exit/target. Once completed, I pass the order ticket back to the original indicator and place the order.
The last piece is the order/position management. Once I send the order, I track the order and its status. If filled, I will track the position status as well. My strategy logic has key points when it could find a better trade. If it does and the previous order has not yet been filled, I cancel that order and send a new one. If I am in a position, I use a technique to move my stop to lock in profits. The technique uses a technical stop and ballistic stop methodologies (much better than a trailing stop), which I call an Adaptive Exit.
The intention is this system will be fully automated. I should not have to do manual interventions. I tried to make it fault tolerant by writing the order/position information to an XML file for more permanent storage. If the system becomes disconnected or crashes, I always have a fully-protected order and I have a routine that re-loads my orders/positions data from permanent storage when a re-start occurs and confirms the current state before proceeding.
I’m still refining the order/position management pieces. Once that is done, I have enough rules to find and get me in trades automatically. However, I plan to do more work on the strategy logic code.
Section 4 – I monitor and manage the order through code in case I want to take actions other than the stop or target. There are many other details, but this is the high-level design. Where am I at on the coding:
Section 1 – Not totally done, although I have several other indicators I use to trade manually. I just need to port them over. I write a lot of functions, which help in the portability of code.
Section 2 – Done and tested.
Section 3 – Working through the function logic to create the multiple levels of OSO Order Ticket (getting close to being done with this).
Section 4 – Since Section 3 creates a fully protected order (set and forget), this is not as critical, but I do want to manage these positions.
It would be nice if we could trade options spread in code, but I have built around that shortcoming. I just get tired of missing out on good opportunities.
** end of rough draft**
Strategy is designed to achieve a specific goal within a broader plan: Try to achieve only one specific goal, because multiple goals with a single strategy, maybe oppose each other. It is important to analyze each goal separately to design a clear strategy. There can be than one strategy to achieve a single goal. Multi strategies at the same time led to identifying more trading opportunities.
The set of rules and formulas comprising the strategy can be based on Technical Analysis, incorporate fundamentals or sentiment data.
Executing strategy for trades: A strategy, when executed, this process results in the exchange of the base currency (asset) for a second asset and after some time — exchanges back the second asset for the base asset. +
The first rule of a trade is to preserve capital and the main goal is to increase capital. The rules of strategy will indicate when to sell your base asset and when to buy your base asset back. Preserving capital is one of the key rules to becoming a successful trader. The law of large numbers says that you will probably have as many good trades as bad ones. The good trades should end up accumulating more profits than the losses you accumulate with your losses of bad trades. Each strategy has three phases, I will call them Trade Analysis Phases, as below:
Pre trade- “Preparing for the trade” Phase: Is about monitoring the market and identifying when the conditions that define certain situations are met, triggering one of your strategies. The conditions that define the situation for actually taking a position may be seen as the final confirmation: the signal that determines that the time for entering a trade is as good as it gets.
- Market Newsletters
- Stock Picking Services
- Various Media Sources
In the trade “Placing and monitoring the trade” Phase includes:
- Broker Account (position updates)
- Real-time Quotes
- Real-time Charting
- Trade Platforms and tools
Post trade -“Reviewing & assessing the trade once completed, Phase includes:
- Buy/sell Trade Logging
- Notes Review
- Charts Review
- Mistakes Review
- Strategy Tweaking
Stage 1: Trigger
Pre-Trade Phase of strategy points to requirement of the rules or conditions to trigger on the strategy.
Triggering a Strategy
These are set of rules to determine if the market and situation is right to execute a certain strategy. Here I outline situations in which I use a certain strategy and each situation is described as a set of conditions that need to be met for me to consider starting to use the said strategy.
trigger on event happens when the conditions for any of the situations that would trigger a strategy are met, indicating the event activates the strategy. A trigger on event is a signal that it is an ideal time to activate the strategy and look for the opportunity of taking a position. Next step is to decide when how and why to take a position or not. When the conditions that define a situation are met, it is a green light for them to enter the trade.
My strategy is guided by predefined conditions when met, define a situation that determines that a certain event will take place. Now, I am ready to analyze, if or when the market has shifted out of those conditions, I do not trade that position, so that the strategy is triggered off.
Size Definition, Capital Request & Allocation
Size of the position: Before taking a position, define the amount of base asset that is being risked. I have a certain amount of capital to trade; therefore, capital allocation is part of my overall capital management and diversification plan.
Set of conditions trigger on and trigger off events that activate and deactivate strategies. The same concept of situations with conditions applies when looking to take a position. When setting up your strategy, you will describe situations, each defined by a set of rules or conditions that — when met, I am ready execute take position event. Taking a position refers to the act of entering into a trade, by placing orders on the exchange.
Stage 2: Open
In this phase, I have an open position. To complete the trade — that is, to buy back, or sell the base asset I need to define the rules to exit the position. This is called take profit (TP) and stop (SL) formulas.
Initial Take Profit & Stop
As per the definition of a trade, the main rule is minimizing the amount of the potential loss and — if possible — the goal is completing the trade at a profit, that is, ending up with a higher amount of your base asset. In that sense, the next step is defining two separate rule-sets for exiting the position: take profit and stop. These formulas will allow us to do just that: take the profit when the trade hits a target or stop and exit the position in case things are not going as expected. These rule-sets are most likely expressed as mathematical formulas. The simplest approach is fixing a constant value as a percentage of the price at the time of the take position event. For instance, let’s say you bought for 10 expecting the price to go up, and your profit target for the trade is a 20% win. Then your take profit would be at 10 + 20% = 12. That would be a constant value for your take profit. Then, let’s say you are willing to lose up to 2% of the capital in the trade if the market moves in the wrong direction; then your stop would be fixed at 10–2% = 9.8. There certainly are many considerations as of how to set these two formulas, and several variables like market volatility, your risk profile, quality of the signal, long-term targets and so on will be part of the criterion you will want to consider. However, such considerations are beyond the scope of this article. That said, it is important to note that setting constant values for take profit and stop is certainly a simplistic approach and that a lot more efficiency can be obtained with more dynamic formulas. Such formulas may take into consideration the actual price movement, momentum, and as many indicators as you may wish to factor in the analysis.
If Stage 1 was mostly about monitoring the market, Stage 2 is about execution: you have identified that the moment is right to take a position, now it’s time to go and do it. Why would you want to think of this as a two-stage process? Isn’t placing an order at the exchange a pretty straightforward operation anyway? Well… it may or may not be. For starters, there are further decisions to be made: are you placing a market order or a limit order? Moreover, the complexity of the execution depends on several factors, the most relevant being the size of the trade and the liquidity of the market. Imagine placing a limit order to buy 1,000 BTC in a second-tier exchange…The order would probably take some time to fill, get partially filled or not get filled at all, right? Also, placing such a big order in the book may affect the market and substantially affect the price, which is undesirable. Large orders need to be fragmented, sometimes even across different exchanges. Also, the position may be taken at different prices, or for a certain period. However, because I’m introducing you to Level One of the frameworks, for the time being, I will assume your orders will be rather small, in the order of magnitude that your exchange of choice can handle fine in a single order. The aforementioned tactics are the subject of a higher level of the framework which I may cover in future articles. As you may now see, there are considerations to be made at the time of execution, and the task itself is quite different from monitoring the market, hence the view of the two as belonging to separate stages.
Stage 3: Manage
As hinted earlier, what you have read so far is the basis of the framework to develop your trading system. As you may have noticed, a trading system corresponds to a lower-level logic concerning the strategic aspects of trading. The system serves to structure the processes and methods that you will use to implement your trading strategies. What follows are considerations that aim to increase the efficiency of your system. In Stages 1 and 2, I described the fundamental components of the take position, take profit and stop events of a trade. What I haven’t covered so far are the underlying opportunities to manage the trade while you have an open position. The term trade management implies that the rules set forth for the take profit and stop don’t need to be static. I already discussed how setting the take profit and stop with dynamic formulas that take into consideration several relevant parameters such as current price or other indicators is preferred over the simplistic approach of setting a constant value considering the price at the take position event only. The concept of managing a trade goes even further. It means that the formulas to determine the take profit and stop may change as the trade develops. The key point to take home is that there is a development or evolution attached to a trade. Trade is not an instantaneous event. It matures over time. Then, how do you manage the trade? What could happen that would make you want to change your take profit and stop formulas? How do you determine when to change them? Well… let’s start with stating the obvious: the development of the trade is analyzed through the same lens you have been using throughout the previous steps, meaning that you keep looking at the state of the market in relation to any number of indicators you wish to analyze, in an attempt to predict what may happen next. But, most importantly, you analyze the market with a focus in your current targets, embodied by the originally defined take profit and stop. To make this clearer, let’s remember the main reason why you want to manage the trade: to optimize the outcome. Therefore, the typical situation in which you may want to change your original take profit and stop formulas is when the trade seems to be going well in your favor. That is, the market is moving in the expected direction and you seem to be making a profit. Does this sound counter-intuitive? Why would you want to change anything at all if things are going according to your expectations? First of all, as long as the position is open, you haven’t accrued the profits! Even if you seem to be winning, the market may reverse before hitting the take profit and may go all the way back to your stop. In such case, if you were playing by the book of Stage 2 (with initial take profit and stop), you would end up with a loss even though you were temporarily winning at some point. Under the Stage 3 paradigm, you would be interested in moving your stop as the price moves in the expected direction in such a way that even if the market reverses before hitting the take profit, you would end up with a smaller loss, with zero loss or even with a profit, depending on how much you manage to move the stop. A second potential scenario is that the market moves in the desired direction and does not reverse. In such a case, if you did nothing to manage the trade, you would hit the original take profit. Good, right? Now, what if the market keeps going way beyond the initial profit? Indeed, you would have missed a good opportunity to surf a big market move and make a much larger profit than originally expected. The conclusion is that it may be in your best interest to manage both stops and take profit, moving them in the direction of the trade as the market moves, allowing some leeway for a larger profit than expected and at the same time cutting the potential for a loss. Remember, greed is not the point of managing the trade; the point is optimization. You need to be careful not to increase the risk as you move the take profit, and make sure you are always tightening your stop at the same time too. In fact, the best practice is to move only part of your take profit, but again, the specifics of the tactics are beyond the scope of this article. How does all this management translate in the framework? The management of the trade is handled in phases. Actually, the management of take profit and stop — while correlated — is done independently of each other, therefore, each concept has its own set of phases.
Changes to take profit and stop formulas respond to the same kind of logic you used to set the original values. When a situation defined by a set of conditions is met, the event indicates that take profit or stop formulas shall be changed. At the moment those predefined conditions are met, you enter the next phase. Keep in mind that the trade is in constant development, so there may be as many phases as you deem appropriate for your particular strategy.
In the animated image above, you may see chart notations indicating changes of phases on take profit (green) and stop (red). Horizontal red lines represent a dynamic stop at each candle interval while horizontal green lines represent a dynamic take profit. The idea of having different phases comes from the notion that big market moves tend to provide clues as to what may come up next. For instance, rallies may accelerate as more traders join the move. Recognizable patterns may emerge. Signs of exhaustion may be identified. All of these considerations should feed the dynamic analysis performed as the trade develops, and may be contrasted with the predefined conditions that may push take profit or stop further, entering one phase after the next.
Stage 4: Close
The Closing Stage has very similar implications to what I explained in the Open Stage in regards to execution. While it is true that the trade management process takes care of making the decisions as of when to close the position by managing the take profit and stop, the actual execution of the exit may require further considerations when dealing with substantial amounts of capital. It is for that reason that I propose to understand execution as a separate stage, while it may not be required in practical terms if you are trading a small capital. If that is the case, then your trade management includes the actual execution and you don’t need to consider any other variables. As hinted earlier, I may review more complex execution tactics in a separate article later on.
While it is sometimes disregarded as a boring task, record-keeping is a fundamental part of the process and should be implemented in your trading system. It doesn’t require much analysis to conclude that being able to track the results of each of your trades will become a fundamental piece of information that should help you finetune your strategies in the future. Remember that markets evolve and strategies perform well for limited periods. Therefore, you should implement a procedure that will evaluate the efficiency of your strategies over time. Such procedures are out of the scope of this piece and I may cover them in a future article. For the time being, just make sure you take note of each of your trades, with at least the basic information, such as date of opening, reasons for entering the trade (conditions met to take the position), take position price, initial and last take profit and stop, return on the trade (%), profit & loss (expressed in your base currency) and duration of the trade.