MarketAlert – Real-Time Market & Crypto News, Analysis & AlertsMarketAlert – Real-Time Market & Crypto News, Analysis & Alerts
Font ResizerAa
  • Crypto News
    • Altcoins
    • Bitcoin
    • Blockchain
    • DeFi
    • Ethereum
    • NFTs
    • Press Releases
    • Latest News
  • Blockchain Technology
    • Blockchain Developments
    • Blockchain Security
    • Layer 2 Solutions
    • Smart Contracts
  • Interviews
    • Crypto Investor Interviews
    • Developer Interviews
    • Founder Interviews
    • Industry Leader Insights
  • Regulations & Policies
    • Country-Specific Regulations
    • Crypto Taxation
    • Global Regulations
    • Government Policies
  • Learn
    • Crypto for Beginners
    • DeFi Guides
    • NFT Guides
    • Staking Guides
    • Trading Strategies
  • Research & Analysis
    • Blockchain Research
    • Coin Research
    • DeFi Research
    • Market Analysis
    • Regulation Reports
Reading: From Novice to Expert: Developing a Liquidity Strategy
Share
Font ResizerAa
MarketAlert – Real-Time Market & Crypto News, Analysis & AlertsMarketAlert – Real-Time Market & Crypto News, Analysis & Alerts
Search
  • Crypto News
    • Altcoins
    • Bitcoin
    • Blockchain
    • DeFi
    • Ethereum
    • NFTs
    • Press Releases
    • Latest News
  • Blockchain Technology
    • Blockchain Developments
    • Blockchain Security
    • Layer 2 Solutions
    • Smart Contracts
  • Interviews
    • Crypto Investor Interviews
    • Developer Interviews
    • Founder Interviews
    • Industry Leader Insights
  • Regulations & Policies
    • Country-Specific Regulations
    • Crypto Taxation
    • Global Regulations
    • Government Policies
  • Learn
    • Crypto for Beginners
    • DeFi Guides
    • NFT Guides
    • Staking Guides
    • Trading Strategies
  • Research & Analysis
    • Blockchain Research
    • Coin Research
    • DeFi Research
    • Market Analysis
    • Regulation Reports
Have an existing account? Sign In
Follow US
© Market Alert News. All Rights Reserved.
  • bitcoinBitcoin(BTC)$78,014.00-1.21%
  • ethereumEthereum(ETH)$2,315.16-3.58%
  • tetherTether(USDT)$1.000.01%
  • rippleXRP(XRP)$1.44-0.91%
  • binancecoinBNB(BNB)$635.42-1.60%
  • usd-coinUSDC(USDC)$1.00-0.01%
  • solanaSolana(SOL)$85.50-2.95%
  • tronTRON(TRX)$0.3290110.16%
  • Figure HelocFigure Heloc(FIGR_HELOC)$1.041.69%
  • dogecoinDogecoin(DOGE)$0.096258-1.25%
Trading Strategies

From Novice to Expert: Developing a Liquidity Strategy

Last updated: February 3, 2026 6:05 pm
Published: 3 months ago
Share

Today, we focus on modeling an Expert Advisor (EA) based on liquidity zones. In previous discussions, we concentrated on identifying and validating these zones, and the results have been both encouraging and promising. However, one critical challenge remains: automating the trading process. This can only be achieved by translating the strategy into executable logic using MQL5, including robust trade execution and risk management rules.

To do this effectively, we will first establish a clear conceptual understanding of the strategy. Once the logic is well defined, we will proceed to implement it in code.

Understanding the strategy

Through our analysis, we have established that a liquidity zone can often be represented by a single candle. Such a candle typically emerges after a period of price pause or consolidation and encapsulates liquidity that has formed over time or across lower timeframes. This behavior is precisely what produces the structural model we are working with in this study.

For clarity and accessibility, we deliberately adopt a simplified approach. Rather than relying on complex multi-bar formations, we define our conditions using minimal price information. This allows us to focus on the core mechanics of the strategy while making the initial implementation in code straightforward and easier to validate.

The objective of this strategy is to return price to the identified liquidity structure (see Fig. 1 below) and build positions from that area, ultimately targeting the most recent swing high or swing low, depending on whether the setup is bullish or bearish. While the concept of a retest is central to this model, it is also important to recognize that it has become a common and widely studied idea. As a result, such levels are increasingly vulnerable to manipulation. Market participants with significantly larger capital can push prices beyond obvious boundaries, triggering stop losses and forcing weaker positions out of the market before the intended move unfolds.

For this reason, risk management cannot be treated as an afterthought. It must be an integral part of both the strategy design and its algorithmic execution. How the Expert Advisor defines risk, places stop losses, and manages exposure is just as critical as how it identifies valid trade setups.

It is also essential to acknowledge that not every setup will succeed. No single trade guarantees a profitable outcome. Instead, performance emerges over time through the aggregation of wins and losses. It is this cumulative result — measured across a sufficiently large sample of trades — that ultimately determines whether a strategy is profitable or unprofitable.

With this foundation established, the next section will focus on translating the strategy into MQL5 code. Once implemented, we will proceed to test and evaluate its behavior under realistic market conditions.

Before implementing the trading logic, we will create a new Expert Advisor project in MetaEditor using the MQL5 Wizard. This wizard automatically generates a default template that includes event handlers and placeholder code. For the purpose of this article, we remove all auto-generated logic and leave only the metadata section, as shown below.

This keeps the focus on understanding and building the strategy step by step as the implementation unfolds in the following sections. It is wise to manually type the code to gain familiarity with the structure; however, for convenience, the complete source file is provided in the attachments at the end of the article for those who prefer not to type everything manually.

Once the EA metadata and inputs are defined, we include the trading library responsible for all order execution. Rather than working with low-level trade functions, we rely on the CTrade class, which provides a safer and more structured interface.

Code:

By declaring a single global CTrade object, we centralize all trading operations — pending orders, stop losses, take profits, and magic number assignment — making the code cleaner and easier to maintain.

Declaring Inputs and Strategy Controls

Before we write any execution logic, we first declare the inputs. This is a deliberate step. Inputs define the external behavior of the Expert Advisor and allow traders to adapt the strategy without touching the source code. By exposing these parameters, we separate strategy logic from user control, which is a key principle in professional EA design.

Code:

Here, we declare each parameter with a clear operational purpose:

By structuring inputs this way, we make the EA flexible, testable, and user-friendly, while keeping the internal logic intact.

Declaring Global Variables

Next, we declare the global variables that must persist across ticks. In this strategy, we deliberately keep global state minimal.

Code:

This variable is used exclusively to detect the opening of a new candle. Controlling execution frequency is critical in automated systems to prevent duplicated trades and inconsistent backtesting results.

Detecting the Opening of a New Candle

Before any trading logic is evaluated, we enforce a one-candle-one-execution rule. This ensures that the EA only reacts once per completed candle, regardless of tick frequency.

Code:

Here, we compare the timestamp of the current candle with the last processed one. When a new candle forms, we update the stored time and allow execution to proceed.

The core of this strategy is range-based comparison, not candle bodies or indicators. To support this, we introduce a helper function that returns the full high-low range of a candle.

Code:

Encapsulating this calculation improves readability and allows us to reuse the logic consistently throughout the EA.

Multi-Level Liquidity Entry for Buy Setups

Rather than entering at a single price, we distribute limit orders across the base candle range. This models how liquidity is typically absorbed by the market.

Code:

By placing orders at the high, midpoint, and low of the liquidity candle, we:

We apply the same logic symmetrically for bearish conditions.

Code:

This symmetry ensures consistent behavior across both market directions and simplifies validation and optimization.

The Main Execution Loop: OnTick()

All strategy logic is coordinated inside the OnTick() function. This is where conditions are evaluated, risk is checked, and orders are placed.

Code:

We immediately enforce new-bar execution. If no new candle has formed, the EA exits without further processing.

Spread Protection and Trade Identification

Before evaluating market structure, we validate trading conditions.

Code:

This prevents entries during unfavorable spreads and ensures all trades are uniquely identifiable.

Defining Candle Roles

We now explicitly define which candles participate in the model.

The currently forming candle (index 0) is intentionally ignored.

Here, we enforce that the base candle must be significantly smaller than the impulse candle. The sensitivity of this condition is fully controlled by RatioMultiplier.

Directional Confirmation

We now confirm that both candles agree directionally.

Code:

This step ensures we are trading continuation, not exhaustion.

Stop Loss Offset and Order Expiry

To account for manipulation and false breaks, we introduce a configurable stop offset and time-based invalidation.

Code:

These two parameters work together to control risk in both price and time dimensions.

We place buy limits inside the liquidity zone, protect beyond it, and target the impulse high.

The logic mirrors the bullish case, preserving structural consistency.

At this stage, we have fully modeled a single-candle liquidity strategy, from structure detection to execution and risk control. The system intentionally avoids indicators and focuses purely on price behavior, liquidity, and disciplined execution.

In the next section, we can proceed to testing methodology, parameter sensitivity, and result interpretation.

Here, I present the initial test results obtained by running the Expert Advisor in the MetaTrader 5 Strategy Tester. For readers who are new to the platform, the first step is to locate the EA associated with this project in the Navigator window under the Experts directory. Once found, right-click on the EA and select Test from the context menu. This action launches the Strategy Tester, where various types of tests can be performed.

Before considering any form of optimization, our primary objective is to verify that the EA executes mechanically and consistently according to the intended strategy rules. At this stage, we are not concerned with profitability; instead, we want to confirm that the logic translates correctly from concept to code and that orders are placed, managed, and expired exactly as designed. Only after this validation step is completed do we move on to optimization and parameter refinement.

It is worth noting that some strategies fail at this early stage. In certain cases, even after genetic optimization, a strategy may prove structurally unsound and therefore unsuitable for further development. Identifying such outcomes early saves time and prevents unnecessary overfitting.

The screencast below demonstrates the strategy in action and confirms that the conceptual model has been successfully brought to life. Although additional work is required before the system can be classified as a profitable trading model, the optimization results presented below — shown in graphical form — already indicate promising regions of performance. With further filtering and refinement aimed at eliminating negative outcomes, these results provide encouraging signals for continued development.

In this article, we demonstrated how a single-candle liquidity pattern, consisting of a base candle and an impulse candle, can be transformed from a conceptual trading idea into a fully automated trading model using MQL5. The resulting Expert Advisor executes the strategy rules as intended: pending orders are placed according to the defined structure, some trades are triggered and closed profitably, others result in losses, and some orders remain unfilled.

Visual testing over an extended historical period (from 2005 to the present) reveals that not all identified liquidity zones are revisited by price. In some cases, the retest may occur after a long delay or not occur at all. To manage this behavior, a time-based expiry mechanism was implemented to remove pending orders automatically after a predefined duration, preventing outdated trade ideas from remaining active indefinitely.

From an educational standpoint, this work illustrates the process of converting abstract trading concepts into precise, rule-based execution logic. The presented Expert Advisor is intended for learning and research purposes only and should be tested on a demo account. Several areas remain open for further development, including session-based trading filters, additional market condition filters, and integration with complementary analytical tools.

Overall, this study confirms that trading strategies can be automated once their conditions are clearly defined and expressed programmatically. It is hoped that this article provides practical insights into both strategy design and Expert Advisor implementation.

Your feedback and contributions are welcome in the comments section below.

Key lessons and related attachments are provided in the following sections.

Read more on mql5.com

This news is powered by mql5.com mql5.com

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook

Like this:

Like Loading...

Related

Tokenized Money Market Funds Reach $9 Billion as BIS Issues Warning
US stocks ended with heavy selling despite the lack of fresh catalyst – Newsquawk Asia-Pac Market Open
ZKsync Backed Hyperliquid Challenger Grvt Raises $19M
Mastering the Art of PrimeXBT Trading A Comprehensive Guide – América Digital
5 Most Trending Cryptos as We Enter December 2025 · Cardano Feed

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Email Copy Link Print
Previous Article Elon’s xAI Is Hiring Crypto Experts As SUBBD Token Surges Past $4.5M | Cryptocurrency Market News | CryptoRank.io
Next Article Retail Traders in Japan Can Now Access Matsui FX Prices in Real Time on TradingView
© Market Alert News. All Rights Reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Prove your humanity


Lost your password?

%d