Skip to content

Writing JSON configuration manually

Benny Thadikaran edited this page Oct 25, 2024 · 2 revisions

The configuration file for Stock-Patterns uses a JSON file. The program, by default, looks for src/user.json. However, you can define multiple configuration files for different data sources. (For example, EOD data or 1 Min OHLC data.)

Below is a sample configuration file structure:

{
  "DATA_PATH": "path/to/ohlc/data",
  "LOADER": "EODFileLoader",
  "DEFAULT_TF": "daily",
  "DATE_COLUMN": "Date",
  "SYM_LIST": "path/to/watchlist/file",
  "24_7": false,
  "EXCHANGE_START_TIME": "09:30"
}

Fields

  • DATA_PATH: The path to the folder containing OHLC (Open, High, Low, Close) data files in CSV format.
  • LOADER: The class used for loading the OHLC data. Possible values are "EODFileLoader" or "IEODFileLoader".
  • DEFAULT_TF: The default timeframe for the OHLC data in your CSV files. Options depend on the loader:
    • "EODFileLoader": "daily", "weekly", "monthly"
    • "IEODFileLoader": "1", "5", "10", "15", "25", "30", "60", "75", "125", "2h", "4h"
  • DATE_COLUMN: (OPTIONAL - Default 'Date') The name of the date column in your OHLC files. If the column is not named "Date", specify the name here.
  • SYM_LIST: (OPTIONAL) The path to the watchlist file (text or CSV file) with symbol names listed one per line.
  • 24_7: (Optional - Default false) Boolean indicating if the market operates 24/7. Set to true for markets like Crypto or Forex. If set to false, specify the EXCHANGE_START_TIME.
  • EXCHANGE_START_TIME: (Optional) The start time of the exchange in HH:MM format, if the market does not operate 24/7.

24_7 and EXCHANGE_START_TIME are necessary only if using IEODFileLoader, else the values are ignored.

Steps to Create the Configuration File

  1. Create a New JSON File: Create a new file named user.json in the src folder.

  2. Set Up DATA_PATH: Specify the full file path to the folder containing your OHLC data files. (Must be a folder).

    "DATA_PATH": "path/to/ohlc/data"
  3. Choose and Set the LOADER: Choose between "EODFileLoader" for end-of-day data or "IEODFileLoader" for intraday data and set it accordingly.

    "LOADER": "EODFileLoader"
  4. Specify DEFAULT_TF: Define the default timeframe. Ensure it matches the timeframe options available for the chosen loader.

    "DEFAULT_TF": "daily"
  5. Set DATE_COLUMN (If Needed): If your OHLC files use a different date column name, specify it here. Otherwise, it defaults to "Date".

    "DATE_COLUMN": "Date"
  6. Provide SYM_LIST: Specify the path to your watchlist file. This file should contain one symbol per line.

    "SYM_LIST": "path/to/watchlist/file"
  7. Set 24_7 (Optional): If the market operates 24/7, set this to true. Otherwise, set it to false and provide the EXCHANGE_START_TIME.

    "24_7": false
  8. Specify EXCHANGE_START_TIME (If 24_7 is false): Provide the start time of the exchange in HH:MM format.

    "EXCHANGE_START_TIME": "09:30"
  9. Save the Configuration File: Save the user.json file with the specified settings.

You can create multiple config files for different data sources.

To use a config file other than user.json, use the -c or --config followed by the file path to your config file.

py init.py -c intraday-config.json

Configuring Optional Chart colors and themes

All chart configuration is nested within the CHART key. See example JSON config below.

{
  "DATA_PATH": "/home/benny/Documents/python/eod2/src/eod2_data/daily",
  "LOADER": "EODFileLoader",
  "DEFAULT_TF": "daily",
  "SYM_LIST": "/home/benny/Documents/python/stock-pattern/src/data.csv",
  "CHART": {
    "TYPE": "candle",
    "STYLE": "mike",
    "LINE_COLOR": "gold",
    "LABEL_COLOR": "white",
    "BIAS_LINE_COLOR": "lime",
    "NAV_TITLE_COLOR": "snow"
  }
}

Image below points out the various chart options and how they apply on chart.

Chart Option Fields

For a list of available colors supported in matplotlib: https://matplotlib.org/stable/gallery/color/named_colors.html#css-colors

  • TYPE: One of candle, ohlc or line. Default candle
  • STYLE: One of binance binancedark blueskies brasil charles checkers classic default ibd kenan mike nightclouds sas starsandstripes tradingview yahoo. Default tradingview.
  • LINE_COLOR: Default midnightblue.
  • LABEL_COLOR: Text label color. Default midnightblue.
  • NAV_TITLE_COLOR: Title color in top left corner. (Used to display chart count). Default black.
  • NAV_STATUS_COLOR: Title color in top right corner. (Used to notify At last chart or At first chart). Default crimson.
  • BIAS_LINE_COLOR: Line color indicating direction of pattern breakout. Default green.
  • LINE_WIDTH: Applies to all lines on chart. Default 0.8.
  • ALPHA: Line color transparency. Default 0.7.

TROUBLESHOOTING

OHLC data must be a CSV file and contain Open, High, Low, Close, and Volume columns to work correctly.

Windows users - Use forward slash / in your file paths to avoid JSON parsing errors. ~/path/to/folder