Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Building a Confluence Signal Engine in MQL5: Leading Triggers, Confirmation Filters and a Live Dashboard - indicator for MetaTrader 5

Shipra Gupta
Shipra Gupta
I’m Shipra Gupta, a trader and quantitative strategy developer with a strong background in mathematics, economics, and algorithmic trading systems. Over the years, I’ve worked extensively across forex, gold, indices, commodities, and crypto markets, focusing on building data-driven trading
Views:
75
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

1. Why one indicator is never enough

Every indicator answers one question. A moving average answers "where is the trend?", RSI answers "how strong is the move?", a volatility filter answers "is the market even moving?". Trading on one answer produces a flood of signals in the wrong conditions. Confluence — requiring several independent answers to agree — is the oldest fix in technical analysis. The hard part is engineering it so that any combination works without writing new code each time.

This article walks through the architecture I use, with MQL5 code you can drop into your own projects.

2. The architecture: normalise everything to two booleans


The key design decision: every indicator, no matter how complex, is reduced to two boolean series — Long[i] and Short[i] . Once that contract exists, the signal engine does not care whether a row is a SuperTrend, an Ichimoku cloud or a volume filter.

struct SigArr { char L[]; char S[]; };      // one pair per indicator
SigArr g_sig[IND_COUNT];

void SS(const int id,const int i,const bool l,const bool s)
  {
   g_sig[id].L[i]=(char)(l?1:0);
   g_sig[id].S[i]=(char)(s?1:0);
  }

// Example: a simple EMA filter reduced to Long/Short
void CalcEmaFilter(const int id,const double &c[],const int n,const int len)
  {
   double a=2.0/(len+1.0), e=c[0];
   for(int i=0;i<n;i++)
     {
      e=(i==0)?c[0]:a*c[i]+(1.0-a)*e;
      SS(id,i,c[i]>e,c[i]<e);
     }
  }

Using char instead of bool keeps the arrays compact, and a struct with dynamic arrays lets you hold any number of indicators in a single fixed-size array.

3. Leading vs. confirmation

Not all inputs are equal. One indicator is the trigger — the event that starts a setup. The others are filters that must agree. Treating them differently matters: the trigger defines when, the filters define whether.

// Filters enabled by the user, stored as a compact id list
int g_conf[]; int g_nconf=0;

bool AllAgree(const int i,const bool longSide)
  {
   for(int k=0;k<g_nconf;k++)
     {
      int id=g_conf[k];
      if(longSide  && g_sig[id].L[i]==0) return(false);
      if(!longSide && g_sig[id].S[i]==0) return(false);
     }
   return(true);   // zero filters = trigger alone
  }

Want 53 ready-made engines wired into this exact architecture?
ConfluenceForge Pro ships 53 indicators, 18 overlays and a live dashboard — pick a trigger, tick your filters, done.
See ConfluenceForge Pro on the MQL5 Market

4. The expiry window: filters must agree in time


Filters rarely flip on the same candle as the trigger. Requiring same-bar agreement throws away good setups; allowing agreement at any time later produces stale entries. The solution is an expiry window: count how many consecutive bars the trigger has been active, and only accept the setup while that count is within N.

int cntL=0, state=0;               // state: +1 last long, -1 last short
for(int i=1;i<n;i++)
  {
   bool trig=g_sig[lead].L[i]!=0;
   cntL = trig ? cntL+1 : 0;        // how long has the trigger been on?
   bool valid = trig && AllAgree(i,true) && cntL<=expiry;
   if(valid && state!=1) { /* LONG signal on bar i */ }
   if(valid) state=1;               // alternate mode: no LONG after LONG
  }

The state variable implements alternate mode: after a long, the next printed signal must be a short. This removes the "five arrows in a row" clutter most multi-indicator tools suffer from.

5. Non-repainting by construction

Evaluate signals only on closed bars (skip index rates_total-1 ) and never let a later bar modify an earlier decision. Indicators that use pivots (fractals, swing-based zones) must only use pivots that are already confirmed — a pivot of length L at bar p is known at bar p+L , never earlier.

bool PivotHigh(const double &h[],const int p,const int L,const int R,const int n)
  {
   if(p-L<0 || p+R>=n) return(false);         // right side not printed yet
   for(int k=1;k<=L;k++) if(h[p-k]>=h[p]) return(false);
   for(int k=1;k<=R;k++) if(h[p+k]>h[p])  return(false);
   return(true);
  }

6. A dashboard users actually read


A confluence signal is only trusted if the trader can see the reasoning. A compact table with a Long and a Short column, one row per filter, answers the most common support question — "why didn't it signal here?" — before it is asked. Build it from OBJ_RECTANGLE_LABEL cells and OBJ_LABEL text, computing positions in pixels from the chart size so it works in any corner:

void Cell(string n,int x,int y,int w,int h,color bg)
  {
   if(ObjectFind(0,n)<0) ObjectCreate(0,n,OBJ_RECTANGLE_LABEL,0,0,0);
   ObjectSetInteger(0,n,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetInteger(0,n,OBJPROP_XDISTANCE,x); ObjectSetInteger(0,n,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(0,n,OBJPROP_XSIZE,w);     ObjectSetInteger(0,n,OBJPROP_YSIZE,h);
   ObjectSetInteger(0,n,OBJPROP_BGCOLOR,bg);  ObjectSetInteger(0,n,OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(0,n,OBJPROP_SELECTABLE,false); ObjectSetInteger(0,n,OBJPROP_HIDDEN,true);
  }
// check / cross marks: Wingdings 252 and 251
string Mark(bool ok){ return CharToString((uchar)(ok?252:251)); }

// bottom-right placement that survives chart resizes
int cw=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
int ch=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
int x0=cw-tableWidth-12, y0=ch-tableHeight-28;

Redraw the table in OnChartEvent on CHARTEVENT_CHART_CHANGE so it stays anchored when the user resizes the window.

See the full dashboard live — every filter, both directions, the passing score and the last signal, plus hover tooltips that list the filters that blocked an expired setup.
See ConfluenceForge Pro on the MQL5 Market

7. Performance: keep it fast with 50+ engines

  • Compute only what is used. Keep a done[] flag per indicator and calculate an engine only if it is the trigger, an enabled filter or a visible overlay.
  • Bound the window. Calculate the last N bars plus a warm-up margin (for example 3,000 + 700) rather than the full history.
  • Throttle ticks. Recalculate on every new bar, and at most every ~300 ms within a bar.
  • Redraw objects on new bars only. Zones, sessions and pivots do not change tick-by-tick; the dashboard does.

8. Free download: Sessions & PVSRA indicator


Attached to this publication is ConfluenceForge_Sessions_PVSRA_Free.mq5, a complete, compile-ready indicator that demonstrates two techniques from this article:

  • DST-aware sessions. Tokyo, London and New York boxes calculated in UTC, shifted for UK and US daylight saving (last Sunday of March/October; second Sunday of March / first Sunday of November), then converted to broker time using an automatic GMT offset ( TimeTradeServer()-TimeGMT() ).
  • PVSRA vector candles. Candles with volume ≥ 200% of the previous 10-bar average (or the highest spread×volume) and ≥ 150% are coloured with DRAW_COLOR_CANDLES .

Also included:

  • 5 preset files (Trend Rider, Kernel Scalper, Cloud Breaker, Squeeze Hunter, Mean Revert) — load them in the indicator's Inputs tab.
  • A printable cheat sheet mapping market conditions to trigger/filter combinations:

9. Choosing combinations that make sense

Family Answers Examples
Trend Which direction? SuperTrend, Half Trend, EMA 200, RQK, Ichimoku
Momentum Is the push strong now? MACD, RSI, QQE, Stochastic, TSI
Volatility / volume Is the market worth trading? Choppiness, Damiani, Squeeze, WAE, Volume

Pick one trigger and two or three filters from different families. Three trend filters agreeing is one opinion repeated three times; trend + momentum + volatility agreeing is genuine confluence.


Conclusion

A confluence engine is mostly a data-design problem: normalise every indicator to Long/Short booleans, separate the trigger from the filters, give filters an expiry window to agree in, evaluate on closed bars, and show the user the reasoning. With that contract in place, adding indicator number 54 is a single function.

Skip the build. Trade the result.
ConfluenceForge Pro: 53 indicators · 18 overlays · non-repainting signals · live dashboard · alerts · EA buffers.
See ConfluenceForge Pro on the MQL5 Market

Attachments: ConfluenceForge_Sessions_PVSRA_Free.mq5 · presets/*.set · ConfluenceForge_Cheat_Sheet.png. Trading involves risk; examples are educational and not investment advice.


Trend Strength Meter Using ADX in a Compact Dashboard Trend Strength Meter Using ADX in a Compact Dashboard

A compact on-chart dashboard that shows the trend strength of up to four timeframes using the ADX: value, strength bar, strength class and +DI/-DI direction, plus a summary row with the average ADX and the agreement of the directions.

Market Hours Label - is the symbol open now and when it closes Market Hours Label - is the symbol open now and when it closes

Small label on the chart. the symbol is open or closed now, the time left to the close or to the next open, and the sessions of today. It reads the trade sessions of your broker. Display only.

Trade Settings — Persist and Migrate Per-Trade Settings Trade Settings — Persist and Migrate Per-Trade Settings

Standalone MQL5 library for storing custom settings separately for each trade and following a verified pending-order-to-position lifecycle. It supports double, ulong and price-unit fields, terminal-local Global Variables, safe cleanup gates and an offline self-test. Includes a demo EA, source archive, and installation guide. A different-ticket transition, reconnection as a separate scenario, and netting behavior remain untested.

MACD Signals MACD Signals

Indicator edition for new platform.