🚀 AI One-Click Generation of mql4 Strategy Code

Integrating with the Mql4 Signals Service Using API Functions

mql4 | Published on: 2025/12/4
The following content is generated by EasyQuant .

Problem Description

How can I get a list of available trading signals and their performance data using code?

Solution

To retrieve a list of available trading signals and their performance data in MQL4, you utilize the SignalBase family of functions. These functions allow you to iterate through the signals database currently loaded in your MetaTrader 4 terminal and extract specific properties such as profit (pips), subscriber count, price, and equity.

Key Functions Used

  1. SignalBaseTotal(): Returns the total number of signals available in the terminal.
  2. SignalBaseSelect(int index): Selects a specific signal from the list by its index (from 0 to Total-1) to allow property retrieval.
  3. SignalBaseGetInteger(), SignalBaseGetDouble(), SignalBaseGetString(): Retrieves specific properties (ID, Name, Price, Pips, etc.) of the currently selected signal.

MQL4 Script Implementation

The following script iterates through all available signals, applies a simple filter (e.g., minimum subscribers), and prints the performance data to the "Experts" log.

//+------------------------------------------------------------------+
//|                                        SignalScanner.mq4         |
//|                        Copyright 2023, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property script_show_inputs

//--- Input parameters to filter the output
input int    InpMinSubscribers = 5;     // Minimum number of subscribers to display
input double InpMaxPrice       = 50.0;  // Maximum price (USD) to display
input int    InpMinPips        = 100;   // Minimum profit in pips

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   // 1. Get the total number of signals available in the terminal cache
   int total_signals = SignalBaseTotal();
   
   PrintFormat("Total signals found in terminal: %d", total_signals);
   Print("-------------------------------------------------------------");

   // 2. Iterate through the list of signals
   for(int i = 0; i < total_signals; i++)
   {
      // 3. Select the signal by index to access its properties
      if(SignalBaseSelect(i))
      {
         // --- Retrieve Integer Properties ---
         long id          = SignalBaseGetInteger(SIGNAL_BASE_ID);
         long pips        = SignalBaseGetInteger(SIGNAL_BASE_PIPS);
         long subscribers = SignalBaseGetInteger(SIGNAL_BASE_SUBSCRIBERS);
         long trades      = SignalBaseGetInteger(SIGNAL_BASE_TRADES);
         long leverage    = SignalBaseGetInteger(SIGNAL_BASE_LEVERAGE);
         
         // --- Retrieve Double Properties ---
         double price     = SignalBaseGetDouble(SIGNAL_BASE_PRICE);
         double equity    = SignalBaseGetDouble(SIGNAL_BASE_EQUITY);
         double balance   = SignalBaseGetDouble(SIGNAL_BASE_BALANCE);
         
         // --- Retrieve String Properties ---
         string name      = SignalBaseGetString(SIGNAL_BASE_NAME);
         string author    = SignalBaseGetString(SIGNAL_BASE_AUTHOR_LOGIN);
         string currency  = SignalBaseGetString(SIGNAL_BASE_CURRENCY);
         
         // 4. Apply Filters
         // We only print signals that meet our input criteria to avoid flooding the log
         if(subscribers >= InpMinSubscribers && price <= InpMaxPrice && pips >= InpMinPips)
         {
            // Format the output string
            string output = StringFormat(
               "ID: %d | Name: %s | Price: $%.2f | Pips: %d | Subs: %d | Trades: %d | Equity: %.2f %s",
               id, 
               name, 
               price, 
               pips, 
               subscribers, 
               trades, 
               equity, 
               currency
            );
            
            Print(output);
         }
      }
      else
      {
         // Error handling if selection fails
         PrintFormat("Failed to select signal at index %d. Error code: %d", i, GetLastError());
      }
   }
   
   Print("-------------------------------------------------------------");
   Print("Scan complete.");
}
//+------------------------------------------------------------------+

Important Considerations

  1. Data Availability: SignalBaseTotal() returns the number of signals currently loaded in the terminal's cache. If you run this script and get 0 results, open the "Signals" tab in the Terminal window (Ctrl+T) to force the terminal to download the list from the server.
  2. Performance Metrics: The property SIGNAL_BASE_PIPS is the primary metric for historical performance available via SignalBaseGetInteger.
  3. Subscription: This script only reads data. If you wish to subscribe to a signal programmatically based on this data, you would use the SignalSubscribe(long signal_id) function.

Q&A: MQL4 Signals

Q: Why does SignalBaseTotal() return 0 even though I have an internet connection?
A: The MetaTrader 4 terminal loads signals lazily. You must manually click the "Signals" tab in the terminal toolbox at least once per session to populate the internal database before the script can access it.

Q: Can I get the Drawdown percentage of a signal via MQL4?
A: In standard MQL4 SignalBase enumerations, Drawdown is not explicitly exposed as a direct property like Pips or Price. You typically have to rely on SIGNAL_BASE_PIPS and SIGNAL_BASE_EQUITY for performance assessment within the API limitations.

Q: How do I check if I am already subscribed to a signal?
A: You can use SignalInfoGetInteger(SIGNAL_INFO_ID) to get the ID of the signal currently subscribed to by the current account. If it returns 0, there is no active subscription.