Does a custom indicator use prices and data that were formed when the EA called it?

 

Hi,

Question 1

This is a question about whether a custom indicator which is called from an EA works "on its own" or not. (This might already be answered in the Book, but some sections are badly translated so it's still unclear to me.) I'll explain through an example:

TICK 1:

The EA (program) is doing calculations for 10 seconds.
EA calls an indicator.
The indicator does some calculations based on prices.

- Are these prices (that are now available to the indicator) formed when the indicator is called, or does the indicator use prices that were formed when the EA called the indicator (i.e. 10 seconds ago)?

Question 2:

The Books states that "if the start() function launched at the preceding quote was running when a new quote came, the new quote will be skipped by the expert." This is easy to test by using Sleep(). But does this also apply to custom indicators? You can't use Sleep() in a custom indicator, so it's hard to test.


I appreciate any help. Thanks.

 

A) If EA is taking 10 seconds to run after entering start(), I suggest refactoring the code.

B) My understanding is that, once start() is called, the prices stay the same until the next time start() is called, which might skip a few prices that came in and just use the latest one.

 

couldnt you use RefreshRates() in the indicator to make sure it has the latest prices ?

 

Tick comes in.

ALL indicators are updated, that's why they can not sleep, and why RefreshRates are useless in indicators.

Then all EA's not currently running are called in parallel. EA's currently running are skipped. iCustom/iRsi etc., only read what is in the indicator's buffer at that moment.

 

WHRoeder is right; indicators cannot sleep.

The price you are talking about is formed when the indicator is called, not when the EA starts. This is easy to confirm:

   Alert("Before iCustom: " , Bid);
   Sleep(10000);
   double test = iCustom(NULL, 0, "Indicator_test", 0, 0); // Indicator_test returns Bid
   Alert("From iCustom after sleeping 10 seconds: " , test);

(Indicator_test returns the current Bid price)

After the EA has been sleeping for 10 seconds the value returned by Indicator_test might have changed.

 

Update:

I found something strange. I ran the same code but tested on High[0] instead. This is what happened:

   Alert("Before iCustom: " , High[0]);                        // result: 132.70
   Sleep(10000);                                               // during this time the symbol made a new high (132.75)
   double test = iCustom(NULL, 0, "Indicator_test", 0, 0);     // returns High[0]
   Alert("From iCustom after sleeping 10 seconds: " , test);   // Indicator_test returned 132.70!

Notice the last comment. Does anyone know why Indicator_test didn't have an updated value for the latest High? (No new bar was formed during this test).

It seems like the called indicator uses High[], Low[] etc from when the EA was started, but Ask, Bid etc are always up to date ...