Pre-market range

A custom indicator created by TrendSpider on TrendSpider. You can import this script into your TrendSpider account. Don't have TrendSpider? Create an account first, then import the script.

Chart featuring the Pre-market range indicator

Source code

This indicator had been implemented by TrendSpider in JavaScript on TrendSpider. Check out the developer documentation to learn more about JS on TrendSpider.

describe_indicator('Pre-market range');

//    30 is the highest time frame which still has candles not overlapping with
//    the market session
const extHoursData = await request.history(constants.ticker, '30', { ext_session: true });

const preMarketRangeByDay = {};

//    first, we compute { high, low } of pre-market
//    per each day we have in our ext data session
for (let extHoursIndex = 0; extHoursIndex < extHoursData.time.length; extHoursIndex += 1) {
    const sessionAtCandle = session_of(
        extHoursData.time[extHoursIndex],
        constants.resolution,
        constants.ext_session_premarket
    );

    const dayOfCandle = sessionAtCandle.session;

    if (!preMarketRangeByDay[dayOfCandle]) {
        preMarketRangeByDay[dayOfCandle] = {
            high: extHoursData.high[extHoursIndex],
            low: extHoursData.low[extHoursIndex]
        };
    }
    else {
        preMarketRangeByDay[dayOfCandle].high = Math.max(preMarketRangeByDay[dayOfCandle].high, extHoursData.high[extHoursIndex]);
        preMarketRangeByDay[dayOfCandle].low = Math.min(preMarketRangeByDay[dayOfCandle].low, extHoursData.low[extHoursIndex]);
    }
}

const rangeHigh = series_of(null);
const rangeLow = series_of(null);

//    now we assigning "pre-market high/low range" to each candle on the chart
for (let candleIndex = 0; candleIndex < time.length; candleIndex += 1) {
    const sessionAtCandle = session_of(time[candleIndex], constants.resolution);
    const extHoursRange = preMarketRangeByDay[sessionAtCandle.session];

    if (extHoursRange) {
        rangeHigh[candleIndex] = extHoursRange.high;
        rangeLow[candleIndex] = extHoursRange.low;
    }
}

fill(
    paint(rangeHigh, { hidden: true, style: 'ladder' }),
    paint(rangeLow, { hidden: true, style: 'ladder' }),
    'blue'
);