Back Testing Indicators For Optimal Parameters

GiantBull

Member
There are plenty of different kinds of indicators that have default values inputted in. For example the MACD default settings are 12,26,9 which have been proven to not be profitable in multiple studies. Those parameters worked in the 1980s when the indicator was invented but during this era using those settings will ultimately be a losing strategy. In order to find the optimal parameters for MACD (or any other indicator) backtesting needs to be done to find the most profitable parameters. I want to test numbers 1-100 for each setting on the MACD to find the best combo. Does anyone know of a program where this could be done? Do you need to have extensive knowledge on coding to do this by yourself? I have heard of genetic algorithms that do this kind of testing but have no idea on how it is done. If someone on here has any sort of knowledge in this area I could use the help!

https://medium.com/swlh/how-to-opti...rameters-with-genetic-algorithms-23671d7b446c
Here is an interesting article explaining what genetic algorithms are!
 
Solution
The answer is probably in python. The problem is in limiting the number of variables you want to work with. for even a simple strategy involving, lets say the MACD, your variables are:
  • candle timeframe
  • 3 MACD lengths
Getting loops set up to go over the MACD variables isn't difficult:
Code:
for x in range (10, 15):
    for y in range (20, 30);
        for z in range(5, 11):
            #do your test here and store returns in a table you can evaluate later for profit/loss drawdown etc...
nested loops are slow but should finish for this reasonably, if you're not testing on 2 years of 1 minute data.

which brings us to the crux of the problem. There is a python package called yfinance which allows you to grab data from...
The answer is probably in python. The problem is in limiting the number of variables you want to work with. for even a simple strategy involving, lets say the MACD, your variables are:
  • candle timeframe
  • 3 MACD lengths
Getting loops set up to go over the MACD variables isn't difficult:
Code:
for x in range (10, 15):
    for y in range (20, 30);
        for z in range(5, 11):
            #do your test here and store returns in a table you can evaluate later for profit/loss drawdown etc...
nested loops are slow but should finish for this reasonably, if you're not testing on 2 years of 1 minute data.

which brings us to the crux of the problem. There is a python package called yfinance which allows you to grab data from yahoo. It's good enough data, but is limited in the length of what you can retrieve to the last 60 days for intraday.

There are a few good packages for indicators which will run on top of a pandas data frame (which is what yfinance will return).

If all of this is too much for you to undertake I understand. It's a lot of work to backtest so thoroughly. Backtesting is probably an art unto itself and deserving of a grander thread and some code... someday I may work on something for the community when I have time

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