QQE MQL5 Indicator: Custom MT5 Oscillator, Alerts & EA Code Guide
This page explains how to build and deploy the Quantitative Qualitative Estimation (QQE) indicator in MQL5 for MetaTrader 5. You will learn the RSI smoothing logic, double Wilder ATR volatility bands, Fast and Slow line crossover detection, push alerts, and automated Expert Advisor order execution.
What this MT5 indicator covers
Complete MQL5 indicator source code plotting Fast QQE and Slow adaptive trailing lines in MetaTrader 5
Double Wilder smoothing calculation applied to RSI true range with the standard 4.236 Fibonacci volatility multiplier
Crossover alert engine supporting MT5 terminal popups and mobile push notifications
Built-in Expert Advisor trading logic with automated order execution, stop-loss, and take-profit handling
Zero repainting on closed bars through strict bar confirmation rules in OnCalculate
Historical test results
Past performance is not indicative of future results. Backtest statistics are based on historical data and do not guarantee future profits. Trading involves significant risk of loss. This content is for educational purposes only and does not constitute financial advice.
How the indicator signal works
Bullish flip
A long entry triggers when the Fast QQE line crosses above the Slow trailing line on a closed bar, with momentum breaking above the 50 centerline. A short entry triggers when the Fast QQE line crosses below the Slow trailing line on a closed bar, confirming a shift into bearish territory below 50.
Bearish flip
Long positions close when the Fast line crosses back below the Slow line or when price reaches the take-profit target (2:1 reward-to-risk ratio). Short positions close on an opposing bullish crossover or at the defined stop-loss level. An ATR-based trailing stop secures open profits as the trend extends.
MQL5 Custom Indicator Code
//+------------------------------------------------------------------+
//| QQE_MT5_Indicator_EA.mq5 |
//| Quantitative Qualitative Estimation for MetaTrader 5 |
//| Platform : MetaTrader 5 (MQL5) |
//| Website : https://pineify.app |
//+------------------------------------------------------------------+
#property copyright "Pineify"
#property link "https://pineify.app"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots 2
//--- Plot 1: Fast Line
#property indicator_label1 "QQE Fast"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrCrimson
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- Plot 2: Slow Trailing Line
#property indicator_label2 "QQE Slow"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDodgerBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
#include <Trade\Trade.mqh>
//--- Input parameters
input group "=== QQE Parameters ==="
input int InpRSIPeriod = 14; // RSI Period
input int InpSF = 5; // RSI Smoothing Factor (EMA)
input double InpQQEFactor = 4.236; // QQE Multiplier (Fast ATR Multiplier)
input double InpThreshold = 50.0; // Centerline Threshold
input group "=== Alert Settings ==="
input bool InpEnableAlerts = true; // Enable Popup and Push Alerts
input group "=== Expert Advisor Settings ==="
input bool InpEnableTrading = false; // Enable Automated Trading
input double InpLotSize = 0.10; // Trade Lot Size
input int InpStopLossPips = 40; // Stop Loss in Pips
input int InpTakeProfitPips = 80; // Take Profit in Pips
input ulong InpMagicNumber = 20260830; // Magic Number
//--- Indicator buffers
double BufferFast[];
double BufferSlow[];
double BufferRSI[];
double BufferATR_RSI[];
//--- Global handles and objects
int g_rsiHandle = INVALID_HANDLE;
CTrade g_trade;
datetime g_lastBarTime = 0;
bool g_alertedBuy = false;
bool g_alertedSell = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Bind indicator buffers
SetIndexBuffer(0, BufferFast, INDICATOR_DATA);
SetIndexBuffer(1, BufferSlow, INDICATOR_DATA);
SetIndexBuffer(2, BufferRSI, INDICATOR_CALCULATIONS);
SetIndexBuffer(3, BufferATR_RSI, INDICATOR_CALCULATIONS);
ArraySetAsSeries(BufferFast, true);
ArraySetAsSeries(BufferSlow, true);
ArraySetAsSeries(BufferRSI, true);
ArraySetAsSeries(BufferATR_RSI, true);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0);
//--- Create standard RSI handle
g_rsiHandle = iRSI(_Symbol, _Period, InpRSIPeriod, PRICE_CLOSE);
if(g_rsiHandle == INVALID_HANDLE)
{
Print("ERROR: Failed to create iRSI handle. Code=", GetLastError());
return INIT_FAILED;
}
//--- Configure trade instance
if(InpEnableTrading)
{
g_trade.SetExpertMagicNumber(InpMagicNumber);
g_trade.SetDeviationInPoints(20);
g_trade.SetTypeFilling(ORDER_FILLING_IOC);
}
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("QQE(%d,%d,%.3f)", InpRSIPeriod, InpSF, InpQQEFactor));
IndicatorSetInteger(INDICATOR_DIGITS, 2);
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(g_rsiHandle != INVALID_HANDLE)
IndicatorRelease(g_rsiHandle);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
if(rates_total < InpRSIPeriod + InpSF + 10)
return 0;
int toCopy = rates_total;
if(prev_calculated > 0)
toCopy = rates_total - prev_calculated + 2;
double rsiRaw[];
ArraySetAsSeries(rsiRaw, true);
if(CopyBuffer(g_rsiHandle, 0, 0, toCopy, rsiRaw) <= 0)
return 0;
//--- Calculate EMA smoothed RSI (Fast Line)
double alphaEMA = 2.0 / (InpSF + 1.0);
int limit = rates_total - 1;
if(prev_calculated > 0)
limit = rates_total - prev_calculated + 1;
for(int i = limit; i >= 0; i--)
{
if(i >= ArraySize(rsiRaw))
continue;
if(i == rates_total - 1 || BufferFast[i + 1] == 0.0)
BufferFast[i] = rsiRaw[i];
else
BufferFast[i] = alphaEMA * rsiRaw[i] + (1.0 - alphaEMA) * BufferFast[i + 1];
//--- Wilder true range smoothing on smoothed RSI
double tr = 0.0;
if(i < rates_total - 1)
tr = MathAbs(BufferFast[i] - BufferFast[i + 1]);
double alphaWilder = 1.0 / (double)InpRSIPeriod;
if(i == rates_total - 1 || BufferATR_RSI[i + 1] == 0.0)
BufferATR_RSI[i] = tr;
else
BufferATR_RSI[i] = alphaWilder * tr + (1.0 - alphaWilder) * BufferATR_RSI[i + 1];
//--- Adaptive trailing band (Slow Line)
double dar = BufferATR_RSI[i] * InpQQEFactor;
double upperBand = BufferFast[i] + dar;
double lowerBand = BufferFast[i] - dar;
if(i == rates_total - 1 || BufferSlow[i + 1] == 0.0)
{
BufferSlow[i] = lowerBand;
}
else
{
double prevSlow = BufferSlow[i + 1];
double prevFast = BufferFast[i + 1];
if(prevFast > prevSlow)
{
BufferSlow[i] = (lowerBand > prevSlow) ? lowerBand : prevSlow;
if(BufferFast[i] < prevSlow)
BufferSlow[i] = upperBand;
}
else
{
BufferSlow[i] = (upperBand < prevSlow) ? upperBand : prevSlow;
if(BufferFast[i] > prevSlow)
BufferSlow[i] = lowerBand;
}
}
}
//--- Execute trading and alert checks on bar close
datetime currentBar = time[rates_total - 1];
if(currentBar != g_lastBarTime && rates_total > 2)
{
g_lastBarTime = currentBar;
CheckSignals(BufferFast[1], BufferSlow[1], BufferFast[2], BufferSlow[2]);
}
return rates_total;
}
//+------------------------------------------------------------------+
//| Check crossover signals on bar close |
//+------------------------------------------------------------------+
void CheckSignals(double fast1, double slow1, double fast2, double slow2)
{
bool buyCross = (fast2 <= slow2 && fast1 > slow1);
bool sellCross = (fast2 >= slow2 && fast1 < slow1);
double point = _Point;
if(_Digits == 3 || _Digits == 5)
point *= 10;
if(buyCross)
{
if(InpEnableAlerts && !g_alertedBuy)
{
string msg = StringFormat("%s (%s): QQE Bullish Crossover. Fast=%.2f, Slow=%.2f",
_Symbol, EnumToString(_Period), fast1, slow1);
Alert(msg);
SendNotification(msg);
g_alertedBuy = true;
g_alertedSell = false;
}
if(InpEnableTrading)
{
ClosePositions(POSITION_TYPE_SELL);
if(CountPositions(POSITION_TYPE_BUY) == 0)
{
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double sl = (InpStopLossPips > 0) ? ask - InpStopLossPips * point : 0;
double tp = (InpTakeProfitPips > 0) ? ask + InpTakeProfitPips * point : 0;
g_trade.Buy(InpLotSize, _Symbol, ask, sl, tp, "QQE Buy Entry");
}
}
}
if(sellCross)
{
if(InpEnableAlerts && !g_alertedSell)
{
string msg = StringFormat("%s (%s): QQE Bearish Crossunder. Fast=%.2f, Slow=%.2f",
_Symbol, EnumToString(_Period), fast1, slow1);
Alert(msg);
SendNotification(msg);
g_alertedSell = true;
g_alertedBuy = false;
}
if(InpEnableTrading)
{
ClosePositions(POSITION_TYPE_BUY);
if(CountPositions(POSITION_TYPE_SELL) == 0)
{
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double sl = (InpStopLossPips > 0) ? bid + InpStopLossPips * point : 0;
double tp = (InpTakeProfitPips > 0) ? bid - InpTakeProfitPips * point : 0;
g_trade.Sell(InpLotSize, _Symbol, bid, sl, tp, "QQE Sell Entry");
}
}
}
}
//+------------------------------------------------------------------+
//| Count active positions for this EA magic number |
//+------------------------------------------------------------------+
int CountPositions(ENUM_POSITION_TYPE posType)
{
int count = 0;
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol &&
PositionGetInteger(POSITION_MAGIC) == (long)InpMagicNumber &&
PositionGetInteger(POSITION_TYPE) == posType)
{
count++;
}
}
}
return count;
}
//+------------------------------------------------------------------+
//| Close active positions of specific type |
//+------------------------------------------------------------------+
void ClosePositions(ENUM_POSITION_TYPE posType)
{
for(int i = PositionsTotal() - 1; i >= 0; i--)
{
ulong ticket = PositionGetTicket(i);
if(PositionSelectByTicket(ticket))
{
if(PositionGetString(POSITION_SYMBOL) == _Symbol &&
PositionGetInteger(POSITION_MAGIC) == (long)InpMagicNumber &&
PositionGetInteger(POSITION_TYPE) == posType)
{
g_trade.PositionClose(ticket);
}
}
}
}Copy this code into MetaEditor, save it in the MQL5/Indicators folder, and compile with F7.
Change the settings or add your own signal filter
Describe the inputs, buffers, alerts, visual style, or confirmation filter you want. Pineify generates editable MQL5 source code that you can inspect and compile in MetaEditor.
Pine Script vs MQL5: Same Strategy, Different Platforms
| Aspect | Pine Script (TradingView) | MQL5 (MetaTrader 5) |
|---|---|---|
| Execution | Series evaluated on chart updates | Event handlers with explicit buffers |
| Deployment | Runs in TradingView with alerts | Runs in the MT5 terminal or on a VPS |
| Broker access | Via TradingView broker integration | Direct broker connectivity |
| Backtesting | Strategy Tester for strategy scripts | Strategy Tester for Expert Advisors |
| Code complexity | Simpler, functional syntax | C++-like, more powerful |
The calculation can be implemented on either platform, but the runtime model and buffer APIs differ. Read the Pine Script reference guide before porting logic between them.
Frequently Asked Questions
Related MQL5 pages
Technical references
Risk and testing note
Past performance is not indicative of future results. Backtest statistics are based on historical data and do not guarantee future profits. Trading involves significant risk of loss. This content is for educational purposes only and does not constitute financial advice.