Problems with iATR - timeframe ignored??

 

Hi,

please help me with a problem in my EA I don't understand...


int OnInit()

{...

AtrMainHandle  = iATR(_Symbol,inpATRTimeframe,100);

...

}


void OnTick()

{

a = Calculate_ATR(inpATRTimeframe,100);

}



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Calculate_ATR(ENUM_TIMEFRAMES tff,int atrPeriod = 100)
{
   //--- returns ATR in pips
   double buf[], atr;
   Price.Update(_Symbol,tff);
  
   if (tff == inpATRTimeframe)
   {
      if (atrPeriod == 100)
      {
         if (CopyBuffer(AtrMainHandle100,0,0,1,buf) > 0)
         {
            atr = buf[0];
            printf("-----------------ATR Main ="+atr/TickSize/10);
            return(atr/TickSize/10);
         }  
         else
         {
            atr = 0;
            printf("Calculate_ATR() -----------------------------------Cannot get ATR value!");
            return(0);
         }
      }
      else
      {
         printf("Calculate_ATR() -----------------------------------Invalid ATR Main period!");
         return(0);
      }      
   }
 
   return(0);  
}

The problem: function Calculate_ATR always returns ATR values of D1 timeframe, does not matter what inpATRTimeframe does not matter...


Help very much appreciated. thx

 

Tested and working as it should.

input ENUM_TIMEFRAMES inpATRTimeframe=PERIOD_H2;
int AtrMainHandle;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()

  {
   AtrMainHandle=iATR(_Symbol,inpATRTimeframe,100);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   double a=Calculate_ATR(inpATRTimeframe,100);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Calculate_ATR(ENUM_TIMEFRAMES tff,int atrPeriod=100)
  {
//--- returns ATR in pips
   double buf[],atr;
   //Price.Update(_Symbol,tff);

   if(tff==inpATRTimeframe)
     {
      if(atrPeriod==100)
        {
         if(CopyBuffer(AtrMainHandle,0,0,1,buf)>0)
           {
            atr=buf[0];
            printf("-----------------ATR Main = %f",atr/_Point/10);
            printf("time frame used = %s",EnumToString(inpATRTimeframe));
            return(atr/_Point/10);
           }
         else
           {
            atr=0;
            printf("Calculate_ATR() -----------------------------------Cannot get ATR value!");
            return(0);
           }
        }
      else
        {
         printf("Calculate_ATR() -----------------------------------Invalid ATR Main period!");
         return(0);
        }
     }
   return(0);
  }

 
Ernst Van Der Merwe:

Tested and working as it should.

Thank you for your reply. Unfortunately it does not work here :-(

Did you test different timeframes? I always get ATR for tf D1 as result..... the results do not change, when I change the tf. I even copied your code to an empty file.... the same result.


I am testing it with the strategy tester... did you do that, too?

 
blackfriday:

Thank you for your reply. Unfortunately it does not work here :-(

Did you test different timeframes? I always get ATR for tf D1 as result..... the results do not change, when I change the tf. I even copied your code to an empty file.... the same result.


I am testing it with the strategy tester... did you do that, too?

Yes. The tester doesn't work on higher than daily time frame though.


 
Ernst Van Der Merwe:

Yes. The tester doesn't work on higher than daily time frame though.


MT5 ST is working well on higher timeframe than daily.

But with a period of 100 for ATR, on a weekly timeframe, you need to have enough history data to get a value.

 
Alain Verleyen:

MT5 ST is working well on higher timeframe than daily.

But with a period of 100 for ATR, on a weekly timeframe, you need to have enough history data to get a value.

There seems to be a bug in MT5 or whatever.... Since I had open trades, my PC and MT5 had been running all the time and maybe get confused with the data... After shutting it down over the weekend everything is working well now.


Thank you all very much for your instant reply and help. At least there had not been a bug in my code ;-)

Reason: