Discussing the article: "Raw Code Optimization and Tweaking for Improving Back-Test Results"

 

Check out the new article: Raw Code Optimization and Tweaking for Improving Back-Test Results.

Enhance your MQL5 code by optimizing logic, refining calculations, and reducing execution time to improve back-test accuracy. Fine-tune parameters, optimize loops, and eliminate inefficiencies for better performance.

The development of our algorithmic trading strategy begins with a structured, methodical approach to pattern recognition and signal validation. At its core, the strategy employs a candlestick-based framework designed to identify high-probability reversal scenarios. For long positions, the logic systematically detects three consecutive bullish candles, followed by one or two corrective bearish candles, culminating in a confirming bullish candle at index 1 (the most recently closed bar).

Conversely, short positions are triggered by an inverse pattern: three consecutive bearish candles, succeeded by one or two retracement bullish candles, and finalized by a confirming bearish candle at index 1. This configuration ensures signals are validated only upon the formation of a new bar, aligning execution with confirmed price action rather than intra-bar fluctuations.

To operationalize this logic, the strategy’s architecture will prioritize modular code design and computational efficiency. First, helper functions will be implemented to abstract repetitive tasks, such as candlestick classification (bullish/bearish determination) and sequence validation (consecutive candle pattern checks). These functions will leverage MQL5’s native price data access methods, including `iOpen()` and `iClose()`, while minimizing redundant calculations through static variable caching.

Author: Hlomohang John Borotho

 

Please enlighten me as to how CTick and PTick work. I see that both are declared along with Includes, but neither is referenced elsewhere in the code. In other words, what does CTick track; and what does PTick track?

(I can't find anything in the MQ documentation).

 

The pursuit of reliable back-test results in algorithmic trading hinges not only on robust strategy logic but also on the efficiency and precision of the underlying code. Raw code optimization and tweaking are critical to ensuring that Expert Advisors (EAs) perform as intended, minimizing computational overhead while maximizing execution accuracy. Poorly optimized code can distort back-test outcomes through delayed order execution, incorrect signal detection, or resource exhaustion—issues that mask a strategy’s true potential.

During the strategy development process, we will take several key steps to ensure the EA is both functionally strong and technically sound. We’ll start by adding custom helper functions and reusable logic blocks to streamline operations and avoid repetitive code. Then, we'll introduce well-structured variables and constants that improve code readability and simplify parameter adjustments. These foundational tweaks will help in maintaining the code and improve overall execution time during heavy back-test loads or multi-symbol testing.

Another major area of enhancement involves leveraging technical indicators more efficiently. Instead of blindly calculating indicators on every tick or bar, we’ll implement smarter update logic to reduce load and lag. We’ll also experiment with different indicator combinations to support better decision-making in the EA’s logic. By combining structural code refinement, performance-aware functions, and indicator optimization, we can drastically improve both the quality and speed of back-testing—bringing us closer to a consistently profitable and deployable strategy.

I don't want to offend anyone, though I have to say this article is a failure. Here above is the introduction, with a lot of strong affirmations and , all which the author failed to implement.

My initial intention was to show the problems with the code, but they are so much... so I will just point 2.

   double sl_distance = StopLoss * point;
   double tp_distance = TakeProfit * point;
   
   double sl = (tradeType == ORDER_TYPE_BUY) ? price - sl_distance :
                                               price + sl_distance;
   
   double tp = (tradeType == ORDER_TYPE_BUY) ? price + tp_distance :
                                               price - tp_distance;

   trade.PositionOpen(_Symbol, tradeType, In_Lot, price, sl, tp, NULL);

Robust code ? Where is the error checking done ? Inputs are used as is without any checking, stoplevels is not checked, margin is not checked, trading request is not checked...

      // Check for bullish pattern
      for (int j = i; j >= i - min_bullish_count + 1; j--) {
         if (iClose(symbol, timeframe, j) > iOpen(symbol, timeframe, j)) {
            bullish_count++;
            first_bullish_low = getLow(5);
         } else break;
      }

Performance ? using iClose/iOpen candle by candle ? These functions are the slowest to deal with data.

Additionally the getLow(5) seems a bug. I didn't check further. 

I will not comment on the trading algorithm itself, I just noted how the author conveniently selected a short period in history where the EA gives good results.

This article is very poor.

 

Good afternoon, this very good analysis, but complement the same with the strength, if volume!!! although candlesticks give you information what ends up confirming is the volume, this way you could execute more trade without error!!!


Greetings