Download MetaTrader 5

Still can't calculate indicator's past values..

To add comments, please log in or register
galexquant
20
galexquant  

Hi all,

I have developed various indicators in various platforms, this is my first time in MQL, hence my question will be ..elementary.

Let's say I've got 1000 bars of prices. My indicator needs 200 bars for initialization but my first indicator result comes at current bar (1000) instead of 201. In other words when I load my custom indicator, my first result comes at the first bar after loading in contrast to the rest of the indicators that MetaTrader provides.

I'm sure that I haven't understood correctly the prev_calculated, rates_total and the last line of return(....). I use Bars(..) to indicate when I have more than 200 bars into my chart.

In other words I need to implement correctly the following:

if bars_on_chart>200 {

calculate my indicator, access variables etc and show results;

}

Alain Verleyen
Moderator
33807
Alain Verleyen  
galexquant:

Hi all,

I have developed various indicators in various platforms, this is my first time in MQL, hence my question will be ..elementary.

Let's say I've got 1000 bars of prices. My indicator needs 200 bars for initialization but my first indicator result comes at current bar (1000) instead of 201. In other words when I load my custom indicator, my first result comes at the first bar after loading in contrast to the rest of the indicators that MetaTrader provides.

I'm sure that I haven't understood correctly the prev_calculated, rates_total and the last line of return(....). I use Bars(..) to indicate when I have more than 200 bars into my chart.

In other words I need to implement correctly the following:

if bars_on_chart>200 {

calculate my indicator, access variables etc and show results;

}

Please show what you tried.
galexquant
20
galexquant  
angevoyageur:
Please show what you tried.

I removed the main calculations, they are not necessary. I just left what I needed to show.


I need to have a rolling window of 200 bars and feed it into my function f1. Then show these 2 results on screen, do some more calculations and show that 3rd result also. The problem is that in a chart of N bars (N>200) I always get results from bar N+1 and not 201.

Thank you for your time, I really appreciate.

Files:
Alain Verleyen
Moderator
33807
Alain Verleyen  
galexquant:

I removed the main calculations, they are not necessary. I just left what I needed to show.


I need to have a rolling window of 200 bars and feed it into my function f1. Then show these 2 results on screen, do some more calculations and show that 3rd result also. The problem is that in a chart of N bars (N>200) I always get results from bar N+1 and not 201.

Thank you for your time, I really appreciate.

Your buffer aren't initialized.
galexquant
20
galexquant  

Still can't get it done.  I have read many examples.

I need to calculate my indicator for past values, not only for the current price and the future ones. This is piece of cake in Ninjatrader, Tradestation etc. It goes by definition that OnBarUpdate or OnCalculate or whatever the main function is, that past values are calculated too.

There is no need to make it difficult in metatrader.

Alain Verleyen
Moderator
33807
Alain Verleyen  
galexquant:

Still can't get it done.  I have read many examples.

I need to calculate my indicator for past values, not only for the current price and the future ones. This is piece of cake in Ninjatrader, Tradestation etc. It goes by definition that OnBarUpdate or OnCalculate or whatever the main function is, that past values are calculated too.

There is no need to make it difficult in metatrader.

I don't understand your problem, and without a code that I can test, I can't help you, sorry.
galexquant
20
galexquant  

ok, I attach the code. I just removed the function that uses f1_data array. The problem is the filling of f1_data array. I want to fill it with the 200 last close prices in reverse order.

The filling (and the function) works up to a point in time; I can see the plots, then I get an error of "array out of bounds" when I get close to current time.

Files:
to_send.txt 4 kb
Alain Verleyen
Moderator
33807
Alain Verleyen  
galexquant:

ok, I attach the code. I just removed the function that uses f1_data array. The problem is the filling of f1_data array. I want to fill it with the 200 last close prices in reverse order.

The filling (and the function) works up to a point in time; I can see the plots, then I get an error of "array out of bounds" when I get close to current time.

Change your limit value :

   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
   limit=(prev_calculated==0) ? rates_total-big_user : rates_total-prev_calculated+1;
galexquant
20
galexquant  
angevoyageur:

Change your limit value :

It's been a long time since I said thank you to someone.

THANK YOU.

Alain Verleyen
Moderator
33807
Alain Verleyen  
galexquant:

It's been a long time since I said thank you to someone.

THANK YOU.

You are welcome.
Pasi Hakamaki
7335
Pasi Hakamaki  
galexquant:

It's been a long time since I said thank you to someone.

THANK YOU.

A common problem these day :'(
To add comments, please log in or register