QQE signals in MQL5 — converted from Pine Script
The QQE signals indicator by colinmck, published on TradingView under the Mozilla Public License 2.0, converted to MetaTrader 5 by the Stratlate engine. The conversion was executed against the original on 500 synthetic bars and compared value by value: equivalent (fidelity 1.000).
Inputs
| Input | Default |
|---|---|
| RSI Length | 14 |
| RSI Smoothing | 5 |
| Fast QQE Factor | 4.238 |
| Thresh-hold | 10 |
Converted MQL5
Save as qqe-signals.mq5 next to PineRuntime.mqh (included with every conversion), compile in MetaEditor, then review and backtest before trading. Output of the engine alone; the AI review available after sign-in may improve it further.
//+------------------------------------------------------------------+
//| pine-transpiler 0.6.46 (pinec) - generated code
//| source sha256: 1e695507ce27 status: CLEAN
//| notes: 0 unsupported, 0 warn, 0 info
//| Review, compile and backtest before trading.
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| QQE signals
//| Converted from Pine Script by pine-transpiler.
//| Review before trading: see the accompanying report for every
//| construct that was approximated or could not be converted.
//+------------------------------------------------------------------+
#property copyright "Converted by pine-transpiler"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_label1 "QQE long"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrDodgerBlue
#property indicator_width1 1
#property indicator_label2 "QQE short"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrDodgerBlue
#property indicator_width2 1
#include "PineRuntime.mqh"
//--- plot buffers
double Buf0[];
double Buf1[];
//--- script-level state
// The newest bar's index: `last_bar_index` and `barstate.islast`.
int __pineLastBar = 0;
// Series-valued names are arrays because their history is read;
// the rest stay scalars.
double src = PINE_NA;
int Wilders_Period = 0;
double Rsi = PINE_NA;
double RsiMa[];
double AtrRsi = PINE_NA;
double MaAtrRsi = PINE_NA;
double dar = PINE_NA;
double longband[];
double shortband[];
double trend[];
double DeltaFastAtrRsi = PINE_NA;
double RSIndex[];
double newshortband = PINE_NA;
double newlongband = PINE_NA;
bool cross_1 = false;
double FastAtrRsiTL[];
double QQExlong[];
double QQExshort[];
double qqeLong = PINE_NA;
double qqeShort = PINE_NA;
//--- live-tick rollback: the state each bar started from
double __sv_src;
double __si_src;
int __sv_Wilders_Period;
int __si_Wilders_Period;
double __sv_Rsi;
double __si_Rsi;
double __sv_AtrRsi;
double __si_AtrRsi;
double __sv_MaAtrRsi;
double __si_MaAtrRsi;
double __sv_dar;
double __si_dar;
double __sv_DeltaFastAtrRsi;
double __si_DeltaFastAtrRsi;
double __sv_newshortband;
double __si_newshortband;
double __sv_newlongband;
double __si_newlongband;
bool __sv_cross_1;
bool __si_cross_1;
double __sv_qqeLong;
double __si_qqeLong;
double __sv_qqeShort;
double __si_qqeShort;
int __pineSnapBar = -1;
void __pineSaveState()
{
__sv_src = src;
__sv_Wilders_Period = Wilders_Period;
__sv_Rsi = Rsi;
__sv_AtrRsi = AtrRsi;
__sv_MaAtrRsi = MaAtrRsi;
__sv_dar = dar;
__sv_DeltaFastAtrRsi = DeltaFastAtrRsi;
__sv_newshortband = newshortband;
__sv_newlongband = newlongband;
__sv_cross_1 = cross_1;
__sv_qqeLong = qqeLong;
__sv_qqeShort = qqeShort;
pine_draw_mark();
__pineSaveGen++; // helpers' static arrays snapshot lazily
}
void __pineRestoreState()
{
src = __sv_src;
Wilders_Period = __sv_Wilders_Period;
Rsi = __sv_Rsi;
AtrRsi = __sv_AtrRsi;
MaAtrRsi = __sv_MaAtrRsi;
dar = __sv_dar;
DeltaFastAtrRsi = __sv_DeltaFastAtrRsi;
newshortband = __sv_newshortband;
newlongband = __sv_newlongband;
cross_1 = __sv_cross_1;
qqeLong = __sv_qqeLong;
qqeShort = __sv_qqeShort;
pine_draw_rollback();
__pineRestoreGen++;
__pineRestoreSaveGen = __pineSaveGen;
}
void __pineSaveInitial()
{
__si_src = src;
__si_Wilders_Period = Wilders_Period;
__si_Rsi = Rsi;
__si_AtrRsi = AtrRsi;
__si_MaAtrRsi = MaAtrRsi;
__si_dar = dar;
__si_DeltaFastAtrRsi = DeltaFastAtrRsi;
__si_newshortband = newshortband;
__si_newlongband = newlongband;
__si_cross_1 = cross_1;
__si_qqeLong = qqeLong;
__si_qqeShort = qqeShort;
pine_draw_save_initial();
}
void __pineRestoreInitial()
{
src = __si_src;
Wilders_Period = __si_Wilders_Period;
Rsi = __si_Rsi;
AtrRsi = __si_AtrRsi;
MaAtrRsi = __si_MaAtrRsi;
dar = __si_dar;
DeltaFastAtrRsi = __si_DeltaFastAtrRsi;
newshortband = __si_newshortband;
newlongband = __si_newlongband;
cross_1 = __si_cross_1;
qqeLong = __si_qqeLong;
qqeShort = __si_qqeShort;
pine_draw_reset();
__pineInitGen++;
}
double __st0[]; // accumulator for one stateful call site
double __stb0[]; // secondary buffer (e.g. true range for ATR)
double __st1[]; // accumulator for one stateful call site
double __stb1[]; // secondary buffer (e.g. true range for ATR)
double __st2[]; // accumulator for one stateful call site
double __stb2[]; // secondary buffer (e.g. true range for ATR)
double __st3[]; // accumulator for one stateful call site
double __stb3[]; // secondary buffer (e.g. true range for ATR)
double __st4[]; // accumulator for one stateful call site
double __stb4[]; // secondary buffer (e.g. true range for ATR)
double __st5[]; // accumulator for one stateful call site
double __stb5[]; // secondary buffer (e.g. true range for ATR)
double __ti0[]; // materialised ta.* source: src
double __ti1[]; // materialised ta.* source: Rsi
double __ti2[]; // materialised ta.* source: AtrRsi
double __ti3[]; // materialised ta.* source: MaAtrRsi
double __ti4[]; // materialised ta.* source: pine_hist(longband, __pineBar, (int)(1))
double __ti5[]; // materialised ta.* source: pine_hist(shortband, __pineBar, (int)(1))
//--- inputs
input int RSI_Period = 14; // RSI Length
input int SF = 5; // RSI Smoothing
input double QQE = 4.238; // Fast QQE Factor
input int ThreshHold = 10; // Thresh-hold
int OnInit()
{
Wilders_Period = ((RSI_Period * 2) - 1);
SetIndexBuffer(0, Buf0, INDICATOR_DATA);
SetIndexBuffer(1, Buf1, INDICATOR_DATA);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(0, PLOT_LINE_COLOR, C'76,175,80');
PlotIndexSetInteger(1, PLOT_LINE_COLOR, C'242,54,69');
PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(0, PLOT_ARROW, 241);
PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, 16);
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW);
PlotIndexSetInteger(1, PLOT_ARROW, 242);
PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, -16);
IndicatorSetString(INDICATOR_SHORTNAME, "QQE signals");
__pineSaveInitial();
return INIT_SUCCEEDED;
}
//--- one bar == one evaluation of the original Pine script
void PineBar(const int __pineBar,
const double &open[], const double &high[],
const double &low[], const double &close[],
const long &volume[],
const datetime &time[])
{
if(__pineBar > 0)
{
RsiMa[__pineBar] = RsiMa[__pineBar - 1];
longband[__pineBar] = longband[__pineBar - 1];
shortband[__pineBar] = shortband[__pineBar - 1];
trend[__pineBar] = trend[__pineBar - 1];
RSIndex[__pineBar] = RSIndex[__pineBar - 1];
FastAtrRsiTL[__pineBar] = FastAtrRsiTL[__pineBar - 1];
QQExlong[__pineBar] = QQExlong[__pineBar - 1];
QQExshort[__pineBar] = QQExshort[__pineBar - 1];
}
src = close[__pineBar];
Wilders_Period = ((RSI_Period * 2) - 1);
__ti0[__pineBar] = src;
Rsi = pine_rsi(__ti0, __st0, __stb0, __pineBar, (int)(RSI_Period));
__ti1[__pineBar] = Rsi;
RsiMa[__pineBar] = pine_ema(__ti1, __st1, __pineBar, (int)(SF));
AtrRsi = MathAbs((pine_hist(RsiMa, __pineBar, (int)(1)) - RsiMa[__pineBar]));
__ti2[__pineBar] = AtrRsi;
MaAtrRsi = pine_ema(__ti2, __st2, __pineBar, (int)(Wilders_Period));
__ti3[__pineBar] = MaAtrRsi;
dar = (pine_ema(__ti3, __st3, __pineBar, (int)(Wilders_Period)) * QQE);
longband[__pineBar] = 0.0;
shortband[__pineBar] = 0.0;
trend[__pineBar] = 0;
DeltaFastAtrRsi = dar;
RSIndex[__pineBar] = RsiMa[__pineBar];
newshortband = (RSIndex[__pineBar] + DeltaFastAtrRsi);
newlongband = (RSIndex[__pineBar] - DeltaFastAtrRsi);
longband[__pineBar] = (((((pine_hist(RSIndex, __pineBar, (int)(1)) > pine_hist(longband, __pineBar, (int)(1))) ? 1 : 0) & ((RSIndex[__pineBar] > pine_hist(longband, __pineBar, (int)(1))) ? 1 : 0)) != 0) ? MathMax(pine_hist(longband, __pineBar, (int)(1)), newlongband) : newlongband);
shortband[__pineBar] = (((((pine_hist(RSIndex, __pineBar, (int)(1)) < pine_hist(shortband, __pineBar, (int)(1))) ? 1 : 0) & ((RSIndex[__pineBar] < pine_hist(shortband, __pineBar, (int)(1))) ? 1 : 0)) != 0) ? MathMin(pine_hist(shortband, __pineBar, (int)(1)), newshortband) : newshortband);
__ti4[__pineBar] = pine_hist(longband, __pineBar, (int)(1));
cross_1 = pine_cross(__ti4, RSIndex, __pineBar);
__ti5[__pineBar] = pine_hist(shortband, __pineBar, (int)(1));
trend[__pineBar] = (pine_cross(RSIndex, __ti5, __pineBar) ? 1 : (cross_1 ? (-1) : pine_nz(pine_hist(trend, __pineBar, (int)(1)), 1)));
FastAtrRsiTL[__pineBar] = ((trend[__pineBar] == 1) ? longband[__pineBar] : shortband[__pineBar]);
QQExlong[__pineBar] = 0;
QQExlong[__pineBar] = pine_nz(pine_hist(QQExlong, __pineBar, (int)(1)));
QQExshort[__pineBar] = 0;
QQExshort[__pineBar] = pine_nz(pine_hist(QQExshort, __pineBar, (int)(1)));
QQExlong[__pineBar] = ((FastAtrRsiTL[__pineBar] < RSIndex[__pineBar]) ? (QQExlong[__pineBar] + 1) : 0);
QQExshort[__pineBar] = ((FastAtrRsiTL[__pineBar] > RSIndex[__pineBar]) ? (QQExshort[__pineBar] + 1) : 0);
qqeLong = ((QQExlong[__pineBar] == 1) ? (pine_hist(FastAtrRsiTL, __pineBar, (int)(1)) - 50) : PINE_NA);
qqeShort = ((QQExshort[__pineBar] == 1) ? (pine_hist(FastAtrRsiTL, __pineBar, (int)(1)) - 50) : PINE_NA);
pine_alertcond(qqeLong, "Long", 1690245061, __pineBar, __pineLastBar);
pine_alertcond(qqeShort, "Short", 275798225, __pineBar, __pineLastBar);
Buf0[__pineBar] = pine_truthy(qqeLong) ? low[__pineBar] : EMPTY_VALUE;
pine_shape_text("0", __pineBar, Buf0[__pineBar], "Long", C'76,175,80', false);
Buf1[__pineBar] = pine_truthy(qqeShort) ? high[__pineBar] : EMPTY_VALUE;
pine_shape_text("1", __pineBar, Buf1[__pineBar], "Short", C'242,54,69', true);
}
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[])
{
// Pine evaluates oldest-to-newest. MQL4 hands OnCalculate
// SERIES-indexed arrays (0 == newest) while MQL5 hands over
// oldest-first, so the direction is forced explicitly rather
// than relying on either default. `x[n]` is then index i - n
// in both dialects, and the generated logic is identical.
ArraySetAsSeries(open, false);
ArraySetAsSeries(high, false);
ArraySetAsSeries(low, false);
ArraySetAsSeries(close, false);
ArraySetAsSeries(tick_volume, false);
ArraySetAsSeries(volume, false);
ArraySetAsSeries(time, false);
ArrayResize(RsiMa, rates_total);
ArrayResize(longband, rates_total);
ArrayResize(shortband, rates_total);
ArrayResize(trend, rates_total);
ArrayResize(RSIndex, rates_total);
ArrayResize(FastAtrRsiTL, rates_total);
ArrayResize(QQExlong, rates_total);
ArrayResize(QQExshort, rates_total);
ArrayResize(__st0, rates_total);
ArrayResize(__stb0, rates_total);
ArrayResize(__st1, rates_total);
ArrayResize(__stb1, rates_total);
ArrayResize(__st2, rates_total);
ArrayResize(__stb2, rates_total);
ArrayResize(__st3, rates_total);
ArrayResize(__stb3, rates_total);
ArrayResize(__st4, rates_total);
ArrayResize(__stb4, rates_total);
ArrayResize(__st5, rates_total);
ArrayResize(__stb5, rates_total);
ArrayResize(__ti0, rates_total);
ArrayResize(__ti1, rates_total);
ArrayResize(__ti2, rates_total);
ArrayResize(__ti3, rates_total);
ArrayResize(__ti4, rates_total);
ArrayResize(__ti5, rates_total);
if(prev_calculated == 0)
{
ArrayInitialize(RsiMa, PINE_NA);
ArrayInitialize(longband, PINE_NA);
ArrayInitialize(shortband, PINE_NA);
ArrayInitialize(trend, PINE_NA);
ArrayInitialize(RSIndex, PINE_NA);
ArrayInitialize(FastAtrRsiTL, PINE_NA);
ArrayInitialize(QQExlong, PINE_NA);
ArrayInitialize(QQExshort, PINE_NA);
ArrayInitialize(__st0, PINE_NA);
ArrayInitialize(__stb0, PINE_NA);
ArrayInitialize(__st1, PINE_NA);
ArrayInitialize(__stb1, PINE_NA);
ArrayInitialize(__st2, PINE_NA);
ArrayInitialize(__stb2, PINE_NA);
ArrayInitialize(__st3, PINE_NA);
ArrayInitialize(__stb3, PINE_NA);
ArrayInitialize(__st4, PINE_NA);
ArrayInitialize(__stb4, PINE_NA);
ArrayInitialize(__st5, PINE_NA);
ArrayInitialize(__stb5, PINE_NA);
ArrayInitialize(__ti0, PINE_NA);
ArrayInitialize(__ti1, PINE_NA);
ArrayInitialize(__ti2, PINE_NA);
ArrayInitialize(__ti3, PINE_NA);
ArrayInitialize(__ti4, PINE_NA);
ArrayInitialize(__ti5, PINE_NA);
}
__pineLastBar = rates_total - 1;
const int start = (prev_calculated > 1) ? prev_calculated - 1 : 0;
static bool __pineRealVolume = false;
if(start == 0)
{
__pineRestoreInitial();
__pineSnapBar = -1;
__pineRealVolume = rates_total > 0 && volume[rates_total - 1] > 0;
}
__pineRealtime = prev_calculated > 0;
for(int __pineBar = start; __pineBar < rates_total; __pineBar++)
{
if(__pineBar == __pineSnapBar)
__pineRestoreState(); // a re-run of this bar: back to its start
else if(__pineBar == __pineLastBar)
{
__pineSaveState(); // the forming bar: remember the state it starts from
__pineSnapBar = __pineBar;
}
if(__pineRealVolume) PineBar(__pineBar, open, high, low, close, volume, time);
else PineBar(__pineBar, open, high, low, close, tick_volume, time);
}
return rates_total;
}
void OnDeinit(const int reason)
{
ObjectsDeleteAll(0, "pine_");
}Original Pine Script
© colinmck — Mozilla Public License 2.0. Reproduced for attribution and comparison; the converted code above is a derivative work offered under the same licence.
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © colinmck
study("QQE signals", overlay=true)
RSI_Period = input(14, title='RSI Length')
SF = input(5, title='RSI Smoothing')
QQE = input(4.238, title='Fast QQE Factor')
ThreshHold = input(10, title="Thresh-hold")
src = close
Wilders_Period = RSI_Period * 2 - 1
Rsi = rsi(src, RSI_Period)
RsiMa = ema(Rsi, SF)
AtrRsi = abs(RsiMa[1] - RsiMa)
MaAtrRsi = ema(AtrRsi, Wilders_Period)
dar = ema(MaAtrRsi, Wilders_Period) * QQE
longband = 0.0
shortband = 0.0
trend = 0
DeltaFastAtrRsi = dar
RSIndex = RsiMa
newshortband = RSIndex + DeltaFastAtrRsi
newlongband = RSIndex - DeltaFastAtrRsi
longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? max(longband[1], newlongband) : newlongband
shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? min(shortband[1], newshortband) : newshortband
cross_1 = cross(longband[1], RSIndex)
trend := cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
FastAtrRsiTL = trend == 1 ? longband : shortband
// Find all the QQE Crosses
QQExlong = 0
QQExlong := nz(QQExlong[1])
QQExshort = 0
QQExshort := nz(QQExshort[1])
QQExlong := FastAtrRsiTL < RSIndex ? QQExlong + 1 : 0
QQExshort := FastAtrRsiTL > RSIndex ? QQExshort + 1 : 0
//Conditions
qqeLong = QQExlong == 1 ? FastAtrRsiTL[1] - 50 : na
qqeShort = QQExshort == 1 ? FastAtrRsiTL[1] - 50 : na
// Plotting
plotshape(qqeLong, title="QQE long", text="Long", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny)
plotshape(qqeShort, title="QQE short", text="Short", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny)
// Alerts
alertcondition(qqeLong, title="Long", message="Long")
alertcondition(qqeShort, title="Short", message="Short")Convert your own Pine Script to MQL5
Your first conversion is free, in either direction. Paste a TradingView indicator or strategy and get MQL5 or MQL4 source, with every construct the engine could not map flagged by line.
Open the converterMore: all example conversions · how Pine Script maps to MQL5 · how the engine measures