Using individual futures contracts for backtesting in RealTest
I quickly cover how to go about handling contract rollover manually instead of using continuous contracts in RealTest.
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.
I use continuous contracts when backtesting futures in RealTest. The data comes from Norgate. They also have individual contracts. In RealTest, you can import the individual contracts and manage the rollover logic yourself. I believe you can also use CSI futures data and manage the rollover logic in their software, but I don't use CSI data.
I tend to use continuous contracts in my backtesting because it is the fastest way to model and test out ideas. Since I day trade futures (ES, specifically), I actually use the strategies I built in RealTest as a scanner. I'll generate orders and see what the orders are generated to help me get a "lean" on the day. Since the tests are ran assuming buy at the open and exit at close, I can use the accuracy percentages of each strategy to gauge the strength of the edge.
However, if you want to actually generate accurate orders for trading these strategies live (or automating the process), you will want to use the individual contracts. This also gives you more control of the rollover logic. If that is what you want to do, I am going to show you how I have done this in the past.
First, the results of both variations on the most recent strategy (26_NQ).
As you can see, it has very similar results.
I will show how to do this witch strategy 26 below the paywall, but for free subsribers, I am going to provide snippets in case you want to implement this. Before you get started, make sure you have a watchlist of the idnividual contracts that you want to trade and import them into RealTest. I use Norgate for this so it is very simple.
Import
:
DataSource: Norgate
IncludeList: .@NQ_Individual_Contracts {"NQ"}
We need to define our rollover logic. Below is an example of a simple volume based rollover and a check to make sure we aren't trading the outgoing contract during triple witching.
Data
:
// Contract Rollover
turnover_min: 5e4
lowest_turnover: Lowest(Extra ,5)
turnover_ma: MA(Extra, 5)
DaysToExp: Days(BarDate, InfoExpiry, True)
TripleWitching: DaysToExp < 5
liquid: lowest_turnover > turnover_min and not TripleWitching
MktRank: #Rank #ByMkt If(liquid and inlist("MicroES"), turnover_ma, -1)
We can use the Library
section to store a constant variable that checks the market rank to determine if we can hold the contract per the logic defined about
Library
:
CanHold: MktRank = 1
From there, you can use the CanHold
boolean to check for the correct contract in the Strategy section.
Strategy
:
EntrySetup: long and CanHold
Too easy. If you are using indicators with long lookbacks, it would be wise to import a second list with the continuous contracts that you are looking to trade as well. That way you can use them to calculate whatever indicators you need.
Code
The rest of this post is for paid subscribers. Paid subscribers will have access to all paid publications, strategies, code associated with posts, and access to the HGT chat room. Red Team members will have access to the community GitHub and more.