MQL4 (MT4) Reverse Lookup Reference: Indicator for Email Notifications on Horizontal Line Breaks & Candle Closures

EA Development
スポンサーリンク

Create an Indicator for Email Notifications on Horizontal Line Breaks & Candle Closures

Using ChatGPT (GPTs), I have developed an indicator that sends email notifications when a horizontal line is broken and the candle closes beyond it.

🔹 GPT Used: EA Creator
🔹 Functionality: Sends an email when a candle closes above or below a specified horizontal line.
🔹 Ideal for: Traders who want real-time alerts on key price levels.

Request Details & Execution Results

Since the initial request was a bit vague, I made some modifications to refine the logic. While crafting the request can be tricky, leveraging AI assistance significantly reduces development time.

Request Specifications

External Parameters:

  • Line Name: Set the name of the horizontal line (e.g., “Line A”).
  • Timeframe: Select the timeframe for analysis.
  • Email Title: Define the subject of the notification email.
  • Email Body: Customize the email message content.

Logic:

  • Send an email notification when the closing price of the previous candle crosses above “Line A”.
  • Send an email notification when the closing price of the previous candle crosses below “Line A”.
  • The email title and body are customizable via external parameters.
ChatGPT Output Code

The following indicator was created based on the specifications. It detects when the previous candle’s closing price crosses the horizontal line and triggers an email notification accordingly.

//+------------------------------------------------------------------+
//|                    Horizontal Line Break Alert Indicator         |
//|                  Copyright 2023, MetaQuotes Software Corp.       |
//|                      http://www.metaquotes.net/                 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property version   "1.00"
#property strict
#property indicator_chart_window

// External Parameters
input string LineName = "Line A";                // Horizontal line name
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Timeframe selection
input string MailTitle = "Line Break Alert";     // Email notification title
input string MailBody = "Line A has been broken."; // Email notification message

//+------------------------------------------------------------------+
//| Indicator Initialization Function                               |
//+------------------------------------------------------------------+
int OnInit()
  {
   if (!ObjectFind(0, LineName)) 
     {
      Print("Line '", LineName, "' found.");
     }
   else 
     {
      Print("Line '", LineName, "' not found. Stopping indicator.");
      return(INIT_FAILED);
     }

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Main Processing Function (Triggered on Each Tick)               |
//+------------------------------------------------------------------+
void OnTick()
  {
   double linePrice = ObjectGetDouble(0, LineName, OBJPROP_PRICE1);
   double prevClose = iClose(_Symbol, TimeFrame, 1);

   // Check for an upward breakout
   if (prevClose > linePrice) 
     {
      string message = MailBody + " Breakout Up!";
      SendMail(MailTitle, message);
     }
   // Check for a downward breakout
   else if (prevClose < linePrice) 
     {
      string message = MailBody + " Breakout Down!";
      SendMail(MailTitle, message);
     }
  }

Important Notes:

  • The indicator requires “Line A” to exist on the chart. If it is missing, the indicator automatically stops to prevent errors.
  • MetaTrader email settings must be correctly configured (SMTP server, port, username, password) for the SendMail function to work.
  • The logic only evaluates completed candles (not real-time fluctuations).
  • Notifications are sent every time a valid breakout occurs. Multiple emails may be triggered if the same condition repeats.

Optimized Code (After Adjustments)

After making additional refinements, here is the improved version of the indicator:

#property copyright "Copyright 2023, SeSe."
#property link      "https://fx-trading-gym.info/"
#property version   "1.00"
#property strict
#property indicator_chart_window

// External Parameters
input string LineName = "Horizontal Line 3354";  // Horizontal line name
input ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Timeframe selection
input string MailTitle = "Line Break Alert";      // Email notification title
input string MailBody = "Line A has been broken."; // Email notification message

//+------------------------------------------------------------------+
//| Indicator Initialization Function                               |
//+------------------------------------------------------------------+
int OnInit()
  {
   if (!ObjectFind(0, LineName)) 
     {
      Print("Line '", LineName, "' found.");
     }
   else 
     {
      Print("Line '", LineName, "' not found. Stopping indicator.");
      return(INIT_FAILED);
     }
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Main Calculation Function (Triggered on Candle Closure)         |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   double linePrice = ObjectGetDouble(0, LineName, OBJPROP_PRICE1);
   double prevClose = iClose(_Symbol, TimeFrame, 1);
   double prevOpen = iOpen(_Symbol, TimeFrame, 1);
   static double sent_Close = 0;
   
   // Check for an upward breakout
   if (prevClose > linePrice && prevOpen < linePrice && sent_Close != prevClose) 
     {
      string message = MailBody + " Breakout Up!";
      SendMail(MailTitle, message);
      Print(message);
      sent_Close = prevClose;
     }
   // Check for a downward breakout
   else if (prevClose < linePrice && prevOpen > linePrice && sent_Close != prevClose) 
     {
      string message = MailBody + " Breakout Down!";
      SendMail(MailTitle, message);
      Print(message);
      sent_Close = prevClose;
     }
    return 0;
  }

🔹 Indicator Sample (Download)

🚀 A sample version of this indicator is available for download. Please complete the required action to unlock access.

👉 Download Now (Unlock content to access the file)

✅ Features:
✔️ Detects horizontal line breakouts
✔️ Sends email alerts upon confirmed breakouts
✔️ Customizable parameters for flexibility
✔️ Compatible with MT4 (MQL4)

⚠️ Note: This is a basic version for demonstration purposes. Proper backtesting and optimization are recommended before live trading.

🚀 Thank You for Using Our Tools! A Small Favor to Ask 🚀

Thank you so much for choosing our FX indicators and tools!
To support your success in FX trading, we’ve carefully selected some services that can help you achieve better results.
If you find them useful, we’d greatly appreciate your support.

Your participation will not only motivate us but also help us continue to develop even better tools for you in the future!

💼 Increase Your Profits with an Overseas FX Account!
🌍 Exness Account – The Broker I Trust the Most!
  • Industry-low spreads to reduce trading costs
  • Fully compatible with MT4/MT5, perfect for automated trading (EA)
  • Instant withdrawals for smooth fund management

👉 Open an Exness Account Now (Special Offer)



💸 Reduce Trading Costs with Cashback from Overseas FX Accounts!
 🚀 TariTali – High Cashback Rates That Make a Difference!
  • Maximize savings with high-rate cashback on every trade
  • Supports a wide range of MT4/MT5 brokers, ideal for EAs
  • Real-time tracking of your cashback history
  • Fast withdrawals to domestic bank accounts

👉 Cut Your Trading Costs Smartly with TariTali!

海外FXキャッシュバック口座開設ならTariTali(タリタリ)

🔥 Money Charger – The New Standard for Forex Cashback!
  • Automatic cashback on every trade → The more you trade, the more you earn!
  • Industry-leading cashback rates for maximum profit efficiency
  • Simple registration with instant cashback available
  • Supports multiple brokers, giving you flexible account choices

👉 Start Earning Cashback with Money Charger Today!
More details: Complete Guide to Forex Cashback

🤖 Accelerate Your Profits with Automated Trading Systems (EAs)!
🔥 Introducing High-Performance EAs I’ve Developed
  • Poundeur (HL Band M15 for GJ) → The best choice for stable profits
  • BBHL Band H1 for EJ & BBHL Band H1 for AJ → Excellent performance even in high-volatility markets

👉 Discover Our Profitable MT4 EAs for FX Traders

📊 Check Out the Most Popular EAs!
  • Handpicked EAs trusted by many traders
  • Performance records and profit data are publicly available

👉 See the Top-Ranked EAs Now

関連記事

スポンサーリンク
海外FXキャッシュバック口座開設ならTariTali(タリタリ)

コメント

タイトルとURLをコピーしました