Here's the MQL4 custom indicator implementing the Multi-Timeframe Auction Oscillator (MTAO) with ARS signals:
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrLimeGreen
#property indicator_color3 clrRed
#property indicator_width1 2
#property indicator_width2 1
#property indicator_width3 1
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID
#property indicator_level1 0.0
#property indicator_levelcolor clrGray
#property indicator_levelstyle STYLE_DOT
input group "Auction Parameters"
input double BuyThreshold = 0.7;
input double SellThreshold = -0.7;
input double HigherTF_Threshold = 0.3;
input group "Volatility Filter"
input double MinATR_Percent = 0.5;
input int ATR_Period = 14;
input group "Higher Timeframe"
input ENUM_TIMEFRAMES HigherTF = PERIOD_H4;
input group "Signal Display"
input bool ShowBuySignals = true;
input bool ShowSellSignals = true;
input int SignalShift = 1;
double MTAOBuffer[];
double BuySignalBuffer[];
double SellSignalBuffer[];
int OnInit() {
SetIndexBuffer(0, MTAOBuffer);
SetIndexBuffer(1, BuySignalBuffer);
SetIndexBuffer(2, SellSignalBuffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_ARROW);
SetIndexStyle(2, DRAW_ARROW);
SetIndexArrow(1, 233);
SetIndexArrow(2, 234);
SetIndexLabel(0, "MTAO");
SetIndexLabel(1, "Buy Signal");
SetIndexLabel(2, "Sell Signal");
IndicatorSetString(INDICATOR_SHORTNAME, "MTAO Auction");
IndicatorBuffers(3);
return(INIT_SUCCEEDED);
}
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 &real_volume[],
const int &spread[]) {
if(rates_total < 2) return(0);
int limit = rates_total - prev_calculated;
if(limit > 1) limit = rates_total - 1;
for(int i = limit; i >= 0; i--) {
double range = high[i] - low[i];
if(range == 0) range = 1;
int barType = i % 2;
double mtao;
if(barType == 0) {
mtao = (close[i] - low[i]) / range;
} else {
mtao = -(high[i] - close[i]) / range;
}
MTAOBuffer[i] = mtao;
BuySignalBuffer[i] = 0;
SellSignalBuffer[i] = 0;
if(prev_calculated > 0 || i < rates_total - 1) {
double atr = iATR(Symbol(), Period(), ATR_Period, i);
double atrPercent = (atr / close[i]) * 100;
if(atrPercent >= MinATR_Percent) {
int shiftHigher = iBarShift(Symbol(), HigherTF, time[i]);
if(shiftHigher >= 0) {
double hRange = iHigh(Symbol(), HigherTF, shiftHigher) -
iLow(Symbol(), HigherTF, shiftHigher);
if(hRange == 0) hRange = 1;
int hBarType = shiftHigher % 2;
double hMTAO;
if(hBarType == 0) {
hMTAO = (iClose(Symbol(), HigherTF, shiftHigher) -
iLow(Symbol(), HigherTF, shiftHigher)) / hRange;
} else {
hMTAO = -(iHigh(Symbol(), HigherTF, shiftHigher) -
iClose(Symbol(), HigherTF, shiftHigher)) / hRange;
}
bool higherTFAligned = (barType == 0 && hMTAO >= HigherTF_Threshold) ||
(barType == 1 && hMTAO <= -HigherTF_Threshold);
if(barType == 0 && mtao >= BuyThreshold &&
close[i] > high[i + SignalShift] && higherTFAligned && ShowBuySignals) {
BuySignalBuffer[i] = high[i];
}
if(barType == 1 && mtao <= SellThreshold &&
close[i] < low[i + SignalShift] && higherTFAligned && ShowSellSignals) {
SellSignalBuffer[i] = low[i];
}
}
}
}
}
return(rates_total);
}
Key Features:
-
MTAO Oscillator:
- Blue line in separate window
- Range: -1 to 1
- Positive values = bullish auction (Low bars)
- Negative values = bearish auction (High bars)
-
ARS Signals:
- Green arrows (Buy) on strong bullish auctions (MTAO ≥ 0.7)
- Red arrows (Sell) on strong bearish auctions (MTAO ≤ -0.7)
- Signals appear at bar extremes (highs for buy, lows for sell)
-
Multi-Timeframe Filter:
- Validates signals against higher timeframe (default H4)
- Requires aligned auction direction in higher timeframe
-
Volatility Filter:
- Only trades when ATR(14) > 0.5% of current price
- Filters out low-volatility consolidation periods
-
Signal Confirmation:
- Buy: Close above previous bar's high
- Sell: Close below previous bar's low
- Adjustable signal shift parameter for timing
Usage Instructions:
- Attach to M15 chart for XAU/USD
- Set higher timeframe to H4 (default)
- Look for:
- MTAO crossing above 0.7 with green arrow (buy)
- MTAO crossing below -0.7 with red arrow (sell)
- Confirm with higher timeframe alignment
- Check ATR filter > 0.5% before entering
Strategy Rules:
-
Entry:
- Buy: MTAO ≥ 0.7 + higher TF bullish + ATR filter satisfied
- Sell: MTAO ≤ -0.7 + higher TF bearish + ATR filter satisfied
-
Stop Loss:
- Buy: Low of entry bar
- Sell: High of entry bar
-
Take Profit:
- Buy: Close of next bar (expected bearish auction)
- Sell: Close of next bar (expected bullish auction)
-
Timeframe Alignment:
- Primary: M15 for signals
- Confirmation: H4 for trend context
- Filter: ATR for volatility
Optimization Tips:
-
For XAU/USD:
- Increase MinATR_Percent to 0.8-1.0
- Set ATR_Period to 20
- Adjust BuyThreshold/SellThreshold to 0.6-0.8
-
For higher timeframes:
- Increase MinATR_Percent proportionally
- Adjust signal shift based on timeframe
-
Backtest with:
- Different volatility filters
- Varying threshold values
- Multiple higher timeframes
This implementation provides a systematic approach to the auction cycle theory while respecting MQL4 limitations and providing clear visual signals for manual testing.