Global variable to use in different function

 

Hi all

 I've a global variable defined like this:

MqlRates ga_rates[];

Then I've a function in my EA defined as follows.

void getBarInfo()
{
   // fill array with bar information to use in functions
   CopyRates(Symbol(), PERIOD_CURRENT, 0,10, ga_rates);
}

Now I would like to use the variable ga_rates in the section onTick().

   // only execute if bar is new
   if (lv_isNewBar == true)
   {
      getBarInfo();
      Print("D", "001", ga_rates[0].open);
      Print("D", "002", ga_rates[0].close);
      Print("D", "003", ga_rates[0].high);
      Print("D", "004", ga_rates[0].low);
   }   

I do expect, that I receive 4 different values, but I only get one. It's always the open-value.

Anybody an idea?

 

Thanks for any help in advance. 

FX_TA 

 
fx_ta:

Hi all

 I've a global variable defined like this:

Then I've a function in my EA defined as follows.

Now I would like to use the variable ga_rates in the section onTick().

I do expect, that I receive 4 different values, but I only get one. It's always the open-value.

Anybody an idea?

 

Thanks for any help in advance. 

FX_TA 

  

 

 

Hello FX_TA!

It's easy, you're calling getBarInfo() when new bar shows up so naturaly you only got the first price of that bar which is the open.

When the first bar arrives Open=Close=High=Low, then they will all change except the open, of course.

Try geting the previous bar rates, ga_rates[1].open; ga_rates[1].close,... You will get all 4 prices correctly, or, remove the new_bar function.

  

Hope it helps, regards 

 

Helghast 

 

Hi Helghast

 Thank you! Problem solved.

 Best Regards

 FX_TA