Market Hours and the Charts

The charting library is Market Hours aware and uses that information to determine if there are any gaps in the data, as well as where the next and previous ticks should be.

Since different markets have different hours, it is important that instruments are properly identified, or the wrong schedule may be leveraged.

The following tutorial reviews existing identification methods and provides direction on how to properly adjust them to meet your needs. Or turn them off and default to all day trading.

Please Note that as of version 04-2016-08 a new Market class replaces LegacyMarket class. If calling any functions from LegacyMarket, please replace them with equivalent Market functions. The Market class now allows a market's hours and holidays to be defined with a market definition file. Market iterators allow you to move forward and backward in time, with the Market automatically skipping over time when the market is closed. See STX.Market for all instructions and details.

Market Hours

The system includes built in logic which supports US Equity market holidays and hours as well as Forex and Futures markets that trade 24 hours.

It is important that the library knows how to properly identify your symbols. Please refer to the "Instruments Identification" section for further details

By default the chart is set to display 24 hours trading sessions for all instruments.

Manual market hours override

You can manually override these default market hours by changing the following parameters immediately after instantiating your chart ( new stxChart) , or every time a new instrument is loaded:

  • stxx.chart.beginHour
  • stxx.chart.beginMinute
  • stxx.chart.endHour
  • stxx.chart.endMinute

Important: All parameters must be specified in Eastern Time (New York)


// Declare a STXChart object. This is the main object for drawing charts
var stxx=new STXChart({container:$$$(".chartContainer"), layout:{"candleWidth": 16, "crosshair":true}});

// Set market hours to 9:30 AM to 4:00 PM ET 
// these hours will remain in place, regardless of instrument, until replaced.
stxx.chart.beginHour= 9;
stxx.chart.beginMinute= 30;

Automatic Market hours

Alternatively, you can allow the chart to automatically derive its own market hours using the built in logic. This is done by setting the above 4 parameters to null. Once automatic market hours are set, they will continue to be used for every new symbol activated with the newChart() function, even if you manually set the above parameters before calling newChart(). If you wish to deactivate automatic market hours after they have been activated, you must also set stxx.automaticMarketHours=false; then newChart() will once again start using the parameters.

Additionally, you can override or modify all of the built in logic as needed to support international exchanges or other markets.

The following functions are responsible for managing the built in logic:

  • STX.LegacyMarket.isAfterMarket
  • STX.LegacyMarket.isAfterDelayed (adjusted for 20 minute delayed quotes)
  • STX.LegacyMarket.isForexOpen
  • STX.LegacyMarket.getNextOpen (will return official closing time regardless of the market hours set in stxx.chart.beginHour and stxx.chart.beginMinute)
  • STX.LegacyMarket.getPreviousClose (will return official closing time regardless of the market hours set in stxx.chart.endHour and stxx.chart.endMinute)
  • STX.LegacyMarket.getHours (returns official trading hours for different security types - used when no override times are defined)
  • STX.LegacyMarket.isMarketDay
  • STX.LegacyMarket.isMarketOpen

STX.LegacyMarket.initializeHolidays should also be reviewed yearly and kept up to date with full or partial market closings.

Note 1 If you wish to by-pass the market sessions hours and holidays logic, simply set the calendarAxis flag to true, right after declaring your chart object, and your chart will treat all hours as market hours.

For example:

var stxx=new STXChart($$("chartContainer"));

Note 2 The chart will draw all of the data you send it, regardless of market hours. The market hours settings are designed to find the next appropriate time/tick if no data is sent for that period. As such if you send 24 hours worth of data, the chart will display it all, including the data corresponding to times when the markets are close.

Instruments Identification

Instruments identification is done by the following functions located in stx.js. They should be overwritten as needed to comply with your quote feed symbol identification method. This could be done via symbol format matching or a source/type ID, if your feed provides this data.

The following is an outline of the current logic embedded in the library by default:


    Identification is done trough symbol format matching
    It must ***not***  contain a dot (.) or a forward slash (/) 
    must be 6 characters (no numbers) with an optional extra '^' prefix

    Example : 'AbcDEF' or '^aBCdEf'


    Identification is done trough symbol format matching
    Must be a forex symbol, as per above definition
    either end or begin with  XAU, XPD, XPT or XAG

    Example : 'AbcXDP' or '^XAGdEf'


    Identification is done trough symbol format matching
    Must begin with a forward slash (/)
    have at least one more character

    Example : '/A' or '/a1C'


    Identification is done trough symbol format matching
    Must contain a dot (.)

    Example : '.XXXX' or 'XX.XXX'

Please carefully review and modify the above methods as needed to ensure the charting library can properly identify the symbol type and its corresponding market hours.

Data gaps cleanups

The charting library works best when there are no gaps in the data during the set market hours for the active instrument. Sometimes lightly traded instruments will not have every expected tick. To address this, the library can automatically add any missing ticks (set to mimic the last tick). This behavior can be enabled by setting the cleanupGaps flag to true

For example:

var stxx=new STXChart($$("chartContainer"));

See STXChart#doCleanupGaps and STXChart#cleanupGaps for additional details.