Sapphire Strat Maker – Insights into Strategy Optimization and Efficiency (Part IV) – Trading Strategy – March 14, 2024
1. Introduction
This is what follows sapphire strat maker and Sapphire Strat Maker Alt (Free) Expert Advisor – This is an EA that allows you to create your own strategy without coding. That’s the beauty of this expert advice. Create your own strategy, be creative and no longer be tied to a single strategy. Optimize the parameters to find the best set and you are ready to go!
Check out our other blog posts before continuing.
2. Insights during and after strategy optimization
In my experience, optimizing your strategy is not as easy as it looks. You can set a large range for the parameters being optimized, wait for the optimization to complete, and then select the most profitable parameters. This may not be the best option for you.. Finding the best parameters can actually be very risky. overfitting. There is a proverb in Portuguese that can literally be translated as follows: “Perfect is the enemy of the optimal, and optimal is the enemy of the good.” This means that you may find the perfect parameters, but you may also overfit them. This is a backtest period where you will lose more than you will win.
But what is overfitting? overfitting This means optimizing your strategy too much so that it only works for certain periods of time. cannot generalize When new data comes.
Avoid overfitting Although it is a very difficult task, there are some simple things you can do to reduce its impact. Let’s look at a few of them. As I said, simple things can reduce the risk of overfitting. We’ll also look at other ideas on how you can pursue your strategy with maximum efficiency.
This is a comprehensive list on this topic. There may be more blog posts about this.
2.1. forward testing
Metatrader 5 offers excellent features for Expert Advisors. Forward testing is one of them.
Forward testing reduces the likelihood of overfitting by: blind test It uses parameters found in previous tests from a certain period of time (hence the name). However, to achieve maximum efficiency from forward testing, an appropriate time period must be defined. Market conditions change with market cycles, so today’s market is not the same as it was 10 years ago, and neither are the players.
I defined my own rules through testing. You can define your own too. But my backtesting period is basically defined as:
period | period |
---|---|
M1~M10 | 1 year backtest + 1 year forward test (2 years total) |
M12~M20 | 1.5 years backtest + 1.5 years forward test (3 years total) |
M30~H2 | 2 years backtesting + 2 years forward testing (4 years total) |
H4~D1 | 2.5 years backtesting + 2.5 years forward testing (or more) (total = 5 years or more) |
This allows us to define a reasonable period of time with a sufficient amount of data, neither too little nor too much. Of course, you can also adjust it according to your experience.
Another idea is Second forward test. MT5 doesn’t provide this, but you can do it manually. You don’t normally do this, but it’s a good idea if you want to feel safer. However, please note that changing market conditions over the years may make it more difficult to find a strategy that works.
2.2. Optimized parameter range
Price movements tend to follow a certain logic. The challenge is to identify this logic as it arises, taking into account that it may change depending on market conditions. For example, a particular instrument in a particular period may consider a particular moving average as support/resistance, while the same instrument in a different period may not.
Anyway, the players are made up of humans and robots (developed by humans). Their strategies may vary, but they always follow a certain logic. Most quantitative strategies are: Logical numbers.
What price is most likely to occur? Is the price holding the 20-day moving average as support/resistance, or the price holding the 279-day moving average? Of course the first one. There is a reason. This is a logical number used by many traders/robots. It is expected that the price will reach that level and react in some way, such as breaking it or reversing it.
Always apply logic when choosing parameters. However, this is not always possible.
Let’s say we want to choose the optimal parameters in a moving average. What should I do? We recommend setting the range for the Period parameter from 1 to 300 in steps of 1 for best results.
no. think logically. Do you really need such a large scope? Generally not.
The best option is to use rounded numbers such as 10, 20, 30, 40, etc. For example, these numbers are most likely to have an impact than the meaningless 134 period. You can also select parameter values via Fibonacci numbers (1,2,3,5,8,13, etc.), although this is not possible with the MT5 optimization function.
By limiting optimization possibilities, Reduce the risk of overfitting, Because what you want are good parameters, not perfect parameters for the test period.
2.3. The best is not the best
As I said a few times here following the last paragraph, You may not want perfect parameters.. You are likely overfitting during your testing period.. Still, if you want to use the best one, Shorten the expiration date Learn about the strategies described in the next section.
Take this first. Here’s the strategy I’ll show you later in this post:
Highlighted are the best results from the backtest (1 year). Let’s take a look at the results of future testing (1 year).
Although still profitable, the results are far inferior to backtesting. complex criteria. If we had not used forward testing, we would have made a profit after a one-year backtesting period, but it would have been much less than before. The strategy clearly overfitted during the backtest period.
Then what we do is forward test Click on the tab and compare your results with the Backtesting tab results. What you can see in the following images are some nice results, but one caught my attention.
When to use complex standards, Values above 75 are Pretty good. Values greater than 90 can be considered overfitting, but are still good. Values greater than 95 are probably overfitting and should not be used. The highlighted results show a backtest result of 81.65/89.65 and a forward test result of 83.11. Similarity in results means the strategy is consistent and maybe Great to use.
Lastly, please know Optimization criteria You are using I think it’s best to use Complex standards. If you use balance, drop, recovery factors, etc., don’t just pick the best of the results.
2.4. Over time, your strategy won’t work.
Who doesn’t love a strategy that works forever? Even if that kind of holy grail exists (I won’t cover this topic here), it’s incredibly difficult to achieve. 99.99% strategy There will be an expiration date. The remaining 0.01% is unusable by mere mortals and designed by geniuses who never really share their secrets. (Jim Simmons). One day they will stop working. They ‘die’ just as they were born. Like humans, we cannot know when something will happen, but we can define objective conditions. ask Or rework your strategy.
First, you can specify: expiration date About that specific strategy. Let’s say you want to optimize your strategy using the table shown above. After finding the optimal parameters, you can set them to work for 1/2 of the test period (for example, if you created a strategy for M10, at least one year). This may change depending on the outcome of the strategy (e.g. if the strategy: ~ degrees lots of dealsThis time can be reduced by 1/4). After this period, do not trade any more until you re-optimize or find another strategy.
Second, define the maximum drawdown of your strategy in real trades. A safe decision is to limit life to the maximum reduction based on testing. If your strategy has a very low loss rate, you can define the real-time trading loss rate in your backtest as 2 times the DD. This defines the conditions under which you will not take larger losses.
Third, we also define the maximum benefit for the strategy. As I said, the strategy is won’t It may not work forever. Once a certain profit is reached, new data collected during that period is used to find a different strategy or re-optimize it. Don’t use the market as a casino.
3. Strategy establishment and optimization
Let’s put that idea into practice.
First, we define the tools and timescales. For this experiment, we will choose the NZDUSD pair on the M10 period.
Second, let’s choose an indicator. In this case, these are the moving averages (defining the trend), the Commodity Channel Index (CCI – defining the possible reversion levels) and the ADX (defining the strength of the trend).
Since we want to define the trend, for now It doesn’t matter whether the trend is short-term, medium-term, or long-term.Let’s set the optimization range. MA period It consists of 10 levels ranging from 20 to 200.
The most common CCI value is 14. The optimization range is 8 to 20 (6 periods below, 6 periods above), so it is fair to use it as level 1.
The most common ADX value is also 14. Let’s use the same logic as CCI.
We’re dealing with a simple strategy. On a bullish reversal while CCI is below the 0 level, if the close is above the moving average and ADX is above the 35 level, we have Long position. When there is a downward reversal while CCI is above the 0 level, the close is below the moving average, and ADX is above the 35 level, we Short position.
It also stops trading when it reaches a certain profit/loss within a month. This amount ranges from U$ 10.00 to U$ 100.00.
Take Profit is defined as a certain number of ticks (25 steps) for the entry price level ranging from 50 to 500. Stop loss is defined as the risk of take profit and ranges from 0.25x to 1x. tp, step 0.05.
The parameters of the indicator are:
Entry conditions are set as follows:
We also optimize the minimum level of ADX (ranging from 20 to 50) in five steps.
Take Profit and Stop Loss levels are defined as follows:
Finally, money/risk is defined as:
After optimizing for 2 years (1 year for backtesting, 1 year for forward testing) complex criteria at Fast genetic-based algorithm I found the following interesting results across optimization types (your results may vary due to different brokers + how fast genetic algorithms work):
As you can see, here are some good parameters:
moving average period = 100;
CCI duration = 9;
ADX period = 18;
ADX min level = 35;
Take profit at entry price = 350;
Stop Loss Risk (1:x of TP) = 0.85 (i.e. stop loss is 350 * 0.85 ticks)
Stop period after P&L = Stop every month
Maximum profit = U$ 20.00
Maximum loss = U$ 40.00
The results for this are as follows:
However, these parameters could be more logical. Let’s see.
The ADX period can be 20 days. It’s closer to a logical parameter as far as I can see.
Nine cycles of CCI is already a good number.
It makes no sense to place the stop loss risk at 0.85. Let’s round it to 0.8 or 0.9. I’ll set it to 0.8.
The maximum profit/loss was set at 1:2. This is actually reasonable, but if the risk is 1:1 or less, it is better to have a winning strategy. I’ll set both to 20 or 40. I’ll set it to 40.
The new results are:
We achieved better profits, but the downside was that our losses also increased. it’s okay. Because it looks like we’ve got really good parameters and it’s likely that this strategy will work for a while. Again, this is not a recommendation. This strategy may or may not work in live trading. This is just an insight/idea on how to get a chance to create a good strategy.
The next blog post will cover my strategy types and my process for thinking about them.
If you have any questions, please feel free to contact us.