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

HTF EMA No Lookahead - indicator for MetaTrader 5

Views:
14
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

A common way to show a higher-timeframe moving average on a lower-timeframe chart is to take the value of the higher-timeframe bar that contains the current bar. On history this looks fine, but it is a hidden lookahead: on an H1 chart at 10:00, the H4 bar that started at 08:00 is not closed yet, and its EMA value is only known at 12:00. An indicator or an Expert Advisor that uses it in the past sees information from the future, and the backtest looks better than live trading.

This indicator draws the higher-timeframe EMA using only data that was available at that moment. For every chart bar it takes the last higher-timeframe bar that closed strictly before the chart bar ends. The result is a step line that never repaints: what you see on history is exactly what you would have seen live.

H4 EMA 50 and 200 on an XAUUSD H1 chart

Input parameters

  • Higher timeframe (default H4). If it is not higher than the chart timeframe, a normal EMA of the chart is drawn.
  • Fast EMA period (default 50, 0 = off).
  • Slow EMA period (default 200, 0 = off).
  • Applied price (default Close).

Buffers for Expert Advisors

  • 0 = fast EMA
  • 1 = slow EMA
  • 2 = trend: +1 fast above slow, -1 fast below slow, 0 = no data
int h = iCustom(_Symbol, PERIOD_H1, "HTF_EMA_NoLookahead", PERIOD_H4, 50, 200, PRICE_CLOSE);
double trend[1];
//--- bar 1 = last closed bar
if(CopyBuffer(h, 2, 1, 1, trend) == 1 && trend[0] > 0)
  {
   //--- H4 trend is up
  }

How it was checked

On 2000 bars of XAUUSD H1 every value was compared with an independent calculation (iBarShift of the last second of the H1 bar, then the previous H4 bar). There were no differences. The indicator loads higher-timeframe history in the background and redraws itself when it arrives, also at the weekend when there are no ticks.

Round Number Levels Session Grid Round Number Levels Session Grid

Round number levels for Gold (XAUUSD) and any symbol on MT5. Draws major and minor round levels around price plus Asia, London and New York session open lines, with an optional alert when a candle closes across a major level. Open source code.

Multi Timeframe Trend Dashboard Multi Timeframe Trend Dashboard

Multi timeframe trend dashboard for Gold (XAUUSD) and any symbol on MT5. Shows up, down or flat for up to 6 timeframes from a fast and slow EMA on the last closed bar, with the distance in points and an alert when all line up. Open source code.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.