Viewing the resource: Awesome Oscillator EA: Ride Momentum with AO Signals

Awesome Oscillator EA: Ride Momentum with AO Signals

Allan Munene Mutiiria 2025-06-20 22:15:19 92 Views
Join our fun, newbie-friendly guide to the Awesome Oscillator EA MQL5 code! We’ll explain every fu...

Introduction

Hey there, future forex wave-rider! Imagine you’re surfing the forex market, chasing the rush of momentum shifts. The Awesome Oscillator (AO) EA, powered by Bill Williams’ momentum indicator, is your high-performance surfboard, spotting when the market’s ready to flip from bullish to bearish or vice versa. This article is your guide to automating that ride with MQL5 code on MetaTrader 5. We’ll explore the code with vivid detail, explaining every major function like you’re new to coding (no worries!), and weave it together with humor and flow, like a storyteller spinning a tale by the beach. By the end, you’ll be ready to let this Expert Advisor (EA) catch market waves for you. Let’s paddle out!

Strategy Blueprint

The Awesome Oscillator EA harnesses the AO indicator, which compares a 34-period and 5-period simple moving average (SMA) of median prices to measure momentum. Displayed as a histogram, the AO shows:

  • Bars above zero: Bullish momentum—buyers are pumped.

  • Bars below zero: Bearish momentum—sellers are in charge.

  • Color changes: Green bars signal rising momentum; red bars signal falling momentum.

The EA triggers a buy when the AO turns green after two red bars and is above zero, confirming a bullish shift. It signals a sell when the AO turns red after two green bars and is below zero, indicating a bearish turn. Trades are opened with a 100-pip stop loss and take profit, keeping your risk in check. It’s like catching the perfect wave at just the right moment. See below.

Code Implementation

Let’s dive into the MQL5 code like surfers chasing a swell, presenting each major section in full with a seamless narrative that flows like the ocean. We’ll explain every key function in detail, ensuring it’s clear for beginners, and quote variables (e.g., "AO_data") and functions (e.g., "OnInit()") for clarity. Our goal is to make the code as inviting as a sunny beach, guiding you from setup to trading with ease.

Setting the Stage: Header, Includes, and Global Variables

We start by laying the foundation, like setting up your surfboard before hitting the waves.

//+------------------------------------------------------------------+
//|                                        AWESOME OSCILLATOR EA.mq5 |
//|                        Copyright 2025, Allan Munene Mutiiria      |
//|                            https://t.me/Forex_Algo_Trader         |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Allan Munene Mutiiria"
#property link      "https://t.me/Forex_Algo_Trader"
#property version   "1.00"

#include <Trade/Trade.mqh>
CTrade obj_Trade;

int handleAO;
double AO_data[],AO_color[];

This opening scene sets the tone. The header declares the EA as “Awesome Oscillator EA,” crafted by Allan in 2025, with a link to your Telegram channel and version 1.00. The #include <Trade/Trade.mqh> directive imports the MQL5 trade library, providing tools for executing trades. The "CTrade" class creates an object named "obj_Trade", your trading assistant for opening buy and sell orders.

Globally, we define:

  • "handleAO": An integer to store the AO indicator’s handle, like a key to unlock its data.

  • "AO_data[]": An array to hold the AO’s histogram values, showing momentum strength.

  • "AO_color[]": An array to store color data (0 for green, 1 for red), tracking momentum direction.

These globals are like your surf gear, ready for the EA to use across its functions.

Preparing the Board: OnInit Function

Next, we set up the AO indicator, like waxing your surfboard for the perfect ride.

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(){
   // create handle of the indicator iAO
   handleAO = iAO(_Symbol,_Period);
   // if the handle is not created
   if (handleAO == INVALID_HANDLE){
      // tell about the failure
      Print("FAILED TO CREATE HANDLE OF THE IAO IND. REVERTING NOW");
      // stop the indicator early
      return (INIT_FAILED);
   }
   
   // sort the data storage arrays as time series
   ArraySetAsSeries(AO_data,true);
   ArraySetAsSeries(AO_color,true);

   return(INIT_SUCCEEDED);
}

The "OnInit()" function is the EA’s pre-surf checklist, running when you attach it to a chart. Let’s break down its key functions:

  • "iAO()": Creates the Awesome Oscillator indicator for the current symbol ("_Symbol", e.g., EURUSD) and timeframe ("_Period", e.g., H1). It returns a handle, stored in "handleAO", which lets the EA access AO data.

  • "Print()": Logs a message to the MetaTrader 5 journal. Here, it reports if the "iAO()" function fails, like a warning flag if your surfboard’s cracked.

  • "ArraySetAsSeries()": Configures the "AO_data[]" and "AO_color[]" arrays as time series, so index 0 holds the latest value, like organizing your surf reports newest first.

  • "INVALID_HANDLE": A constant indicating a failed indicator creation. If "handleAO" equals this, the EA logs an error and exits with INIT_FAILED.

If all goes well, it returns INIT_SUCCEEDED, signaling, “We’re ready to surf!” This function ensures the AO is set up and ready to track momentum.

Cleaning the Beach: OnDeinit Function

When the surf session ends, this function tidies up.

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
   // RELEASE THE INDICATOR HANDLE FROM THE PC MEMORY  
   IndicatorRelease(handleAO);
}

The "OnDeinit()" function is the EA’s cleanup crew, called when you remove it from the chart. It uses:

  • "IndicatorRelease()": Frees the "handleAO" from memory, like returning your surfboard to the shop. This prevents memory leaks, keeping MetaTrader 5 running smoothly.

This short function ensures a clean exit, leaving no trace behind.

Catching the Wave: OnTick Function

Now we hit the EA’s core, where it hunts momentum shifts on every price tick.

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(){
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

   // copy data from the indicator buffers and store in a part of the data arrays
   if (CopyBuffer(handleAO,0,0,3,AO_data) < 3){
      // if the copying of the data fails, inform about the failure
      Print("FAILED TO RETRIEVE ENOUGH DATA FROM THE AO FOR FURTHER ANALYSIS. REVERTING");
      // quit further calculations and return
      return;
   }
   if (!CopyBuffer(handleAO,1,0,3,AO_color)){return;}
   
   static datetime signalTime = 0;
   datetime currTime0 = iTime(_Symbol,_Period,0);
   
   if (AO_color[0] == 0 && AO_color[1] == 0 && AO_color[2] == 1 && signalTime != currTime0 && AO_data[0] > 0){
      Print("BUY SIGNAL @ ",TimeCurrent());
      signalTime = currTime0;
      obj_Trade.Buy(0.01,_Symbol,Ask,Ask-100*_Point,Ask+100*_Point);
   }
   else if (AO_color[0] == 1 && AO_color[1] == 1 && AO_color[2] == 0 && signalTime != currTime0  && AO_data[0] < 0){
      Print("SELL SIGNAL @ ",TimeCurrent());
      signalTime = currTime0;
      obj_Trade.Sell(0.01,_Symbol,Bid,Bid+100*_Point,Bid-100*_Point);
   }
}

The "OnTick()" function is the EA’s surf session, running on every price tick to catch momentum waves. It’s the heart of the strategy, so let’s dive in with detail, explaining each major function:

  • "SymbolInfoDouble()": Retrieves real-time market data for the current symbol. It grabs the ask price ("SYMBOL_ASK") for buying and bid price ("SYMBOL_BID") for selling, stored in "Ask" and "Bid".

  • "NormalizeDouble()": Rounds prices (e.g., "Ask", "Bid") to the symbol’s decimal places ("_Digits", e.g., 5 for EURUSD), ensuring they’re formatted correctly for trading, like tuning your board for precision.

  • "CopyBuffer()": Copies data from the AO indicator (via "handleAO") into arrays. It pulls three values for the histogram ("AO_data[]" from buffer 0) and colors ("AO_color[]" from buffer 1). If "CopyBuffer()" fails to get three "AO_data[]" values, it logs an error with "Print()" and exits. If "AO_color[]" fails, it exits silently.

  • "iTime()": Gets the timestamp of the current candle (index 0) for the symbol and timeframe, stored in "currTime0". This helps ensure trades only trigger once per candle.

  • "TimeCurrent()": Returns the current server time, used in "Print()" to log the exact time of a signal, like timestamping a surf photo.

  • Signal Timing Logic: A static "signalTime" variable tracks the last signal’s timestamp. If "signalTime" matches "currTime0", the EA skips to avoid duplicate trades on the same candle.

  • Buy Signal Logic: Checks if the latest AO bar is green ("AO_color[0] == 0"), the previous two are green and red ("AO_color[1] == 0", "AO_color[2] == 1"), the candle is new ("signalTime != currTime0"), and the AO value is above zero ("AO_data[0] > 0"). If true, it logs “BUY SIGNAL” with "Print()", updates "signalTime", and opens a buy trade with "obj_Trade.Buy()", using 0.01 lots, "Ask" price, a 100-pip stop loss ("Ask-100*_Point"), and a 100-pip take profit ("Ask+100*_Point").

  • Sell Signal Logic: Checks if the latest AO bar is red ("AO_color[0] == 1"), the previous two are red and green ("AO_color[1] == 1", "AO_color[2] == 0"), the candle is new, and the AO value is below zero ("AO_data[0] < 0"). If true, it logs “SELL SIGNAL”, updates "signalTime", and opens a sell trade with "obj_Trade.Sell()", using 0.01 lots, "Bid" price, a 100-pip stop loss ("Bid+100*_Point"), and a 100-pip take profit ("Bid-100*_Point").

  • "Buy()", "Sell()": Methods of the "CTrade" class, used to open buy or sell trades. They take parameters like lot size (0.01), symbol ("_Symbol"), price, stop loss, and take profit, executing trades like a broker with a megaphone.

  • "_Point": A built-in variable for the symbol’s pip size, used to calculate stop loss and take profit distances.

This function flows from fetching prices to checking AO signals to executing trades, like a surfer spotting a wave, checking conditions, and riding it with precision.

Putting It All Together

To launch this EA:

  1. Open MetaEditor in MetaTrader 5.

  2. Paste the code into a new Expert Advisor file.

  3. Compile (F5). If errors pop up, double-check your copy-paste.

  4. Drag the EA onto your chart, enable AutoTrading, and watch for buy or sell trades.

  5. Trade smart—don’t bet your surfboard on one signal!

Conclusion

The Awesome Oscillator EA is your momentum-riding companion, using the AO’s histogram to catch market waves. We’ve surfed through its MQL5 code with clear, detailed explanations, so you understand every move like a seasoned pro. Now you’re set to automate your trades and ride the market’s momentum. Want to see it in action? Check our video tutorial on the website!

Disclaimer: Trading’s like surfing a stormy sea—thrilling but risky. Losses can exceed deposits. Test on a demo account before going live.

Disclaimer: The ideas and strategies presented in this resource are solely those of the author and are intended for informational and educational purposes only. They do not constitute financial advice, and past performance is not indicative of future results. All materials, including but not limited to text, images, files, and any downloadable content, are protected by copyright and intellectual property laws and are the exclusive property of Forex Algo-Trader or its licensors. Reproduction, distribution, modification, or commercial use of these materials without prior written consent from Forex Algo-Trader is strictly prohibited and may result in legal action. Users are advised to exercise extreme caution, perform thorough independent research, and consult with qualified financial professionals before implementing any trading strategies or decisions based on this resource, as trading in financial markets involves significant risk of loss.

Recent Comments

Go to discussion to Comment or View other Comments

No comments yet. Be the first to comment!