MT4: iBars iADX using two timeframes does not work on Strategy Tester

 

Hi guys,

  MT4: iBars iADX using two timeframes does not work on Strategy Tester. Why ?

I am testing an Expert on M5, but it makes calls to the H1 timeframe.

Thanks !

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
show the code
 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

    Your image shows the problem with “ADX0: 0”.

 

Please don't post randomly in any section. Your question is not related to the section you posted.

MT4/mql4 has it's own section on the forum.

This thread has been moved accordingly, so please don't create another duplicate topic.

 
MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 

The code below is only to illustrate or reproduce the situation. I am testing this code using the Strategy Tester , M5, on every tick, visual mode = On

#property strict

input ENUM_TIMEFRAMES timeframe1 = PERIOD_CURRENT;
input ENUM_TIMEFRAMES timeframe2 = PERIOD_H1;
bool mipDebug = true;                       // Debug mode

int minBars;            // min number of historical bars to consider the initial calculation
int maxBars;            // max number of historical bars to consider the initial calculation
string g_symbol;

int OnInit() {
  minBars = 15;
  g_symbol = Symbol();
  return(INIT_SUCCEEDED);
}

void OnTick() {
  double ADX0 = iADX(getSymbol(), getTimeframe1(), 14, PRICE_CLOSE, MODE_MAIN, 0);
  Print("validate 1. Timeframe: " + timeframe1  + " , ADX0: " + ADX0);
  int bars = getBars(timeframe1);
  Print("validate 2: bars: " + bars + ", minBars: " + minBars);
  ADX0 = iADX(getSymbol(), getTimeframe2(), 14, PRICE_CLOSE, MODE_MAIN, 0);
  Print("validate 1. Timeframe: " + timeframe2  + " , ADX0: " + ADX0);
  bars = getBars(timeframe2);
  Print("validate 2: bars: " + bars + ", minBars: " + minBars);
}

int getBars(ENUM_TIMEFRAMES timeframe) {
  return iBars(g_symbol, timeframe);
}

int getMinBars() {
  return minBars;
}

string getSymbol() {
  return g_symbol;
}

ENUM_TIMEFRAMES getTimeframe1() {
  return timeframe1;
}

ENUM_TIMEFRAMES getTimeframe2() {
  return timeframe2;
}
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
jocafi #:
void OnTick() {
  double ADX0 = iADX(getSymbol(), getTimeframe1(), 14, PRICE_CLOSE, MODE_MAIN, 0);

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)