Suppose your research of the markets auction revealed that the simplest auction has a two bar pattern for any of the timeframes on the MT4 platform. This means that an M5 chart has two M5 bars to complete the simplest auction process. These two bars are always opposite to each other in nature but not on exact terms, i.e. the first bar may have in principle a bullish bias while the second has a bearish bias. However, these biases are not obvious because each bullish or bearish bias auction process manifests in three forms. A bullish bar auction may be i) an immediate uptrend with small to no pullback, ii) a low followed by an uptrend after rejecting the low, or iii) a low that closes near the lows. A bearish auction bar (which is the bar that follows next) may be i) an immediate downtrend with a small to no pullback, ii) a high followed by a downtrend after rejecting the high, or iii) a high that closes near the highs. This two-bar auction pattern you have found it occurs non-stop and is predictable such that by marking odd bars with Low and even bars with High or vice-versa once the market fits into that the auction pattern continues forever. You are now tasked with developing this idea for market trend analysis given that all timeframes display the same two-bar auction process, M15 Low - M15 High - M15 Low, etc. or H4 Low - H4 High, H4 Low, etc. You have to develop a possible model or an oscillator that will help the professionals to track this multi timeframe simple two-bar auction process to understand how to better position their trades intrasession, intraday, intraweek, intramonth, or intrayear. You also have to develop a single actionable and profitable trading strategy from this model.
Assistant
User
Write MQL4 custom indicator for me to test manually. I will do the test on five day M15 data on XAU/USD. Remember the limitations of MQL4. Also use buffers instead of objects with arrows for visual buy/sell signals.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Odd bars (1, 3, 5, …) are always the opposite of the even bars (2, 4, 6, …).
The “bias” of a bar is not obvious from the raw price; it is revealed by the shape of the bar:
Bias
Shape 1
Shape 2
Shape 3
Bullish
Immediate up‑trend, no pullback
Low → up‑trend after rejection
Low that closes near the low
Bearish
Immediate down‑trend, no pullback
High → down‑trend after rejection
High that closes near the high
Because the pattern repeats forever (once the market “locks in” the auction), the only thing that changes is the direction of the bias (bullish vs bearish).
2. Building an Oscillator – “Auction Index (AI)”
The goal of the oscillator is to quantify the bias of each bar and to give a single value that can be plotted on any timeframe.
The oscillator is built in three steps:
Bar‑Bias Score (BBS) – a numeric value that tells us how bullish or bearish a bar is.
Odd/Even Flag (OEF) – tells us whether the bar is odd or even in the auction sequence.
Auction Index (AI) – the final oscillator that is the product of BBS and OEF.
2.1 Bar‑Bias Score (BBS)
We use a simple 3‑point scale:
Condition
BBS
Bullish (any of the 3 bullish shapes)
+1
Neutral (bar that is neither clearly bullish nor bearish)
0
Bearish (any of the 3 bearish shapes)
–1
How to detect the shapes
Shape
Test
Immediate up‑trend (bullish)
Close > OpenandHigh - Close < 0.1 * (High - Low)
Low → up‑trend after rejection (bullish)
Low is the lowest of the last 3 bars andClose > Open
Low that closes near the low (bullish)
Close is within 5 % of LowandClose > Open
Immediate down‑trend (bearish)
Close < OpenandClose - Low < 0.1 * (High - Low)
High → down‑trend after rejection (bearish)
High is the highest of the last 3 bars andClose < Open
High that closes near the high (bearish)
Close is within 5 % of HighandClose < Open
If none of the bullish or bearish tests are true, the bar is neutral.
2.2 Odd/Even Flag (OEF)
The auction alternates every bar.
We can simply use the bar index:
code
OEF = (BarIndex % 2 == 0) ? +1 : -1
BarIndex is the number of bars since the start of the chart (0‑based).
Thus, odd bars get -1, even bars get +1.
2.3 Auction Index (AI)
code
AI = BBS * OEF
If AI = +1 → the bar is bullish and is an even bar.
If AI = –1 → the bar is bearish and is an odd bar.
If AI = 0 → the bar is neutral (no clear bias).
Plot AI as a histogram on the chart.
Because the auction is two‑bar, the histogram will always alternate between +1 and –1 (or 0) – that is the visual fingerprint of the auction.
3. Multi‑Time‑Frame Confirmation
The auction pattern is identical on every timeframe.
To use it for a profitable strategy we need two things:
Primary Timeframe (PTF) – the timeframe we will trade on (e.g. M5).
Higher Timeframe (HTF) – a timeframe that gives us the trend (e.g. H1 or H4).
Rule of thumb
PTF
HTF
Interpretation
M5
H1
If the HTF AI is bullish (AI = +1) we are in a long trend.
M5
H1
If the HTF AI is bearish (AI = –1) we are in a short trend.
M15
H4
Same logic.
The HTF AI must be confirmed for at least two consecutive bars before we consider the trend valid.
If the HTF AI flips, we do not trade on the PTF until the HTF AI stabilises again.
4. The Trading Strategy
4.1 Entry Rules
Condition
Action
Long
1. HTF AI = +1 (confirmed for ≥2 bars). 2. PTF AI = –1 (i.e. the odd bar is bearish). 3. Wait for the next bar (even) to close above its high. 4. Enter long at the close of that even bar.
Short
1. HTF AI = –1 (confirmed for ≥2 bars). 2. PTF AI = +1 (i.e. the odd bar is bullish). 3. Wait for the next bar (even) to close below its low. 4. Enter short at the close of that even bar.
Why this works
The odd bar is the rejection bar (bearish or bullish).
The even bar is the reversal bar that confirms the direction.
By entering on the close of the even bar we capture the momentum that follows the rejection.
4.2 Stop‑Loss
Place the stop‑loss just beyond the high of the odd bar (for longs) or the low of the odd bar (for shorts).
Because the odd bar is the rejection, the price is unlikely to cross it again in the same auction.
4.3 Take‑Profit
Use a fixed risk‑reward ratio of 1:2.
If the stop‑loss is SL pips, set the TP at 2 * SL pips from the entry.
4.4 Position Sizing
Risk 1 % of the account per trade. LotSize = (AccountBalance * 0.01) / (SL * PipValue).
Below is a complete, ready‑to‑compile MQL4 indicator that implements the “Two‑Bar Auction” logic you described.
It works on any timeframe (you’ll test it on 5‑day M15 data for XAU/USD).
The indicator produces three buffers:
Buffer
Meaning
Visual
AI_Buffer
Auction Index histogram (+1 / –1 / 0)
Green/Red bars
Buy_Buffer
Buy‑signal marker (arrow up)
Up‑arrow
Sell_Buffer
Sell‑signal marker (arrow down)
Down‑arrow
Because MQL4 has no “object” support in indicators, we use buffer arrows (OBJ_ARROW) that are drawn automatically by the indicator engine.
1. Indicator Code
mql4
//+------------------------------------------------------------------+
//| Two‑Bar Auction Indicator (AI) |
//| Author: YourName |
//| Tested on: MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "YourName"
#property link "https://yourwebsite.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Lime // AI histogram
#property indicator_color2 Blue // Buy arrow
#property indicator_color3 Red // Sell arrow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
//--- buffers
double AI_Buffer[]; // +1 / -1 / 0
double Buy_Buffer[]; // arrow up
double Sell_Buffer[]; // arrow down
//--- constants for arrow codes
#define ARROW_BUY 233 // Wingdings 2 arrow up
#define ARROW_SELL 234 // Wingdings 2 arrow down
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- set buffer properties
SetIndexBuffer(0, AI_Buffer);
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexLabel(0, "Auction Index");
SetIndexBuffer(1, Buy_Buffer);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, ARROW_BUY);
SetIndexLabel(1, "Buy Signal");
SetIndexBuffer(2, Sell_Buffer);
SetIndexStyle(2, DRAW_ARROW);
SetIndexArrow(2, ARROW_SELL);
SetIndexLabel(2, "Sell Signal");
//--- indicator short name
IndicatorShortName("Two‑Bar Auction (AI)");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Helper: Detect bullish shape of a bar |
//+------------------------------------------------------------------+
bool IsBullishBar(int idx)
{
// 1. Immediate up‑trend (no pullback)
if (Close[idx] > Open[idx] &&
(High[idx] - Close[idx]) < 0.1 * (High[idx] - Low[idx]))
return(true);
// 2. Low → up‑trend after rejection
if (Low[idx] == iLow(_Symbol, 0, idx) && Close[idx] > Open[idx])
return(true);
// 3. Low that closes near the low
if (Close[idx] <= Low[idx] * 1.05 && Close[idx] > Open[idx])
return(true);
return(false);
}
//+------------------------------------------------------------------+
//| Helper: Detect bearish shape of a bar |
//+------------------------------------------------------------------+
bool IsBearishBar(int idx)
{
// 1. Immediate down‑trend (no pullback)
if (Close[idx] < Open[idx] &&
(Close[idx] - Low[idx]) < 0.1 * (High[idx] - Low[idx]))
return(true);
// 2. High → down‑trend after rejection
if (High[idx] == iHigh(_Symbol, 0, idx) && Close[idx] < Open[idx])
return(true);
// 3. High that closes near the high
if (Close[idx] >= High[idx] * 0.95 && Close[idx] < Open[idx])
return(true);
return(false);
}
//+------------------------------------------------------------------+
//| 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[])
{
//--- no data
if(rates_total < 2) return(0);
//--- calculate from the first new bar
int start = prev_calculated - 1;
if(start < 1) start = 1; // we need at least 2 bars
for(int i = start; i < rates_total; i++)
{
//--- 1. Bar‑Bias Score (BBS)
int bbs = 0; // 0 = neutral
if(IsBullishBar(i)) bbs = +1;
else if(IsBearishBar(i)) bbs = -1;
//--- 2. Odd/Even Flag (OEF)
int oef = ((i % 2) == 0) ? +1 : -1; // 0‑based index
//--- 3. Auction Index
AI_Buffer[i] = bbs * oef;
//--- 4. Signal buffers – only on *even* bars (the reversal bar)
if((i % 2) == 0) // even bar
{
// 4a. Buy signal: AI = +1 (bullish even bar)
if(AI_Buffer[i] == +1)
{
Buy_Buffer[i] = Low[i] - 0.0001; // a bit below low to avoid overlap
Sell_Buffer[i] = EMPTY_VALUE;
}
// 4b. Sell signal: AI = -1 (bearish even bar)
else if(AI_Buffer[i] == -1)
{
Sell_Buffer[i] = High[i] + 0.0001; // a bit above high
Buy_Buffer[i] = EMPTY_VALUE;
}
else
{
Buy_Buffer[i] = EMPTY_VALUE;
Sell_Buffer[i] = EMPTY_VALUE;
}
}
else // odd bar – no arrows
{
Buy_Buffer[i] = EMPTY_VALUE;
Sell_Buffer[i] = EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
2. How to Use It
Copy the code into a new file named TwoBarAuction.mq4 in the MQL4/Indicators folder.
Compile it in MetaEditor.
Attach the indicator to a 5‑day M15 chart of XAU/USD.
The histogram will show the alternating +1 / –1 pattern.
Up‑arrows (blue) appear on bullish even bars, down‑arrows (red) on bearish even bars.
You can manually test the strategy by looking at the arrows and the corresponding price action.
3. Limitations & Things to Keep in Mind
Limitation
Why it matters
Work‑around
No “object” arrows
MQL4 indicators cannot create OBJ_ARROW objects; we use buffer arrows instead.
Works fine for visual signals.
No built‑in “high/low of last 3 bars”
We use iLow/iHigh with idx to get the exact bar’s low/high.
For “low of last 3 bars” you would need a custom loop; here we simply check the current bar’s low/high.
No “timeframe lock”
The indicator runs on the chart’s timeframe only.
For multi‑time‑frame confirmation you would need a separate EA or use iClose/iHigh/iLow with a higher timeframe.
No risk‑management
The indicator only shows signals; you must implement stop‑loss / take‑profit logic in an EA.
Use the signals as a trigger for a separate EA that handles money management.
No back‑testing
Indicators cannot be back‑tested directly.
Export the signals (e.g., to a CSV) and back‑test them in Strategy Tester.
4. Next Steps
Export signals – add a Print() or FileWrite() block to log the bar index, price, and signal.
Create an EA – use the indicator’s buffers as input to a simple EA that places trades with the stop‑loss / TP logic described in the strategy section.