Something changed!

 

The code below used to give me the Average Daily Range (ADR) before but now suddenly it does not work anymore and keep on giving me the value of ADR = 0.

Can anybody help me to solve this?

for(i=1; i<=20; i++)
   ADR   =    ADR + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

   ADR = ADR/20;
 
  1. Something changed; likely your code. Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.
  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 - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
 
Ernest Klokow:

The code below used to give me the Average Daily Range (ADR) before but now suddenly it does not work anymore and keep on giving me the value of ADR = 0.

Can anybody help me to solve this?

double _adr,ADR;


void OnTick()
 {
for(int i=1; i<=20; i++)
  {
      ADR = iHigh(Symbol(),PERIOD_D1,i)-iLow(Symbol(),PERIOD_D1,i)/Point;
      _adr = NormalizeDouble(ADR/20,0);
  }
Comment(_adr);//Shows the ADR value on chart
 return;
 }

//Just an example....
 
William Roeder:
  1. Something changed; likely your code. Do you really expect an answer with the information you've provided? There are no mind readers here and our crystal balls are cracked. We can't see your broken code.
  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 - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

William I am not sure what code you want to see. Except for these 3 lines of code there is only one line of other code in the EA where the value of ADR is used and this does not affect the calculation of the ADR value at all.

This line is something like this: if(LongBarSize > (ADR * PercentageADR)/100) SO I believe that the problem lies in the 3 lines of code that calculates the value of ADR.

 
Ernest Klokow: Except for these 3 lines of code there is only one line of other code
All relevant code
  1. No context; code at global scope is not allowed.
  2. Variable not declared; no scope or typing.
  3. Variable not initialized.
  4. You state you get zero, but show no code that could lead to that conclusion.
There are no mind readers here
 
William Roeder:
All relevant code
  1. No context; code at global scope is not allowed.
  2. Variable not declared; no scope or typing.
  3. Variable not initialized.
  4. You state you get zero, but show no code that could lead to that conclusion.
There are no mind readers here

I can understand your frustration with me. The thing is this EA has nearly 1600 lines of code and I cannot see anybody working through all that. But if you want it I can post it. I sit with an unexplained situation. I have found other code that should definitely give a value but they give zero values. I have never experienced this before. I will post a piece of code below and ALL 5 the variables there give zero values. They are properly declared with the right types. So tell me what I must do!

 if(LongBar == true)
      {
       HighBarLB = iHighest(NULL,PERIOD_H1,MODE_HIGH,NumberOfBarsLong,1);
       LongBarHigh = iHigh(NULL,PERIOD_H1,HighBarLB);
       LowBarLB = iLowest(NULL,PERIOD_H1,MODE_LOW,NumberOfBarsLong,1);
       LongBarLow = iLow(NULL,PERIOD_H1,LowBarLB);
       LongBarSize = (LongBarHigh - LongBarLow)/UsePoint;   
         if(LongBarSize > (ADR * PercentageADR)/100)       
         LongBarTrade = false;
         else LongBarTrade = true;
      }
 

Here are the input variables

input bool     LongBar = false;          //Check for LongBars? 
input int      NumberOfBarsLong = 10;    //Qty of Long Bars
input int      PercentageADR = 150;        //Percentage of ADR 

And here are the global variables:

double      HighBar;
int         HighBarLB;
double      LowBar;
int         LowBarLB;
bool        LongBarTrade = false;
int         LongBarSize;
double      LongBarHigh;
double      LongBarLow;
 
  1. Everything you posted in #5 and #6 has nothing to do with your original post/problem.
  2. Ernest Klokow: So tell me what I must do!
    What part of "All relevant code" was unclear?
  3. Your code
             if(LongBarSize > (ADR * PercentageADR)/100)       
             LongBarTrade = false;
             else LongBarTrade = true;
    Simplified
             LongBarTrade = LongBarSize > (ADR * PercentageADR)/100;
    
 
Ernest Klokow:

I can understand your frustration with me. The thing is this EA has nearly 1600 lines of code and I cannot see anybody working through all that. But if you want it I can post it. I sit with an unexplained situation. I have found other code that should definitely give a value but they give zero values. I have never experienced this before. I will post a piece of code below and ALL 5 the variables there give zero values. They are properly declared with the right types. So tell me what I must do!

You should post code sample that demonstrates problem and, more important, sample that can be compiled and tested.

Code snippet you posted probably does not have syntax errors as you claim, but we can't verify because we don't have sample that can be compiled. Because you use standard MQL functions, there is 99% chance you have a bug somewhere in your code. We can't see what you did, we don't have access to log files, we can't run this thing through debugger (see Williams note on crystal ball).

As a start, you should check LastErrorCode() after each iSomething(...) function.

 
Ernest Klokow:

The code below used to give me the Average Daily Range (ADR) before but now suddenly it does not work anymore and keep on giving me the value of ADR = 0.

Can anybody help me to solve this?

On what timeframe is this code running ? If your platform don't have D1 data iHigh() and iLow() will return 0. Resulting in an ADR value of 0.
 
Alain Verleyen: On what timeframe is this code running ? If your platform don't have D1 data iHigh() and iLow() will return 0. Resulting in an ADR value of 0.

As I mentioned in #1.2