Buy the Dip Backtesting Strategy for ThinkorSwim

thebewb

Member
All,

Developed a strategy within ToS based off Ben's Buy The Dip indicator.

See summary below:

Position Entrance

1. Uses 8 and 21 EMA at a higher aggregation (which is selectable by user)to determine if stock is in an uptrend or downtrend. If 8 is above 21 then the underlying is considered to be in an uptrend and vice versa. I would use a timeframe that is 5-10 times higher for this.
2. Based off the trend identified in #1, the strategy will either Buy The Dip when in an uptrend or Sell The Rip when in a downtrend.
3. I added functionality based off Ben's "Conservative" iteration of this indicator. If you select "Yes" in the Conservative input then strategy will only enter a position if at least 2 out of 3 of the BTD or STR values are below and above, respectively, the defined threshold, which I have set at .01 and -.01. You can change the threshold to be more aggressive or conservative based off your risk profile. Ben's original default was set to 0.

Position Exit

1. I used Mobius's SuperTrend formula to determine exits e.g., when price closes above or below last bar's calculation. Feel free to mess with these inputs based off your trading style. I have found a multiplier of 3 and period of 6 work best for 30min time frame. I would tighten it up on the higher timeframes.

Other

For the shortest BTD and STR values, I calculated an overbought or oversold ratio that can be used in conjunction with the signals given. Basically it will show as overbought or oversold if the current reading is greater than the "extr" percentage input. If you have the useExtr input turned to yes, this will plot on the upper chart as orange for overbought and cyan for oversold. It will plot green if BTD signals and the ratio is oversold and red if STR signals and the ratio is overbought. You can change the length of the lookback used to determine OB or OS in the applicable input. I used 100 but that is based off my default of using this on the 30 min.

When underlying is not deemed overbought or oversold the line is colored either light green or light red. It will be light green if the most recent signal was a STR and light_red if the most recent signal was BTD. I use this to determine how strong the stock movement is. It seems counterintuitive but the way I look at it is the stock is strong when STR signals and weak when BTD signals, so just wanted to capture that data. You can turn off this functionality by selecting No in the useExtr input.

If you are backtesting different inputs select Yes in the futures input if you are backtesting futures and No for all others. I trade options, so i added the Contracts input to model profitability based off trading a number of options contracts that are high delta. This backtests very nicely on equities and futures. As previously stated, I prefer using it on the 30min but obviously you can use it however you want.

This is a great tool, but obviously there is no holy grail. Please let me know if you have any questions.

See screenshots below:

AMZN - Daily w/ Weekly Agg EMAs showing and SuperTrend set at a multiplier of 2 and period of 4.



TSLA - 30min & 30 days w/ daily agg EMAs determining trend and SuperTrend set at multiplier of 3 and period of 6.



NQ Futures 30 min 30 days


Code:
This content is only accessible to VIP members.
Upgrade your account

Or Learn more.

 
Last edited:

Tradervic

Member
VIP
Hi thebewb, thanks for sharing your thoughts on this. A couple of questions.
1) Uses 8 and 21 EMA at a higher aggregation. Does this mean that on a daily chart, you are using EMAs from a weekly chart?
2) useExtr. I believe this is in your code above and not in Ben's or Boar's code. Correct?
3) You provided the backtesting script. Is that to create the chart above or does it actually do backtesting to see how profitable the system is?
Thanks for your time!
 

thebewb

Member
Hi @Tradervic

1. You will need to manually select higher aggs depending on your chart time frame. Yes for daily I would use weekly.
2. Correct. This plots the overbought/oversold signals and if stock is strong or weak relatively speaking
3. The backtesting script title shouldn't be in there. The script provided needs to be added as a strategy and then it will plot entries and exits and you can backtest it yourself using ToS's functionality.
 

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