Simple strategy, seemingly complex solution.

J2theR

New member
VIP
Need a bit of help or at least someone put eyes on my code (shown below). Appreciate any suggestions. Embarrassed to admit have already spent over 30 hours on this. Thanks in advance!

Background: I'm well versed in TOS but recently started coding with thinkscript to check strategies.

Goal: With this strategy, I want to look at entering a long or short position when the price moves a predefined distance from its price at a certain time of day. Then once I enter a trade, execute an OCO bracket set at predefined limit/stop. Seems pretty straightforward, but am getting errors. I also want to evaluate this strat at the longest possible timeframe (at least a year) and make trade entry/exit decisions on the shortest possible timeframe (1 min or less).

Test environment: Using onDemand of course and set most of my variables to plot so I can debug.

Errors/Challenges:

1. It seems that if I use the 1 min timeframe for evaluating price to trigger the trade, I can't increase my chart timeframe to evaluate P&L on the strat. When I increase timeframe, the strat doesn't appear to run. I did read that TOS won't let you add data from smaller timeframes to larger timeframes on charts, but evaluating P&L's on larger timeframes must be do-able for strategies that depend on small timeframes to trigger actions.
 
Last edited:
Solution
And now for an even more complex solution:

For back testing something like this over the timeframe you're envisioning ToS is not going to make you a happy camper. You'd be better served working on some python code.
Some pre-built options for tools are:
https://pypi.org/project/Backtesting/
and a big rundown here:
https://www.qmr.ai/best-backtesting-library-for-python/

Of course, you can't readily get a year of 1m data out of ThinkOrSwim. You can (or could -- don't know the current state) get 7 days of 1m from Yahoo Finance (look for yfinance for python) and up to 60 days of 5m data.

You can buy data from 3rd party brokers, or use some of the 'export' scripts from this site to get data out of ToS and into a...
And now for an even more complex solution:

For back testing something like this over the timeframe you're envisioning ToS is not going to make you a happy camper. You'd be better served working on some python code.
Some pre-built options for tools are:
https://pypi.org/project/Backtesting/
and a big rundown here:
https://www.qmr.ai/best-backtesting-library-for-python/

Of course, you can't readily get a year of 1m data out of ThinkOrSwim. You can (or could -- don't know the current state) get 7 days of 1m from Yahoo Finance (look for yfinance for python) and up to 60 days of 5m data.

You can buy data from 3rd party brokers, or use some of the 'export' scripts from this site to get data out of ToS and into a spreadsheet.

The basics are that, while your strategy is simple to describe, writing code to do it is not an easy thing. And while you're at it, python will allow you to test a variety of parameters for tuning your strategy.

There are many good user groups out there that can help you with this, including a few of us around here.

Good luck, and let us know what you decide to do and how it goes.
-mashume
 
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
359 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