Enhancing Stability and Robustness of Automated Trading Robots: Strategies, Challenges, and Insights

 
 What strategies and techniques do you recommend for increasing the stability and robustness of automated trading robots in financial markets? Can you share your experiences and insights?

In automated trading, maintaining stability and robustness is crucial for long-term success. It would be great to hear from the community about the strategies and techniques they have found effective in achieving this goal. Additionally, please share any experiences, challenges, or insights you have gained while developing and improving automated trading robots.

To kick off the discussion, I would like to suggest one solution: implementing proper risk management techniques. Managing risk is vital to protect your trading capital and ensure the longevity of your trading system. What risk management strategies have you found effective in your automated trading endeavors? Are there any specific techniques or rules you follow to mitigate potential risks?

I invite all members of the MQL5 community to contribute their experiences, recommendations, and insights regarding strategies to enhance stability and robustness in automated trading systems. Your valuable input can greatly benefit others and foster a lively and informative discussion.
 
Soraya Bahlekeh:
 What strategies and techniques do you recommend for increasing the stability and robustness of automated trading robots in financial markets? Can you share your experiences and insights?

In automated trading, maintaining stability and robustness is crucial for long-term success. It would be great to hear from the community about the strategies and techniques they have found effective in achieving this goal. Additionally, please share any experiences, challenges, or insights you have gained while developing and improving automated trading robots.

To kick off the discussion, I would like to suggest one solution: implementing proper risk management techniques. Managing risk is vital to protect your trading capital and ensure the longevity of your trading system. What risk management strategies have you found effective in your automated trading endeavors? Are there any specific techniques or rules you follow to mitigate potential risks?

I invite all members of the MQL5 community to contribute their experiences, recommendations, and insights regarding strategies to enhance stability and robustness in automated trading systems. Your valuable input can greatly benefit others and foster a lively and informative discussion.
One thing that comes to mind is after I had accidentally set the execution delay in strategy tester to random, I noticed lots of errors and had to fix quite some code to make it robust.

Also I designed my Algo in such a way that it is stateless. So whatever happens, when I kill the EA and restart it, it will pick up exactly where it should. Any details or information is reconstructed from "scratch" so that the Algo is independent of any saved states.

Something a lot of coders do not do is go through the "Checks a Robot must pass" which is contributed by MQL whenever you want to upload an EA to the market.

Also an EA should be able to run on any symbol. It should be coded in such a way that your code adapts to the symbols and accounts specifications.

You should have comprehensive logging in such a way that whatever the robot is doing, you can reconstruct from the logs what exactly it did to open, close a position.

Also it helps finding if your signals got executed in how you want them to be triggered.

I periodically save a template from the chart to keep any objects the EA draws onto it as a reference. This I can load onto a chart and then I can sync this with my logs so that I know exactly what has been going on.

I have some additional logs to store details, like a slippage and execution and network connection log. But these are details, depending on how your Algo works. It might not be relevant to you.

I suggest also to include some checks like accidentally starting the Algo on same symbol and timeframe twice. More difficult is to prevent an EA running on two different machines but on the same account and symbol and timeframe, but I guess checking for every possible use error is sometimes not possible or practical. I use a heartbeat method to perform such a check.

I guess there are lots of more checks you could include. I personally implemented prop firms rules as well, with the possibility to set other parameters to these rules. But in general their rules are not dumb and they can help to protect your account. So most of them, in slightly adopted way, I use these recommendations.

Some algorithms require quite some resources, so I also check the runtimes if my functions for anomality. I found it's a good rule of thumb, the usual execution paths average time should not exceed 5 * average time.

You will need to have some system in place for a graceful shutdown of your EA. How to stop it, if positions are open and being handled by your EA.

If you keep track of your SL in code, you should also keep a broker side SL, in case of outage.

Sometimes, if you have multiple positions,you might want to close the profits first and then the losses, to keep you away from stop outs. - Depends on your Algo of course.

OrderSend should be wrapped with a sanity check, to exclude crazy parameters. Something like: average lot you trade, max and min lot as well and keep your current lot request within a certain range of these values. Same could be done with SL and TP. Just in case you mess up some calculations somewhere.

For all these situations, you need a plan on how to handle them. - I suggest, if something like that happens to shutdown the EA so you can investigate on the happenings.

These are some of my ideas.


 

Forum on trading, automated trading systems and testing trading strategies

Can't Find Any Profitable EA on MQL5 in past 5 years.

Sergey Golubev, 2019.04.14 08:26

There are Raw Ideas. It is the ideas about the following: attach indicators to the chart and see that it may be profitable.

There are Elaborated/Proven Ideas. It is when someone was trading this indicators' setup during the several days/or weeks/or months on demo account (and, in some cases - on real live account). I am not talking abouty backtesting. Raw idea became to be a Elaborated Idea by trading (at least - on demo).
Why to trade? To define the trading rules, and to know: when the system will let you win, and when you will lose by using this system (and why).

  • Some people prefer to do it in public threads (coding, testing, trading) and finally - post/upload everything as the source codes on the public threads.
  • The other people are doing in privately (with no one can see it), and it is always about some kind of believing for example (do we trust those people or not).
  • And there are some people who do not do anything. They just attached indicators to the chart and see that it is good ...
 
Sergey Golubev #:
Crypto currency trading is just like any other business, but in this case more sophisticated and advanced. When you invest, your money goes through the stock market and is used for trades. A professional with many years of experience uses softwares in trading these currencies
 
Soraya Bahlekeh:
 What strategies and techniques do you recommend for increasing the stability and robustness of automated trading robots in financial markets? Can you share your experiences and insights?

In automated trading, maintaining stability and robustness is crucial for long-term success. It would be great to hear from the community about the strategies and techniques they have found effective in achieving this goal. Additionally, please share any experiences, challenges, or insights you have gained while developing and improving automated trading robots.

To kick off the discussion, I would like to suggest one solution: implementing proper risk management techniques. Managing risk is vital to protect your trading capital and ensure the longevity of your trading system. What risk management strategies have you found effective in your automated trading endeavors? Are there any specific techniques or rules you follow to mitigate potential risks?

I invite all members of the MQL5 community to contribute their experiences, recommendations, and insights regarding strategies to enhance stability and robustness in automated trading systems. Your valuable input can greatly benefit others and foster a lively and informative discussion.

I recommend checking the brokers spread etc and carrying out a genetic optimisation test. If possible carry out a monte carlo simulation and a what if scenario simulation. 

What I did with my bot. 

 
Dominik Christian Egert #:
Also an EA should be able to run on any symbol. It should be coded in such a way that your code adapts to the symbols and accounts specifications.

This was a big thing for me when I started coding my own EAs vs using ones from the Market or CodeBase. Many are coded to use points or pips/percentages as units for any kind of distance, i.e., not just stop loss or take profit, but the size of a candle, or the distance from a moving average, etc. The problem is that these units are radically different between different symbols and brokers.

For the most part, I now try to code everything either as an ATR multiple of some kind, so that it ports better from symbol to symbol without having to work so hard to try to even figure out the right range of values for a particular input. Sometimes, depending on the strategy and timeframe, that may mean using longer periods to calculate the ATR, e.g., if I'm trading on M1, I may use values of 60 on up to 240 for the periods for the ATR, so I have something more stable, less subject to momentary fluctuations.

Similarly, it's a good practice to always have an option for risk as a % of the account, or a fixed dollar/currency amount, not just fixed lot size. Again, this makes it much easier to apply to different symbols without worrying about screwing up the math.

 
Soraya Bahlekeh:
What risk management strategies have you found effective in your automated trading endeavors? Are there any specific techniques or rules you follow to mitigate potential risks?

The biggest risk in automated trading is always that past performance is no guarantee of future results, i.e., your live trading won't live up to your backtesting.

Besides the usual practices of backtesting in out of sample data and being careful not to overfit (that's a whole other discussion of its own), I've increasingly become mindful of the LR correlation metric in the backtest, and I'm planning to start implementing R-squared as a custom OnTester() metric. I've come to the point that I feel like optimizing for maximum consistency is more important than maximizing profitability.

I've also found that so long as a) the algorithm isn't overly complex, and b) it's at least moderately profitable with the default values, that algos that have a higher LR correlation / R-squared over a decent period of time (say, 3 years) tend to perform better on out of sample data, as well.

R-squared as an estimation of quality of the strategy balance curve
R-squared as an estimation of quality of the strategy balance curve
  • www.mql5.com
This article describes the construction of the custom optimization criterion R-squared. This criterion can be used to estimate the quality of a strategy's balance curve and to select the most smoothly growing and stable strategies. The work discusses the principles of its construction and statistical methods used in estimation of properties and quality of this metric.
 
Scott Allen #:

This was a big thing for me when I started coding my own EAs vs using ones from the Market or CodeBase. Many are coded to use points or pips/percentages as units for any kind of distance, i.e., not just stop loss or take profit, but the size of a candle, or the distance from a moving average, etc. The problem is that these units are radically different between different symbols and brokers.

For the most part, I now try to code everything either as an ATR multiple of some kind, so that it ports better from symbol to symbol without having to work so hard to try to even figure out the right range of values for a particular input. Sometimes, depending on the strategy and timeframe, that may mean using longer periods to calculate the ATR, e.g., if I'm trading on M1, I may use values of 60 on up to 240 for the periods for the ATR, so I have something more stable, less subject to momentary fluctuations.

Similarly, it's a good practice to always have an option for risk as a % of the account, or a fixed dollar/currency amount, not just fixed lot size. Again, this makes it much easier to apply to different symbols without worrying about screwing up the math.

My experience has shown the periods of ATR have only very little actual influence if it is not below 14.

I made multiple experiences and it shows to be the case 14 is actually the perfect amount of periods to consider. The more periods you use on a lower timeframe the more you have historic values in your current calculations, the less precise you adapt to the current market behavior.

If you plot two ATRs one with 14 and another with 1400 you can see, actually you get about the same values, but one reacts to current happenings, while the other ignores these.

Like the difference between Sydney and London/NY sessions. This is especially prevalent on time-frames H1 and lower.

But it all depends on your over all TA you apply.

The more general the approach is, the similar the results from your TA will get across different time frames, I noticed. When using a simple TA setup, something along ADX + MACD and counting the positions per candle over a fixed amount of candles, it will turn out to have similar outcome, independent of the applied time frame.

Which makes the argument, as said depending on your specific TA, using different periods for ATR (or any indicator in that matter) rather obsolete.

I guess it strongly depends on your approach. But for me, when looking at EAs from the market, and seeing they use a certain time frame, makes me think it's over fitted.
 
Dominik Christian Egert #:
My experience has shown the periods of ATR have only very little actual influence if it is not below 14.
...
I guess it strongly depends on your approach. But for me, when looking at EAs from the market, and seeing they use a certain time frame, makes me think it's over fitted.

Like you said, it depends on the strategy.

In some cases, like a trailing stop calculation, you may want it to be more reactive, even down to like 5 periods or so, so that it responds quickly to a consolidation.

In the case I described, I'm not trying to be reactive to current market conditions, but using ATR to easily get a sense of appropriate scale. I don't want to have to figure out the appropriate scale for stop loss in points on every symbol and timeframe I test on. Some, a range of 1-100 makes sense; others, it's more like 100-10,000, in steps of 1000. But if I'm trading on the M1, I certainly don't want to set that since of scale based on just the last 15 minutes -- I probably want at least, say, 4 hours (in fact, ATR(240) is a common starting point for me when trading on M1), or on the H1, I don't want it just based on today, but more like a week, so ATR(120) is what I often use.

Tl;dr: a much longer ATR period gives a good general sense of scale that ports well across different symbols and timeframes.

 
Scott Allen #:

Like you said, it depends on the strategy.

In some cases, like a trailing stop calculation, you may want it to be more reactive, even down to like 5 periods or so, so that it responds quickly to a consolidation.

In the case I described, I'm not trying to be reactive to current market conditions, but using ATR to easily get a sense of appropriate scale. I don't want to have to figure out the appropriate scale for stop loss in points on every symbol and timeframe I test on. Some, a range of 1-100 makes sense; others, it's more like 100-10,000, in steps of 1000. But if I'm trading on the M1, I certainly don't want to set that since of scale based on just the last 15 minutes -- I probably want at least, say, 4 hours (in fact, ATR(240) is a common starting point for me when trading on M1), or on the H1, I don't want it just based on today, but more like a week, so ATR(120) is what I often use.

Tl;dr: a much longer ATR period gives a good general sense of scale that ports well across different symbols and timeframes.

Right, I agree on that. - But also there is some "disagrement" I see. - If you take the ATR with 240, on a 1M and you transition from London evening to Syney night, you will have a wrong scale. - Same goes for London open... Or do I see this wrong?

 
Dominik Christian Egert #:

Right, I agree on that. - But also there is some "disagrement" I see. - If you take the ATR with 240, on a 1M and you transition from London evening to Syney night, you will have a wrong scale. - Same goes for London open... Or do I see this wrong?

No, you're correct. That could be accommodated for somehow if you really wanted to. In the particular case I'm implementing it for, though, I'm actually trading n minutes before the NY close, so the 240 is appropriate - it's the NY afternoon session.