Updates and Changes
It has been a few weeks since I last posted. This is a quick post to round up what we have done so far and where we are going next.
I apologize for the delay in posts. I have been knee-deep in NinjaScript documentation, trying to solve some issues with my strategy development method. I have also been exploring other platforms and methods for creating automated trade systems. I have learned a lot, and there have been some changes in the HGT code base that reflect this. In this post, I will discuss the issue I was working on, where it led me, and what I plan to do next.
TL;DR
Backtest engine and data resolution/reliability matter, especially so for intraday systems.
There have been updates to the HGT code base and overall structure.
I will be dropping 3 Twilight Strategies from ATS before the end of this month.
Disclaimer: the following post is an organized representation of my research and project notes. It doesn’t represent any type of advice, financial or otherwise. Its purpose is to be informative and educational. Backtest results are based on historical data, not real-time data. There is no guarantee that these hypothetical results will continue in the future. Day trading is extremely risky, and I do not suggest running any of these strategies live.
Changes to the Code Base
The first change in the code is the namespacing convention and the use of explicit coding methods over functional methods. I attempted to export Strategy 9X and ran into compatibility issues with C# versions and how I used namespaces. Now, the namespaces properly represent the folder structure that it belongs to. This helps NinjaTrader find these functions so they can be packaged with a strategy for export. I removed all lambda expressions from the code and used more explicit coding methods.
Several of my previous posts discussed many changes to the original strategy template and idea. This attempt to encapsulate different parts of logic separately led me to refine this approach further. Many of the same concepts from before still exist, but they have been altered to be more extensible and readable. As it currently stands, I have five main models for creating a trading strategy:
Signal Model
Responsible for generating trade signals.
Execution Model
Responsible for entry execution and relies on a signal from a signal model.
Stop Model
Responsible for setting the stop orders (if used).
Profit Model
Responsible for setting the profit orders (if used).
Risk Model
Responsible for overall risk management of a strategy.
Each model has a base model that extends the strategy reference. That gives us access to strategy methods that we did not have access to in the previous way. On top of those models, there are still various helper functions. One of those is a Trade Tracker class that acts as an object to store orders for active positions and set flags for current market positions. It is a product of my attempt to increase backtest accuracy.
An Attempt to Increase Backtest Accuracy
While working on a project with Celan Bryant of Automated Trading Strategies recently, I ran into an issue with running a backtest using tick-level calculations and market replay. The strategy in question used Calculate.OnEachTick
instead of the Calculate.OnBarClose
method we have been experimenting with here at HGT. To backtest a strategy that calculates on each tick, you need to enable the Tick Replay feature in NinjaTrader (NT). This allows the simulator to (attempt) to playback the market the way it would have in real-time.
There are a lot more things to consider when developing a strategy this way. One of those things is how rapidly a signal for a trade is generated in a backtest. The backtest simulation does not consider certain things, such as delay in order placement. When attempting to run a backtest with Tick Replay enabled, I got results showing more than one thousand trades daily. The signal to trade was firing so fast that the signals were interrupting the process and causing stacked trades by the hundreds.
To combat this, I created the Trade Tracker class mentioned above. This didn’t work. It improved it, but it was still generating repeat trades. I also refined the stop, profit, and execution models, but it didn’t help. In the end, what helped was hard coding a slight (1 second) delay into the execution model. That delay was long enough to disrupt the loop and signal trades more realistically.
While the backtest on that particular strategy now looks more realistic, I have yet to test it entirely in a forward test. I already attempted once and got some funk that needed addressing. It is running again, and we will see how it goes. Learning to use tick data for testing and development is a work in progress.
Upcoming Posts
I plan on releasing three more Twilight Strategies from Automated Trading Strategies before the end of this month. Since there was a delay in getting started this month, this is a good way to give back to the subscribers. I will always post at least one strategy a month, but my hope is to continuously provide updates and improvements to the strategies and framework as a whole.
Plans for the Future
After the next three strategy posts, I want to switch gears a bit. Through the past couple of weeks of hardship, I kept finding myself looking at other options for developing and backtesting trade systems. There is a lot of information out there, and there are a lot of different methods for creating and testing trade strategies. You can roll your own, find a single platform that handles everything you need (research, backtesting, live trading), or you can define a technology stack that suits your specific needs.
I use NinjaTrader and NinjaScript for everything right now. I trade manually on that platform, and it’s where I started experimenting with automated trading. My original intention was to continue using this platform and build a home server so I could run forward tests on the strategies we create. However, during this last project, I kept wandering the internet searching for other solutions for the backtesting and strategy research portion of strategy development.
This search led me to QuantConnect (QC). It has several key features/benefits that drew me to it. One of the biggest draws is that if you use their cloud infrastructure, you can access the cloud data for no additional cost. This means that I don’t have to download or format data, and I don’t have to pay bulk download prices. The backtest and research processes would be performed in the cloud, leaving my precious CPU and RAM free to continue streaming anime in the background.
My goal will be to use the QC framework for researching and testing strategies in the cloud. I will continue posting strategies for NinjaTrader. I hope to use the QC trading engine and services to improve strategy development and increase reliability in backtest results. After that, I wish to start an official forward test of the better-performing strategies. I don’t know yet which platform I will run these forward tests on. That is a bridge I intend to cross when I get to it.
Feel free to comment below or e-mail me if you need help with anything, wish to criticize, or have thoughts on improvements. Paid subscribers can access this code and more at the private HGT GitHub repo. As always, this newsletter represents refined versions of my research notes. That means these notes are plastic. There could be mistakes or better ways to accomplish what I am trying to do. Nothing is perfect, and I always look for ways to improve my techniques.