Charting synthetic data

M T

New member
VIP
Hello, I've been frustrated a how different the TOS Hull moving average is compared to hand-coded versions (this has been noted by others on previous threads).

To try to nail down the discrepancies I want to create and chart synthetic data and apply the TOS Hull to it. (Code below)

Once I have the synthetic data in the chart and am applying the Hull to it:

I can't find in Chart Settings how to hide the original price data. Any help is greatly appreciated, thanks!


Code:
# Inputs
input period = 20;      # Number of bars for one full sine wave cycle
input amplitude = 200;  # Adjust amplitude for the sine wave
input hullPeriod = 13;  # Period for the Hull Moving Average

# Calculate bar-based frequency
def barIndex = BarNumber();                   # Get the bar number
def normalizedIndex = barIndex - Floor(barIndex / period) * period;  # Modulus operation
def angle = normalizedIndex * 360 / period;   # Calculate angle in degrees

# Generate sine wave
def SyntheticData = amplitude * Sin(angle * Double.Pi / 180);  # Convert angle to radians

# Apply Hull Moving Average
def wma1 = WMA(SyntheticData, hullPeriod / 2);                 # WMA with half the Hull period
def wma2 = WMA(SyntheticData, hullPeriod);                     # WMA with the full Hull period
def hullMA = WMA(2 * wma1 - wma2, Sqrt(hullPeriod));           # Hull Moving Average formula

# Plot synthetic data and Hull MA
plot OriginalSyntheticData = SyntheticData;
OriginalSyntheticData.SetDefaultColor(Color.CYAN);
OriginalSyntheticData.SetLineWeight(2);

plot HullMovingAverage = hullMA;
HullMovingAverage.SetDefaultColor(Color.MAGENTA);
HullMovingAverage.SetLineWeight(2);
 

Attachments

  • Screenshot 2025-01-05 at 2.10.34 PM.png
    Screenshot 2025-01-05 at 2.10.34 PM.png
    281.7 KB · Views: 89
Last edited:
Solution
As I understand the question, you're asking how to scale the data for visibility's sake, and hide the price bars. HidePricePlot(); will hide the price bars, but the chart's original scaling remains intact when you do that. I believe the best solution would simply be to Declare Lower;.

TWOO5Tw.png
Hello, I've been frustrated a how different the TOS Hull moving average is compared to hand-coded versions (this has been noted by others on previous threads).

To try to nail down the discrepancies I want to create and chart synthetic data and apply the TOS Hull to it. (Code below)

Once I have the synthetic data in the chart and am applying the Hull to it:

I can't find in Chart Settings how to hide the original price data. Any help is greatly appreciated, thanks!
"...chart synthetic data..." : please define for clarification.

Something like this ?:

1736127079382.png


"
 
  • Like
Reactions: M T
As I understand the question, you're asking how to scale the data for visibility's sake, and hide the price bars. HidePricePlot(); will hide the price bars, but the chart's original scaling remains intact when you do that. I believe the best solution would simply be to Declare Lower;.

TWOO5Tw.png
 
Solution
As I understand the question, you're asking how to scale the data for visibility's sake, and hide the price bars. HidePricePlot(); will hide the price bars, but the chart's original scaling remains intact when you do that. I believe the best solution would simply be to Declare Lower;.

TWOO5Tw.png
Thanks @Joshua and @Carl-not-Karl for your helpful replies. One further question:

Is there any way to output the values of the Hull moving average bar by bar to a file?
 
what makes you think a sine wave should be the same as an average line?
I'm trying to diagnose why hand-coded versions of the Hull moving average don't yield the same results as hand-coded versions using the standard formula. Therefore I'm testing the TOS Hull on various types of synthetic data, including sine waves. I'm not expecting the sine waves and the Hull to be the same.
 
Is there any way to output the values of the Hull moving average bar by bar to a file?

Not with thinkscript. There are no file read/write functions or anything remotely similar to that.

You can export a watch list to excel. You might be able to use a series of custom columns in a watch list, each individually hard-coded to a different offset of the hull.

I suppose you could also write external software to check the pixel color at exact screen coordinates.

So I wouldn't say it's impossible, but it's certainly not practical.
 
Not with thinkscript. There are no file read/write functions or anything remotely similar to that.

You can export a watch list to excel. You might be able to use a series of custom columns in a watch list, each individually hard-coded to a different offset of the hull.

I suppose you could also write external software to check the pixel color at exact screen coordinates.

So I wouldn't say it's impossible, but it's certainly not practical.
One thing I did figure out as a kludge: force a trade in a strategy every day and then write the value of the indicator you're interested in into the price field (for the .csv that can be downloaded). Not pretty, but makes writing data possible.
 

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
391 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