Discussing the article: "The MQL5 Standard Library Explorer (Part 3): Expert Standard Deviation Channel"

Check out the new article: The MQL5 Standard Library Explorer (Part 3): Expert Standard Deviation Channel.

In this discussion, we will develop an Expert Advisor using the CTrade and CStdDevChannel classes, while applying several filters to enhance profitability. This stage puts our previous discussion into practical application. Additionally, I’ll introduce another simple approach to help you better understand the MQL5 Standard Library and its underlying codebase. Join the discussion to explore these concepts in action.

The explorer’s goal is to look deeper into things, to experiment, and through that process, to discover new ideas. In the previous discussion, I aimed to simplify this journey by laying the foundation and outlining a routine for integrating classes into Expert Advisors. The main objective was to study class interfaces to understand their purpose—and in doing so, recognize how developer comments can make the learning process much easier.

I concluded by summarizing the essential steps for working with Standard Library classes. One key advantage that stands out is the comprehensive documentation available for MQL5. Much like other programming languages, MQL5’s documentation forms a complete knowledge base. In fact, the entire MQL5 website—including its articles, forums, books, and codebase—collectively serves as a rich source of reference material. Each section is designed to help developers and traders solve practical challenges in algorithmic trading.

Today’s challenge is to build an Expert Advisor that trades using volatility-based channels. In doing so, we’ll explore the CChartObjectStdDevChannel class, which will help us not only create a functional EA but also gain deeper insight into the Standard Library. There’s always something new to learn, even from existing code—because every experiment opens the door to new ideas.

Think of today’s task as a puzzle: the final picture is our Expert Advisor, and our job is to fit the pieces together using concepts and notes from the previous discussion.

Author: Clemence Benjamin

In your code, when  UseMeanReversion = false, the tp value should be higher than g_upper, no?


      if (EnableBuys)       {          bool buySignal = false;          if (UseMeanReversion)          {             // Mean reversion buy: Bounce off lower (current > lower, prior low <= lower)             double prevLow = iLow(_Symbol, PERIOD_CURRENT, 1);             buySignal = (bid > g_lower && prevLow <= g_lower);          }          else          {             // Breakout buy: Break above upper             buySignal = (ask > g_upper);          }                   if (buySignal)          {             double entry = ask;             double sl = NormalizeDouble(g_lower - (SLBuffer * point), digits);             double tp = NormalizeDouble(g_upper, digits);                          // Adjust SL to meet min distance             if (entry - sl < minDist)                sl = NormalizeDouble(entry - minDist, digits);                          // Check TP min distance             if (tp - entry < minDist)             {                Print("TP too close for buy (dist=", (tp - entry)/point, " < ", minDist/point, ") - skipping");             }             else if (trade.Buy(LotSize, _Symbol, entry, sl, tp, "Channel Buy"))             {                Print("Buy order placed: Entry=", entry, " SL=", sl, " TP=", tp, " (TP > SL)");             }             else             {                Print("Buy order failed: ", trade.ResultRetcode(), " - ", trade.ResultRetcodeDescription());             }          }       } 
To add comments, please log in or register