Here's a custom MQL4 indicator for your Two-Bar Auction Model (MT2BAM) that plots buffers (not objects) for visual signals on XAU/USD M15. It tracks auction phases (L/H) and bar strength (0-2) across M15 (with optional H1/H4 alignment).
Indicator: MT2BAM_Oscillator.mq4
//+------------------------------------------------------------------+
//| MT2BAM Oscillator (MQL4) |
//| For XAU/USD M15 Testing |
//| Buffers (No Objects/Arrows) |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrRed
#property indicator_color3 clrLime
#property indicator_color4 clrGray
#property indicator_color5 clrGold
//--- Inputs
input bool ShowHigherTF = true; // Show H1/H4 alignment
input int HigherTF1 = PERIOD_H1; // Higher TF 1
input int HigherTF2 = PERIOD_H4; // Higher TF 2
input int SignalBarLookback = 1; // Bars to check for signals
//--- Buffers
double PhaseBuffer[]; // Auction Phase (L=-1, H=1)
double StrengthBuffer[]; // Bar Strength (0-2)
double HTF1Buffer[]; // Higher TF1 Phase
double HTF2Buffer[]; // Higher TF2 Phase
double SignalBuffer[]; // Buy/Sell Signal (1=Buy, -1=Sell)
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Set buffers
SetIndexBuffer(0, PhaseBuffer, INDICATOR_DATA);
SetIndexBuffer(1, StrengthBuffer, INDICATOR_DATA);
SetIndexBuffer(2, HTF1Buffer, INDICATOR_DATA);
SetIndexBuffer(3, HTF2Buffer, INDICATOR_DATA);
SetIndexBuffer(4, SignalBuffer, INDICATOR_DATA);
// Name labels
IndicatorShortName("MT2BAM Oscillator");
SetIndexLabel(0, "Auction Phase");
SetIndexLabel(1, "Bar Strength");
SetIndexLabel(2, "H1 Phase");
SetIndexLabel(3, "H4 Phase");
SetIndexLabel(4, "Signal");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
//--- Check if we have enough bars
if (rates_total < 10) return(0);
//--- Start calculation from the last bar
int start = (prev_calculated > 0) ? prev_calculated - 1 : 0;
for (int i = start; i >= 0 && !IsStopped(); i--)
{
//--- Get current auction phase (L=-1, H=1)
PhaseBuffer[i] = (i % 2 == 0) ? 1 : -1; // Even=H, Odd=L
//--- Get bar strength (0-2)
StrengthBuffer[i] = GetBarStrength(i, open, high, low, close);
//--- Get higher TF phases (if enabled)
if (ShowHigherTF)
{
HTF1Buffer[i] = GetHigherTFPhase(iTime(NULL, 0, i), HigherTF1);
HTF2Buffer[i] = GetHigherTFPhase(iTime(NULL, 0, i), HigherTF2);
}
else
{
HTF1Buffer[i] = EMPTY_VALUE;
HTF2Buffer[i] = EMPTY_VALUE;
}
//--- Generate signals (only if bar is confirmed)
if (i >= SignalBarLookback)
{
// Buy: Current bar is L (Phase=-1) + Strength=1 or 2 + HTF alignment
if (PhaseBuffer[i] == -1 &&
(StrengthBuffer[i] == 1 || StrengthBuffer[i] == 2) &&
(!ShowHigherTF || (HTF1Buffer[i] == -1 && HTF2Buffer[i] == -1)))
{
SignalBuffer[i] = 1; // Buy
}
// Sell: Current bar is H (Phase=1) + Strength=1 or 2 + HTF alignment
else if (PhaseBuffer[i] == 1 &&
(StrengthBuffer[i] == 1 || StrengthBuffer[i] == 2) &&
(!ShowHigherTF || (HTF1Buffer[i] == 1 && HTF2Buffer[i] == 1)))
{
SignalBuffer[i] = -1; // Sell
}
else
{
SignalBuffer[i] = EMPTY_VALUE;
}
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| Get Bar Strength (0-2) |
//+------------------------------------------------------------------+
int GetBarStrength(int index, const double &open[], const double &high[], const double &low[], const double &close[])
{
// Form 1: Strong (immediate trend)
if (PhaseBuffer[index] == -1 && close[index] > open[index] && low[index] <= low[index+1]) return 2; // Bullish
if (PhaseBuffer[index] == 1 && close[index] < open[index] && high[index] >= high[index+1]) return 2; // Bearish
// Form 2: Rejection
if (PhaseBuffer[index] == -1 && close[index] > open[index] && low[index] > low[index+1]) return 1; // Bullish
if (PhaseBuffer[index] == 1 && close[index] < open[index] && high[index] < high[index+1]) return 1; // Bearish
// Form 3: Weak (close near extreme)
if (PhaseBuffer[index] == -1 && close[index] <= low[index] + (high[index] - low[index]) * 0.2) return 0;
if (PhaseBuffer[index] == 1 && close[index] >= high[index] - (high[index] - low[index]) * 0.2) return 0;
return 1; // Default (moderate)
}
//+------------------------------------------------------------------+
//| Get Higher TF Phase (L=-1, H=1) |
//+------------------------------------------------------------------+
int GetHigherTFPhase(datetime time, int tf)
{
int barIndex = iBarShift(NULL, tf, time);
return (barIndex % 2 == 0) ? 1 : -1; // Even=H, Odd=L
}
//+------------------------------------------------------------------+
How to Use This Indicator
-
Attach to XAU/USD M15 chart (or any other pair/timeframe).
-
Interpretation:
- PhaseBuffer (Blue Line):
1 = High (H) bar
-1 = Low (L) bar
- StrengthBuffer (Red Line):
2 = Strong (Form 1)
1 = Moderate (Form 2)
0 = Weak (Form 3)
- HTF1Buffer (Gray) & HTF2Buffer (Gold):
- Shows H1/H4 phase alignment (if enabled).
- SignalBuffer (Lime):
1 = Buy (L bar with strength 1 or 2 + HTF alignment)
-1 = Sell (H bar with strength 1 or 2 + HTF alignment)
-
Manual Trading Rules:
- Buy when:
SignalBuffer = 1 (Lime line at 1)
- Price breaks the high of the Low (L) bar.
- Sell when:
SignalBuffer = -1 (Lime line at -1)
- Price breaks the low of the High (H) bar.
Limitations (MQL4 Constraints)
- No dynamic arrays → Fixed buffer sizes.
- No multi-timeframe in
OnCalculate → Uses iBarShift for HTF checks.
- No objects/arrows → Uses buffers for signals (cleaner for backtesting).
Next Steps for Testing
- Load 5 days of XAU/USD M15 data in MT4.
- Check alignment between:
- M15 Phase (Blue)
- Bar Strength (Red)
- H1/H4 Phase (Gray/Gold)
- Enter trades when:
- SignalBuffer (Lime) gives
1 or -1.
- Price confirms with a break of the bar’s extreme.
Would you like any modifications (e.g., adding alerts, optimizing for scalping, or filtering news events)?