This article walks you step by step through creating a new strategy inside the Strategy Tester, covering how to define entry and exit conditions so you can test your strategy logic on historical data.
#1 - Open Strategy Tester
You can access the Strategy Tester by clicking on the Strategy Tester button in the web application by navigating to the bottom left corner.
The Strategy Tester will appear below the primary price chart. Use the Maximize toggle on the top right corner to make the Strategy Tester larger. You can click the ? mark button on the top right corner to get a interactive tour or a link to the documentation.
#2 - Strategy Settings
Specify the Name of your strategy, Timeframe, Depth, and Settings. Settings allows you to set the chart type (price source), extended hours (on/off), direction (long or short), and trade cost (%).
Note: You can only select a single timeframe. List of available timeframes: 1min, 2min, 3min, 4min, 5min, 6min, 10min, 12,min, 15min, 30min, 45min, 1hr, 65min, 90min, 2hr, 4hr, Daily, Weekly, Monthly, Quarterly, Yearly.
Note: Depth is limited based on your plan. You can choose a "number of candles" or set a date range.
#3 - Defining Entry Conditions
You can define your entry using a Script or a List of Signals (see below). You can define these entry conditions using the same visual scripting editor that powers TrendSpider’s Multi-Factor Alerts, Market Scanner, and Smart Checklist. For example, you might create an entry condition where the SMA 20 is above SMA 50 and the “4 Green Candles” pattern forms.
You can define your Entry conditions with AI by clicking the AI button on the top right corner of the Script box.
Note: You can not scale into a position or have multiple entries in a row. When an entry occurs, the Strategy Tester then looks for the exit.
#4 - Defining Exit Conditions
After you’ve added an Entry Condition, you need to decide when to exit the position — or “when to sell” — by setting Exit Conditions (#4). Exit conditions include Script, Take Profit, Stop Loss, Trailing Stop, Entry Invalidated, # Candles Passed, and List of signals capabilities. For example, you might create an exit condition where you exit if the SMA 20 is below SMA 50 or a 1.5% stop loss is hit.
You can define your Script conditions with AI by clicking the AI button on the top right corner of the Script box.
Note: You can not scale out of a position. Any exit will exit 100% of the position.
#5 - Run Backtest & Save Strategy
Once you have created your Entry and Exit conditions, you can click the Run button to see the results of your backtest. Make sure to always click Save as you make iterations on your strategy so as to not lose your work.
For more information on Strategy Tester, please refer to the documentation on Understanding Strategy Tester from TrendSpider
Using Explicit List of Signals
You can also specify time stamps of triggering candles explicitly, instead of configuring backtester criteria in TrendSpider directly. This is useful in case if you already have a system which generates signals and you want to leverage TrendSpider's unique visualizations for results of backtests.
You can have a list of signals in both Entry and Exit sections. Each list is supposed to contain one signal per line. Order of signals does not matter. Comments (any line starting from #) and empty lines are allowed.
Date/Time Formats Supported
We are flexible in terms of formats of dates we support. Here's a list of options, but it's not exhaustive.
- Unix time stamp. I.e.,
1683755663 - JS time stamp. I.e.,
1683755663924 - ISO datetime (ISO 8601). I.e.,
2023-05-10T21:54:49.486Z - Various human-readable formats, like
23 Aug 2022 09:00 EST, or03/21/2023 10:00 CST,May 10, 2023 18:30 GMT-04e.t.c
Time stamps passed as human-readable text should have a time zone specified.
For Daily charts and above, you should still specify full date and time, specifying the date only won't work. Time is supposed to be equal to session start time.
Time Zones of Signals
It is your responsibility to provide time in a correct time zone. If you don't specify any time zone in your time stamps, then we'll use UTC by default. We're suggesting you specifying time stamps in UTC since it's going to result in the most straightforward behavior. Using other time zones can be quirky. In example, if you'll want to specify a time zone explicitly, then you'll have to know when to use EST and when EDT.
Please mind your chart's time axis time zone when browsing a chart. We suggest you holding everything (charting and time stamps in your backtester) to the same time zone, whatever it is.
Signal Order and Time Stamp
If you provide signals, then please remember the following:
- You should provide a list of time stamps of triggering candles. Backtester will always enter on the next candle after trigger, just like it does with other condition types like Script.
- Order of records in your list does not matter.
- In case if backtester is in a position and then it faces a candle which has yet another Entry signal, this new signal will be ignored. The same is true for Exits.
- You should specify time stamps of "triggering candle open" precisely. Internally, backteser uses strict mathematical equality of JS time stamps when determining whether a candle shoudl trigger a signal.
Other Use Cases for Lists of Signals
You can also use this feature in case if you're willing to share your strategy without revealing its underlying criteria. In example,
- Build a real strategy (with your criteria) on TrendSpider.
- Run a backtest and download list of positions as CSV.
- Create a new blank strategy and specify signals using time stamps (use
Triggering Candle Open Timecolumns). - Share this new strategy.