MQL4 Tutorial: Simple IOSMA Expert Advisor


In this article, the focus is on creating an Expert Advisor that utilizes the IOSMA (Moving Average of Oscillator). The IOSMA is a technical indicator that showcases the difference between an oscillator and a moving average of that oscillator. It’s particularly useful for traders as it generates buy or sell signals whenever it crosses the 0 (zero) line. Here’s a detailed breakdown:

  1. Understanding the IOSMA: The IOSMA, while having a somewhat unusual name, is a powerful tool. When it crosses the 0 line from above, it generates a sell signal, and when it crosses from below, it produces a buy signal.
  2. The OnTick Function: At the beginning of the code, there’s the OnTick function. This function is activated every time a new price update (a new tick) for the current financial instrument comes in. It’s the foundation for all subsequent calculations and actions of the Expert Advisor.
  3. Signal Variable Creation: Within the OnTick function, a string variable named “Signal” is defined. This variable will later be used to determine whether a buy or sell signal exists.
  4. IOSMA Value Calculation: The current value of the IOSMA and the value of the IOSMA for the previous candle are calculated using the iOsMA command in MQL4. This calculation allows the Expert Advisor to understand the market’s current position relative to its recent past.
  5. Determining Signals: Based on the calculated IOSMA values, the decision is made whether a buy or sell signal exists. If the current IOSMA value is above 0 and the previous value was below 0, a buy signal is generated. Conversely, if the current value is below 0 and the previous value was above, a sell signal is generated.
  6. Displaying on the Chart: After determining the signal, it’s displayed directly on the chart. This provides traders with a clear visual confirmation of the current market signal.

Benefits of the IOSMA Expert Advisor:

  • Market Trend Identification: The IOSMA assists traders in recognizing the overall direction of the market, which is crucial for making long-term trading decisions.
  • Accuracy: By combining an oscillator with its moving average, the IOSMA delivers precise signals that are less prone to false breakouts.
  • Adaptability: The IOSMA can be combined with other technical indicators to further refine and optimize the trading strategy.

In conclusion, the IOSMA Expert Advisor in MQL4 offers traders a robust tool to understand market dynamics and make informed trading decisions. It’s a valuable addition to any technical analysis toolkit.