Skip to content

backtest usage

Benny Thadikaran edited this page Sep 13, 2024 · 4 revisions

This tool allows you to scan for patterns that played out in the past and display on chart how the pattern played out along with its historical context.

  • You must specify an end date and a pattern to scan.
  • The default scan period is 30 periods prior to this end date.
  • It loops through each candle and scans for pattern formation during the scan period.
  • If a pattern is detected, it plots the chart, starting 120 days prior to pattern and ending 120 days after the pattern.
  • This gives you the historical context of the pattern and its success or failure.

It allows you to compare, evaluate and study patterns more effectively.

m&m backtest result

Basic Usage:

Ensure you have user.json setup.

Use -p or --pattern to specify the pattern name.

Use -d or --date to specify the end date. Date must be in ISO format YYYY-MM-DD or YYYY-MM-DDTHH:MM.

Both options are required to run the scan.

py backtest.py -p vcpu -d 2024-05-07

Custom Watchlist

Provide a custom watchlist of symbols as a CSV or TXT file. Default watchlist should be specified in user.json

py backtest.py -p hnsd -d 2024-05-07 -f symlist.csv

Set Scan parameters

If --date is not provided, end date is set 120 periods prior to the latest available date.

By default, scan period is 30 candles prior to end date. You can override it with --period

py backtest.py -p trng -d 2023-12-01 --period 120


You can also specify the timeframe using --tf option.

py backtest.py -p trng --d 2023-12-01 --tf weekly

If configured for intraday data, you can pass an intraday timeframe as well.

py backtest.py -p hnsd -d 2024-05-11 --tf 60


For IEODFileLoader, valid values for DEFAULT_TF are 1, 5, 10, 15, 25, 30, 60, 75, 125, 2h, 4h.

For EODFileLoader, valid values for DEFAULT_TF are daily, weekly and monthly.

Help

Use -h to see help

py backtest.py -h

usage: backtest.py [-h] [-f FILE] [--tf TF] [-p str] [--plot PLOT] [--idx IDX] [-d DATE] [--period PERIOD]

Run backdated pattern scan

options:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  Filepath with symbol list. One on each line
  --tf TF               Timeframe string.
  -p str, --pattern str
                        Pattern to test. One of vcpu, vcpd, dbot, dtop, hnsu, hnsd, trng
  --plot PLOT           Plot results from json file
  --idx IDX             Index to plot
  -d DATE, --date DATE  Ending date of scan. ISO FORMAT date YYYY-MM-DDTHH:MM
  --period PERIOD       Scan Period, prior to ending date. Default 30
Clone this wiki locally