How ThinkOrSwim Processes Missing Data Bars

Hello Everyone,

I hope you're all doing well. I've been exploring the ThinkOrSwim platform and encountered a question that I haven't been able to resolve through documentation or other resources. I apologize if I'm missing something obvious here.

To illustrate my question, I'm using a script that calculates the Exponential Moving Average (EMA) based on the last 20 bars. The script is straightforward:

Code:
// Script to calculate the Fast Exponential Moving Average (EMA).
input fastLength = 20;
script calc_fastEMA {
    input source = close;
    input length = fastLength;
    def fastMA = MovAvgExponential(source, length);
    plot out = fastMA;
}
def fastEMA = calc_fastEMA(close, fastLength);
plot FastEMAPlot = fastEMA;
FastEMAPlot.SetDefaultColor(Color.BLUE);

This script computes the EMA from the closing prices of the past 20 one-minute bars. However, my query arises in situations where there is a lack of trading activity for a specific bar. For instance, consider a scenario where there's no trading at 1:45 PM, within the 1:40-2:00 PM window.

My question is: How does ThinkOrSwim handle such missing data in its EMA calculation?

  1. Does it perform a forward-fill, using the close price of 1:44 PM as the price for the missing 1:45 PM bar?
  2. Or does it include an earlier bar (like the 1:39 PM bar) to ensure that the EMA is calculated over a full set of 20 bars with trading activity?
I'm trying to understand the underlying mechanics of the EMA calculation in the context of missing data. Any insights or pointers to relevant documentation would be greatly appreciated.

Thank you in advance for your help!
 
Solution
Depends.

Under normal circumstances, the chart itself will simply skip time from 1:44 to 1:46 without an empty space appearing in between. The average is then calculated based on the most recent 20 available bars, which ever bars those might be.

But it's different when you're referencing a secondary symbol, and there is data for the primary symbol, but no data for the secondary symbol. In that case, the secondary reference returns Double.NaN which breaks the calculation if not handled. The usual method, in that case, is to do the forward fill, but you must do it yourself.

if isNaN(value) then value[1] else value

For the reverse, if there is no data for the primary symbol, but there is data for the secondary symbol, then there is no...
Depends.

Under normal circumstances, the chart itself will simply skip time from 1:44 to 1:46 without an empty space appearing in between. The average is then calculated based on the most recent 20 available bars, which ever bars those might be.

But it's different when you're referencing a secondary symbol, and there is data for the primary symbol, but no data for the secondary symbol. In that case, the secondary reference returns Double.NaN which breaks the calculation if not handled. The usual method, in that case, is to do the forward fill, but you must do it yourself.

if isNaN(value) then value[1] else value

For the reverse, if there is no data for the primary symbol, but there is data for the secondary symbol, then there is no attempt at all to access the secondary symbol during those periods. It will only access the secondary data that directly corresponds to the primary.
 
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
337 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top